DOC PREVIEW
CSU CS 453 - LECTURE NOTES

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS453 Intro and PA1 1CS453 Lecture x86 code gen 1Plan for today Finish Tree patterns for MiniJava Instruction selection for x86 Suggested exercisesCS453 Lecture x86 code gen 2Tree Patterns Approach– organize them by Tree.Exp and Tree.Stm node and for each one figure out ifmunchNodeNAME is needed– determine which nodes correspond to code generation for MIPS Tree.Exp nodes– ExpCONST(int i)– ExpNAME(Label n) - parent node will do any code gen– ExpTEMP(Temp t) - code gen not needed because result already in Temp– ExpBINOP(int binop, Exp left, Exp right)– code gen based on?– how do we get Temps for left and right?– ExpMEM(Exp exp)– where can this show up in Tree.Stm?– ExpCALL(Exp func, List<Exp> args)– what should happen here?CS453 Lecture x86 code gen 3Tree Patterns Tree.Exp nodes– StmMOVE(Temp t, Exp rhs)– StmMOVE(ExpMEM lhs, Exp rhs)– StmEXP(Exp e)– StmJUMP(Label targ)– StmCJUMP(int relop, Exp lhs, Exp rhs, Label true, Label f)– StmLABEL(Label l)CS453 Lecture x86 code gen 4Instruction selection for x86 Registers– EAX, the accumulator– EBX, the base register– ECX, the counter register– EDX, the data register Representations– Constants prefixed with ‘$’, $3, $4, $-5, etc– Registers prefixed with ‘%’, %eax, %esp, etc. Some Instructions– movl -12(%ebp), %eax // M[%ebp-1] --> %eax– imull -4(%ebp), %eax // M[%ebp-4] * %eax --> %eax– cmpl -4(%ebp), %eax– jge .L2 // if ( M[%ebp-4] >= %eax ) goto .L2•ESI, the source register•EDI, the destination register•ESP, the stack pointer register•EBP, the frame pointer registerCS453 Intro and PA1 2CS453 Lecture x86 code gen 5Suggested Exercises Compile the following three C programs– using ‘gcc -S filename.c’ on a 32-bit machine– read http://cs.wellesley.edu/~cs342/crash-course.pdf, pages 5-9 Answer the following questions– The Pentium requires that the destination of a multiply must be %eax.What instruction in the assembly output for the below programs seems tosuggest that is probably true?– Identify and explain the lines of assembly code (5 lines that start at cmpl)generated for the ‘if’ statement.– What is the return register?int main() { return 20;}int main() { int x, y; x = 2; y = 42; if (x>y) { return 7; } else { return 8; }}int main() { int x, y; x = 2; y = 42; return


View Full Document

CSU CS 453 - LECTURE NOTES

Download LECTURE NOTES
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view LECTURE NOTES and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view LECTURE NOTES 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?