lect.04.Assembly3.4up

lect.04.Assembly3.4up - Announcements PA1 available, due on...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
EE108b Lecture 4 C. Kozyrakis 1 EE108B Lecture MIPS Assembly Language III Christos Kozyrakis Stanford University http://eeclass.stanford.edu/ee108b EE108b Lecture 4 C. Kozyrakis 2 Announcements • PA1 available, due on Thursday 2/8 – Work on you own (no groups) • Homework #1 due on Tue 1/23, 5pm outside Gates 310 • Lab #1 is available – Due on Tuesday 1/30, midnight • EE108B Review Session – Friday: 2:15pm-3:05pm in Thornton 102 EE108b Lecture 4 C. Kozyrakis 3 Review of MIPS Assembly Language II • Memory data transfer – Data alignment • Control transfer instructions – Branches and jumps • Machine language – Encoding assembly instructions – MIPS instruction formats • R-format EE108b Lecture 4 C. Kozyrakis 4 MIPS Machine Instruction Review: Instruction Format Summary
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
EE108b Lecture 4 C. Kozyrakis 5 Today’s Menu • Reading 2.5, 2.7, 2.9 • Introduce a few more instructions – Logical operations – jal, jr • For loops • Switch statements • Procedure calls EE108b Lecture 4 C. Kozyrakis 6 I-Format • The immediate instruction format – Uses different opcodes for each instruction – Immediate field is signed (positive/negative constants) – Used for loads and stores as well as other instructions with immediates (addi, lui, etc.) – Also used for branches OP rs rt imm Bits 6 5 5 16 First Source Register Second Source Register or dest Immediate EE108b Lecture 4 C. Kozyrakis 7 I-Format Example • Consider the addi instruction addi $t0, $t1, 1 # $t0 = $t1 + 1 • Fill in each of the fields 001000 01001 01000 0000000000000001 8 9 8 1 Bits 6 5 5 16 First Source Register Second Source Register Immediate EE108b Lecture 4 C. Kozyrakis 8 Another I-Format Example • Consider the while loop Loop: addu $t0, $s0, $s0 # $t0 = 2 * i addu $t0, $t0, $t0 # $t0 = 4 * i add $t1, $t0, $s3 lw $t2, 0($t1) # $t2 = A[i] bne $t2, $s2, Exit # goto Exit if != addu $s0, $s0, $s1 # i = i + j j Loop # goto Loop Exit: • Pretend the first instruction is located at address 80000
Background image of page 2
EE108b Lecture 4 C. Kozyrakis 9 I-Format Example (Incorrect) • Consider the bne instruction bne $t2, $s2, Exit # goto Exit if $t2 != $s2 • Fill in each of the fields • This is not the optimum encoding 000101 01010 10010 0000000000001000 5 10 18 8 Bits 6 5 5 16 First Source Register Second Source Register Immediate EE108b Lecture 4 C. Kozyrakis 10 PC Relative Addressing • How can we improve our use of immediate addresses when branching? • Since instructions are always 32 bits long and word addressing requires alignment, every address must be a multiple of 4 bytes • Therefore, we actually branch to the address that is PC + 4 + 4 × immediate EE108b Lecture 4 C. Kozyrakis 11 I-Format Example • Re-consider the bne instruction bne $t2, $s2, Exit # goto Exit if $t2 != $s2 • Use PC-Relative addressing for the immediate 000101 01010 10010 0000000000000010 5 10 18 2 Bits 6 5 5 16 First Source Register Second Source Register Immediate
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 13

lect.04.Assembly3.4up - Announcements PA1 available, due on...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online