By the way, I would love any feedback on this approach and where I should take this further.
There are a couple of great (free) resources on 32bit x86 assembly I'm aware of:
http://www.drpaulcarter.com/pcasm/ http://www.plantation-productions.com/Webster/HighLevelAsm/i...
There's apparently some plans on upgrading HLA to x86_64 -- I don't know of any good tutorials or guides on working on 64bit assembly specifically I'm afraid.
Just adding "-S" and looking at the source can be helpful of course, although I much prefer nasm/intel syntax, for clang/gcc that should require:
clang -S -mllvm --x86-asm-syntax=intel main.c
gcc -S -masm=intel main.c
Note that gas syntax is the "default" in the gnu-world, so it might be easier to just go with that if you're just starting out.It looks like clang might be generating less "noise" for tiny trivial programs, here's a side by-side-diff (in intel syntax) of int main{} vs int main { return 0;} (slightly reformatted):
diff --side-by-side main.s main.no-ret
.file "main.c" .file "main.c"
.text .text
.globl main .globl main
.align 16, 0x90 .align 16, 0x90
.type main,@function .type main,@function
main: # @main main: # @main
.cfi_startproc .cfi_startproc
# BB#0: # %entry # BB#0: # %entry
mov EAX, 0 mov EAX, 0
mov DWORD PTR [RSP - 4], 0 <
ret ret
.Ltmp0: .Ltmp0:
.size main, .Ltmp0-main .size main, .Ltmp0-main
.cfi_endproc .cfi_endproc
.section ".note.GNU-stack","",@progbits .section ".note.GNU-stack","",@progbits
It can be fun to do this with stuff like hello world (and contrast
puts("Hello, world!"); with printf("Hello world!\n);). http://c.learncodethehardway.org/book/