For both of these one argument must be in register

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: x %edx,(%eax) %ecx,%eax Get xp Get y Get x at *xp Store y at *xp Set x as return value int exchange(int *xp, int y) { int x = *xp; *xp = y; return x; } code/asm/exchange.c (a) C code (b) Assembly code Figure 3.5: C and Assembly Code for Exchange Routine Body. The stack set-up and completion portions have been omitted. program stack is stored in some region of memory. The stack grows downward such that the top element of the stack has the lowest address of all stack elements. The stack pointer %esp holds the address of this lowest stack element. Pushing a double-word value onto the stack therefore involves first decrementing the stack pointer by 4 and then writing the value at the new top of stack address. Therefore, the instruction pushl %ebp has equivalent behavior to the following pair of instructions: subl $4,%esp movl %ebp,(%esp) except that the pushl instruction is encoded in the object code as a single byte, whereas the pair of instruction shown above requires a total of 6 bytes. Popping a do...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online