intermezzOS / journey

Supplemental Book to intermezzOS exploring low level concepts like stack vs. heap, assembly language and virtual memory.
7 stars 1 forks source link

Change add to counter and counter-minimal #3

Closed rylev closed 8 years ago

rylev commented 8 years ago

I changed add to be a bit more useful, otherwise the compiler can completely optimize everything away. When compiling the minimal example in release mode and then disassembling it, we get some very nice assembly:

(__TEXT,__text) section
_main:
0000000100000fa0    pushq   %rbp
0000000100000fa1    movq    %rsp, %rbp
0000000100000fa4    leal    0x1(%rdi), %eax
0000000100000fa7    popq    %rbp
0000000100000fa8    retq

I really like this as a teaching example, but it's still quite advanced. In order to understand this code the student will need to know about C calling conventions, the stack, and more. So I don't think we can start here, but this would be nice to get to after covering more of the basics.

steveklabnik commented 8 years ago

That is a great disassembly! Just one tiny nit.