Show and tell: Noise demo, maybe, if it all works right I dug out an arduino I had around and made it blink a light Still thinking of putting a little more EE content Addressing Modes (probably dive into programming and come back here): Register (in a register) Direct (in memory at an address) Indexed (in memory, given address, index, multiplier) Indirect (address is in a register) Base pointer (address is given in a register, also have an offset) First: The exit example from the book as and ld are both on isoptera Alright, now that we've done that: Compiling with gcc is possible You'll need main instead of start I've got a bunch of examples from last term around Might need -static to get some of them to build First place the book is out of date: x86-64 has all the 32-bit registers But it has extras too! R8, R9, R10, R11, R12, R13, R14, R15 wikipedia x86-64 The book has an example of calculating maximum Let's calculate something else How about adding them up? We'll stick with returning the result to the shell That'll limit our range to a byte The rest of the int is used for other things... Can we make it harder? What about average? Alright, everybody wants to know: Can we please have a print function instead of returning a status? This is chapter 8 in the book Sure...we can call C library functions Linking is easier if we just run it through gcc Replace _start with main Give -static to gcc for linking Dynamic linking used to work with the default options If I figure out what's wrong now, I'll explain it Alright, calling printf: 1. Put a string somewhere (.asciz, in data section) 2. Push any register values you care about onto the stack 3. Put the address of the string in %rdi 4. Put the value you want to print in %rbx, or a shorter version 5. Set rax to 0 (0 floating point arguments) 6. call printf 7. If you pushed values onto the stack, pop them back where they go Cheating: Write what you wanted in C, compile it, and disassemble it Can actually be pretty useful Compiler is somewhat pedantic when not using optimization Sometimes you can beat the optimizer by leaving out cases that won't happen Sometimes you can make the most likely branch fastest Sometimes you know the value range is constricted Add a byte instead of a register Can't we just stick the whole thing in the middle of a C program? Sure, but not for this week's lab Learn assembly at least a little before mixing it with C!