Last active
September 2, 2017 22:32
-
-
Save maxchehab/6c4b4da931b26f8d6581ae6f43834837 to your computer and use it in GitHub Desktop.
Compiler nasm output example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = 10; | |
var b = 15; | |
var c = a + b; | |
print(c); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
section .bss | |
digitSpace resb 100 | |
digitSpacePos resb 8 | |
a resb 32 | |
b resb 32 | |
c resb 32 | |
section .text | |
global _start | |
_start: | |
mov rax, 10 | |
mov [a], rax | |
mov rax, 15 | |
mov [b], rax | |
mov rax, [a] | |
mov rbx, [b] | |
add rax, rbx | |
mov [c], rax | |
mov rax, [c] | |
call _printRAX | |
mov rax, 60 | |
mov rdi, 0 | |
syscall | |
_printRAX: | |
mov rcx, digitSpace | |
mov rbx, 10 | |
mov [rcx], rbx | |
inc rcx | |
mov [digitSpacePos], rcx | |
_printRAXLoop: | |
mov rdx, 0 | |
mov rbx, 10 | |
div rbx | |
push rax | |
add rdx, 48 | |
mov rcx, [digitSpacePos] | |
mov [rcx], dl | |
inc rcx | |
mov [digitSpacePos], rcx | |
pop rax | |
cmp rax, 0 | |
jne _printRAXLoop | |
_printRAXLoop2: | |
mov rcx, [digitSpacePos] | |
mov rax, 1 | |
mov rdi, 1 | |
mov rsi, rcx | |
mov rdx, 1 | |
syscall | |
mov rcx, [digitSpacePos] | |
dec rcx | |
mov [digitSpacePos], rcx | |
cmp rcx, digitSpace | |
jge _printRAXLoop2 | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment