Calculation for resistor value for mains to speaker Electricity safety demo An exercise for us! Test questions sometimes look like this... .section .text .globl _start a_function: push %ebp mov %esp, %ebp sub $8, %esp movl $100, (%esp) movl $20, 4(%esp) push $52 // Draw the stack here // Note: The program will actually crash after this _start: mov %esp, %ebp push $82 call a_function int $0x80 Next: Back to our writing numbers example Can we open a file and write some numbers to it? NOT ascii codes So cat will make a mess of the file hexcat would be ok After that: Libraries and building things together (chapter 8) Let's make a library with our flexible print number function And use it to print the numbers in a file Clobbering registers Could we, then, link to a system library and call a C function? For sure 1. Respect the C calling convention in use 1a. Parameters need to be in the right spot 1b. Remember register clobbering 1c. Look for the return value in the right place For 32-bit Linux: Parameters go on the stack eax, ecx, and edx are clobbered, others are preserved Return value will be in eax 2. Link to the correct library (ld will need more parameters) That's it, let's do it! A question: IF you can either call the C library wrapper or do the system call, which is best? Do the system call unless you need the wrapper for something More efficent, uses less electricity