Presentation is loading. Please wait.

Presentation is loading. Please wait.

OCC - CS/CIS CS116-Ch00-Orientation 1 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 1CS 116 Fall 2003 Not quite finished Creating.

Similar presentations


Presentation on theme: "OCC - CS/CIS CS116-Ch00-Orientation 1 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 1CS 116 Fall 2003 Not quite finished Creating."— Presentation transcript:

1 OCC - CS/CIS CS116-Ch00-Orientation 1 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 1CS 116 Fall 2003 Not quite finished Creating assembly – Process Details of the simulator – Loading code – Registers – Kernel – Debugging

2 OCC - CS/CIS CS116-Ch00-Orientation 2 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 2CS 116 Fall 2003 Creating Assembly Start with problem description: – Write a program that solves the problem High level language like C or Pascal For each function in the solution – Translate each HLL statement into assembly – Write the procedure entry and exit code For global data – That is data that is accessible from everywhere Such as strings for output – Create a.data section and add globals there

3 OCC - CS/CIS CS116-Ch00-Orientation 3 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 3CS 116 Fall 2003 Translating Statements Associate each value with a register – Including temporary results Consider: A*(B+C)-15 A: $a0, B: $a1, C: $a2 B+C: $t0, A+$t0: $t0 Convert each line – Consider if you need to use Immediate form (with constants) Register form – Above example: add $t0, $a1, $a2 mul $t0, $a0, $t0 subi $t0, $t0, 15

4 OCC - CS/CIS CS116-Ch00-Orientation 4 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 4CS 116 Fall 2003 Procedures If your HLL code has variables... – Try and assign them to registers – Otherwise, will need stack space If you need stack space... – Assign them an offset from $fp – Load them into a temporary register when needed – Spill (save) the result back to the stack when done

5 OCC - CS/CIS CS116-Ch00-Orientation 5 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 5CS 116 Fall 2003 Example load and spill Cosider a local variable x – On the stack, located -28 from the $fp – To use it in an equation: X = X + 15 lw $t0, -28($fp) addi $t0, $t0, 15 sw $t0, -28($fp)

6 OCC - CS/CIS CS116-Ch00-Orientation 6 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 6CS 116 Fall 2003 Procedure Entry Procedures must save the state of the processor – Procedure prologue & epilogue Prologue – Adjust stack by size of procedure frame – Put $ra on stack – Put $fp on stack – Save any argument registers (if necessary) – Save any other registers ($s0...$s7, etc)

7 OCC - CS/CIS CS116-Ch00-Orientation 7 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 7CS 116 Fall 2003 Procedure finish Epilogue – Pretty much the inverse of the prologue Restore any saved registers ($s0..$s7, etc) Restore argument registers Restore old $fp Restore return address ($ra) Readjust the stack Exit the procedure

8 OCC - CS/CIS CS116-Ch00-Orientation 8 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 8CS 116 Fall 2003 Sample Procedure proc_start: subi $sp, $sp, 32 sw $ra, 28($sp) sw $fp, 24($sp) sw $s0, 20($sp) addiu $fp, $sp, 28 (some instructions) proc_end:lw $s0, 20($sp) lw $fp, 24($sp) lw $ra, 28($sp) addi $sp, $sp, 32 jr $ra

9 OCC - CS/CIS CS116-Ch00-Orientation 9 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 9CS 116 Fall 2003 A Worked Out Example Please see page A-26 in the book – Walks through all of the steps – Creates a program to calculate the factorial of a given parameter

10 OCC - CS/CIS CS116-Ch00-Orientation 10 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 10CS 116 Fall 2003 The Simulator Registers Text (Code) Data segment Error messages

11 OCC - CS/CIS CS116-Ch00-Orientation 11 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 11CS 116 Fall 2003 Loading Code

12 OCC - CS/CIS CS116-Ch00-Orientation 12 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 12CS 116 Fall 2003 Registers

13 OCC - CS/CIS CS116-Ch00-Orientation 13 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 13CS 116 Fall 2003 Kernel Set of software routines for common services – Usually provided by the OS – Interrupts via syscall

14 OCC - CS/CIS CS116-Ch00-Orientation 14 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 14CS 116 Fall 2003 Debugging Set a breakpoint at a given address When executing, simulator stops – Examine state of machine – Resume program


Download ppt "OCC - CS/CIS CS116-Ch00-Orientation 1 1998 Morgan Kaufmann Publishers ( Augmented & Modified by M.Malaty) 1CS 116 Fall 2003 Not quite finished Creating."

Similar presentations


Ads by Google