spring elec 5200 0016200 001 lecture 3 34 addresses

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: Publishers Spring 2013, Jan 25 . . . Spring ELEC 5200-001/6200-001 Lecture 3 34 Addresses in Branches and Jumps Instructions: bne $t4, $t5, Label Next instruction is at Label Next if $t4 ≠ $t5 if beq $t4, $t5, Label Next instruction is at Label Next if $t4 = $t5 if $t4 Next instruction is at Label j Label Formats: Formats: I op J op rs rt 16 bit rel. address 26 bit absolute address 2004 © Morgan Kaufman Publishers Spring 2013, Jan 25 . . . Spring ELEC 5200-001/6200-001 Lecture 3 35 Addresses in Branches Instructions: bne $t4,$t5,Label beq $t4,$t5,Label Formats: Next instruction is at Label if $t4 ≠ $t5 Next $t5 Next instruction is at Label if $t4 = $t5 – 215 to 215 – 1 ~ ±32 Kwords ±32 op op rs rt 16 bit address 26 bit address Relative addressing 226 = 64 Mwords – with respect to PC (program counter) – most branches are local (principle of locality) Jump instruction just uses high order bits of PC Jump – address boundaries of 256 MBytes (maximum jump 64 Mwords) 2004 © Morgan Kaufman Publishers Spring 2013, Jan 25 . . . 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 2013, Jan 25 . . . 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 2013, Jan 25 . . . 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 ..... N...
View Full Document

Ask a homework question - tutors are online