Morgan kaufman publishers spring 2014 jan 24 spring

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: Bytes (maximum jump 64 Mwords) 2004 © Morgan Kaufman Publishers Spring 2014, Jan 24 . . . Spring ELEC 5200-001/6200-001 Lecture 3 36 Example: Loop in C (p. 74) while while ( save[i] == k ) i += 1; += Given a value for k, set i to the index of Given element in array save [ ] that does not equal k. element Spring 2014, Jan 24 . . . Spring ELEC 5200-001/6200-001 Lecture 3 37 MIPS Code for While Loop Compiler assigns variables to registers: $s3 (reg 19) $s5 (reg 21) $s6 (reg 22) ← ← ← i initially 0 k memory address where save [ ] begins Then generates the following assembly code: Loop: sll add lw bne addi j Exit: $t1, $t1, $t0, $t0, $s3, Loop Spring 2014, Jan 24 . . . Spring $s3, 2 $t1, $s6 0($t1) $s5, Exit $s3, 1 # # # # # # Temp reg $t1 = 4 * i $t1 = address of save[i] Temp reg $t0 = save[i] go to Exit if save[i] ≠ k i=i+1 go to Loop ELEC 5200-001/6200-001 Lecture 3 38 Machine Code and Mem. Adresses Memory Machine code Byte addr. Bits 31-26| 25-21 | 20-16 | 15-11 | 10 – 6 | 5 – 0 | 80000 0 0 19 9 2 0 sll 80004 0 9 22 9 0 32 add 80008 35 9 8 0 80012 5 8 21 Exit = +2 bne 80016 8 19 19 1 addi 80020 2 80024 Loop = 20000 (memory word address) lw j ..... Note: $t0 ≡ Reg 8, $t1 ≡ Reg 9, $s3 ≡ Reg 19, $s5 ≡ Reg 21, $s6 ≡ Reg 22 temp temp i k save Spring 2014, Jan 24 . . . Spring ELEC 5200-001/6200-001 Lecture 3 39 Finding Branch Address Exit Finding Exit Exit = +2 is a 16 bit integer in bne instruction 000101 01000 10101 0000000000000010 = 2 $PC = 80016 is the byte address of the next instruction 00000000000000010011100010010000 = 80016 80016 Multiply bne argument by 4 (convert to byte address) 0000000000001000 = 8 $PC ← $PC + 8 $PC $PC 00000000000000010011100010011000 = 80024 00000000000000010011100010011000 80024 Thus, Exit is memory byte address 80024. Thus, Exit Spring 2014, Jan 24 . . . Spring ELEC 5200-001/6200-001 Lecture 3 40 Finding Jump Address Loop Finding Loop J 20000 000010 00000000000100111000100000 = 20000 $PC = 80024, when jump is being executed 00000000000000010011100010011000 = 80024 Multiply J argument by 4 (convert to byte address) 0000000000010011100010000000 = 80000 0000000000010011100010000000 Insert four leading bits from $PC 00000000000000010011100010000000 = 80000 Thus, Loop is memory byte address 80000. Thus, Loop Spring 2014, Jan 24 . . . Spring ELEC 5200-001/6200-001 Lecture 3 41 Summary: MIPS Registers and Summary: Memory Memory $s0-$s7, $t0-$t9, $zero, Fast locations for data. In MIPS, data m ust be in registers to perform 32 registers $a0-$a3, $v0-$v1, $gp, arithm etic. MIPS register $zero alw ays equals 0. Register $at is $fp, $sp, $ra, $at reserved for the assem bler to handle large constants. Memory[0], 230 memoryMemory[4], ..., words Memory[4294967292] Spring 2014, Jan 24 . . . Spring Accessed only by data transfer instructions. MIPS uses byte addresses, so sequential w ords differ by 4. Mem ory holds data structures, such as arrays, and spilled registers, such as those saved on procedure calls. EL...
View Full Document

This document was uploaded on 02/23/2014 for the course COMUPER AR 6200 at Auburn University.

Ask a homework question - tutors are online