Debugging, and rockets I posted projects 3 and 4 Still thinking about 5...probably not the same as last time Yesterday's C++ problem: As mentioned, C++ function naming is more complicated For g++ anyway: extern "C" Today's topic: Putting assembly into C programs Can you work with the compiler? Reference I used 8 years ago: http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html Reference I was using yesterday (gcc documentation): https://gcc.gnu.org/onlinedocs/gcc/Using-Assembly-Language-with-C.html basic asm directive: Let's just put some assembly into a C program! We can make it do something extended asm: We can have compiler-assigned registers now! Example: Change a variable that's in our program basic vs. extended asm syntax: %%rax vs. %rax Can have four sections assembler template: - This is assembly code, but will be processed further - Template in CS: Something which will be filled out later - Use %% for regs here - %n for registers identified in input/output section output operands: - which variables are used for output from the template? - Example: "=r"(foo), "=a"(bar) = is a modifier, means that the initial value of the variable is not used - "r" will let the compiler pick a register, "a" picks ax / eax / rax input operands: - Same thing, for input clobbered registers: - clobbering defined - gcc can work with you on the optimization volatile: Might produce side effects the compiler won't know about As in, the optimizer is not allowed to leave it out inline: More accurate size calculation Normally gcc kind of guesses goto: Might jump to one of the listed labels If you just jump, it might confuse the compiler You can jump out of an asm, or to a different one Why wouldn't we need extended asm for anything productive? Let's define a function in a basic asm directive Parameters will be where we expect Clobbers are dictated by calling convention Active Learning: puzzle.c