Created
November 28, 2016 18:38
-
-
Save afternoon/f5cf3f2cb894fae92653735dcde75462 to your computer and use it in GitHub Desktop.
This file contains 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 __TEXT,__text,regular,pure_instructions | |
.macosx_version_min 10, 12 | |
.globl _main | |
.p2align 4, 0x90 | |
_main: ## @main | |
.cfi_startproc | |
## BB#0: | |
pushq %rbp | |
Ltmp0: | |
.cfi_def_cfa_offset 16 | |
Ltmp1: | |
.cfi_offset %rbp, -16 | |
movq %rsp, %rbp | |
Ltmp2: | |
.cfi_def_cfa_register %rbp | |
leaq L_.str(%rip), %rdi | |
xorl %eax, %eax | |
callq _printf | |
xorl %eax, %eax | |
popq %rbp | |
retq | |
.cfi_endproc | |
.section __TEXT,__cstring,cstring_literals | |
L_.str: ## @.str | |
.asciz "Hello World!\n" | |
.subsections_via_symbols |
Hi I'll take a crack at trying to explain this...
Lines 8, 13: Prepare a new stack frame (save the old base pointer, and set
the new base pointer to the current stack pointer)
Lines 16: Get the address of your string (lea = load effective address)
and put it into the rdi register as a parameter to printf. %rip is the instruction
pointer, and the code uses that to find the string literal below.
Line 17: Not sure why this is needed - I believe it sets eax to zero. Must be another parameter to printf
Line 18: Call printf
Line 19: Same thing here - set eax to zero, which is now the return value of the function
Lines 20,21: Restore the old stack frame and return to the caller
Line 26: The string literal referenced by leaq.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What does all this mean? What's the
leaq
call on line 16 doing to%rip
? What are all the directives?!