Created
January 27, 2018 10:31
-
-
Save elvircrn/022cd5bfca666f70c498edd4446e5b78 to your computer and use it in GitHub Desktop.
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
; ubuntu@ubuntu:~/Desktop/usr/bin$ ./nasm -f elf hello.asm | |
; ubuntu@ubuntu:~/Desktop/usr/bin$ gcc -o hello hello.o | |
; ubuntu@ubuntu:~/Desktop/usr/bin$ ./hello | |
; a=5, eax=7 | |
extern printf | |
SECTION .data ; Data section, initialized variables | |
a: dd 5 ; int a=5; | |
fmt: db "a=%d, eax=%d", 10, 0 ; The printf format, "\n",'0' | |
SECTION .text ; Code section. | |
global main ; the standard gcc entry point | |
main: ; the program label for the entry point | |
push ebp ; set up stack frame | |
mov ebp,esp | |
mov eax, [a] ; put a from store into register | |
add eax, 2 ; a+2 | |
push eax ; value of a+2 | |
push dword [a] ; value of variable a | |
push dword fmt ; address of ctrl string | |
call printf ; Call C function | |
add esp, 12 ; pop stack 3 push times 4 bytes | |
mov esp, ebp ; takedown stack frame | |
pop ebp ; same as "leave" op | |
mov eax,0 ; normal, no error, return value | |
ret ; return | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment