Created
September 13, 2015 14:22
-
-
Save peterprokop/c31ef0150cd91c766d8a to your computer and use it in GitHub Desktop.
Fooling around with nasm
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
; /usr/local/bin/nasm -f macho64 sum.asm && ld -macosx_version_min 10.7.0 -lSystem -o sum sum.o && ./sum | |
global start | |
section .text | |
extern _printf | |
extern _exit | |
start: | |
; Calculations | |
mov rax, 1 | |
push rax | |
mov rax, 2 | |
pop rbx | |
add rax, rbx | |
push rax | |
mov rax, 3 | |
pop rbx | |
add rax, rbx | |
push rax | |
mov rax, 9 | |
pop rbx | |
add rax, rbx | |
; Output | |
mov rsi, rax ; Move result to output | |
mov qword rax, 0 ;A zero in rax indicates that printf receives standard | |
lea rdi, [rel message] | |
call _printf | |
mov qword rax, 0 | |
call _exit | |
section .data | |
message: db "Register %i", 10, 0 | |
.len: equ $ - message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment