15-213 Recitation 3 – 2/5/01Code to ExecutablesMachine ModelSpecial RegistersAssembly Programming: StructureSlide 6Assembly Programming: Simple Addressing ModesAssembly Programming: Indexed Addressing Modes15-213 Recitation 3 – 2/5/01Outline•Code to Executables•Machine Model•Assembly Programming–Structure–Addressing Modes–Miscellaneous Stuf•H1a / L3 PracticeShaheen Gandhie-mail: [email protected] Hours: Wednesday 1:30 – 2:30 Wean 3108Code to ExecutablesPreprocessor (text)Compiler (text)Assembler (binary)Linker (binary)Binary Executable (binary)C/C++ Code (text)startfinishMachine ModelEIPRegistersCPUMemoryObject CodeProgram DataAddressesDataInstructionsStackConditionCodesSpecial Registers•%eax Return Value•%eip Instruction Pointer•%ebp Base (Stack Frame) Pointer•%esp Stack PointerAssembly Programming: StructureFunction Setup•Save Old Base Pointer (pushl %ebp)•Set up own base pointer (movl %esp, %ebp)–Note that this saves the old stack pointer•Save any registers that could be clobbered–Where?Function Body•Operations on data, loops, function callsAssembly Programming: StructureFunction Cleanup•Return value placed in %eax–What about returning larger values? (structs, doubles, etc.)•Restore Caller’s Stack Pointer (movl %ebp, %esp)•Restore Old Base Pointer (popl %ebp)•Return–Where does it return to?Assembly Programming:Simple Addressing ModesExamples•(R) Mem[R]•$10(R) Mem[R + 10]•$0x10(R) Mem[R + 16]Assembly Programming:Indexed Addressing ModesGeneric FormD(Rb, Ri, S) Mem[Reg[Rb]+S*Reg[Ri]+ D]Examples•(Rb,Ri) Mem[Reg[Rb]+Reg[Ri]]•D(Rb,Ri) Mem[Reg[Rb]+Reg[Ri]+D]•(Rb,Ri,S)
View Full Document