Skip to content

Instantly share code, notes, and snippets.

@mkakh
Last active October 8, 2018 05:51
Show Gist options
  • Save mkakh/fe6f70f2eab146304d10f6a8b43f01e1 to your computer and use it in GitHub Desktop.
Save mkakh/fe6f70f2eab146304d10f6a8b43f01e1 to your computer and use it in GitHub Desktop.
section .data
text db "number> "
nl db 10
section .bss
input1 resb 1
input2 resb 1
tmp resb 1
section .text
global _start
%macro addNum 2
mov rax, [%1]
mov rbx, [%2]
add rax, rbx
%endmacro
%macro exit 0
mov rax, 60
mov rdi, 0
syscall
%endmacro
%macro getNum 1
; 1桁入力(数値として)
mov rax, 0
mov rdi, 0
mov rsi, %1
mov rdx, 1
syscall
sub byte [%1], 48
mov rax, [%1]
; 改行を捨てる
mov rax, 0
mov rdi, 0
mov rsi, tmp
mov rdx, 1
syscall
%endmacro
_start:
call _printText
getNum input1
call _printText
getNum input2
addNum input1, input2
call _printRAXDigit
call _printNewLine
exit
_printNewLine:
mov rax, 1
mov rdi, 1
mov rsi, nl
mov rdx, 1
syscall
ret
_printText:
mov rax, 1
mov rdi, 1
mov rsi, text
mov rdx, 8
syscall
ret
_printRAXDigit:
add rax, 48
mov byte [tmp], al
mov rax, 1
mov rdi, 1
mov rsi, tmp
mov rdx, 1
syscall
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment