first commit
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
calculator
|
||||
calculator.o
|
||||
70
calculator.s
Normal file
70
calculator.s
Normal file
@@ -0,0 +1,70 @@
|
||||
; -- Assembly Calculator ---------------------------------------
|
||||
;
|
||||
; This project is a practice for my low-level programming study
|
||||
; --------------------------------------------------------------
|
||||
|
||||
; x86_64 linux syscalls table
|
||||
;
|
||||
; 0: read (needs fd, where to save and length)
|
||||
; 1: write (needs fd, string and string length)
|
||||
; 60: exit (needs status code)
|
||||
|
||||
global _start
|
||||
|
||||
section .bss
|
||||
fnum resb 128
|
||||
snum resb 128
|
||||
|
||||
; "variables" read-only
|
||||
section .rodata
|
||||
title db "Assembly Calculator v1.0 by /synt-xerror", 0xA
|
||||
titlel equ $ - title
|
||||
|
||||
fir db 0xA, "Enter the first number: "
|
||||
firl equ $ - fir
|
||||
|
||||
sec db "Enter the second number: "
|
||||
secl equ $ - sec
|
||||
|
||||
section .text
|
||||
|
||||
_start:
|
||||
; print title
|
||||
mov rax, 1
|
||||
mov rdi, 1
|
||||
mov rsi, title
|
||||
mov rdx, titlel
|
||||
syscall
|
||||
|
||||
; ask to enter first number
|
||||
mov rax, 1
|
||||
mov rdi, 1
|
||||
mov rsi, fir
|
||||
mov rdx, firl
|
||||
syscall
|
||||
|
||||
; input to enter the first number
|
||||
mov rax, 0
|
||||
mov rdi, 0
|
||||
mov rsi, fnum
|
||||
mov rdx, 128
|
||||
syscall
|
||||
|
||||
; ask to enter second number
|
||||
mov rax, 1
|
||||
mov rdi, 1
|
||||
mov rsi, sec
|
||||
mov rdx, secl
|
||||
syscall
|
||||
|
||||
; input to enter the second number
|
||||
mov rax, 0
|
||||
mov rdi, 0
|
||||
mov rsi, snum
|
||||
mov rdx, 128
|
||||
syscall
|
||||
|
||||
; exit
|
||||
mov rax, 60
|
||||
mov rdi, 0
|
||||
syscall
|
||||
Reference in New Issue
Block a user