lect.03.Assembly2.4up

# lect.03.Assembly2.4up - Announcements Urgent: sign up at...

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

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

View Full Document
EE108b Lecture 3 C. Kozyrakis 5 Today’s Menu • Finish Memory data transfer – Stores – Data alignment – Memory mapped I/O • Control transfer instructions – Branches and jumps • Machine language design – Binary encoding of assembly instructions – 3 MIPS instruction formats EE108b Lecture 3 C. Kozyrakis 6 Storing Data • Storing data is just the reverse and the instruction is nearly identical • Use the sw instruction to copy a word from the source register to an address in memory sw src, offset(base) • Offset value is signed EE108b Lecture 3 C. Kozyrakis 7 Storing Data Example • Consider the example *a = b + c; • Use the sw instruction to store add \$t0, \$s1, \$s2 # \$t0 = b + c sw \$t0, 0(\$s0) # Memory[s0] = b + c EE108b Lecture 3 C. Kozyrakis 8 Storing to an Array • Consider the example a[3] = b + c; • Use the sw instruction offset add \$t0, \$s1, \$s2 # \$t0 = b + c sw \$t0, 12(\$s0) # Memory[a[3]] = b + c
EE108b Lecture 3 C. Kozyrakis 9 Complex Array Storage • Consider the example a[i] = b + c; • Use the sw instruction offset add \$t0, \$s1, \$s2 # \$t0 = b + c sll \$t1, \$s3, 2 # \$t1 = 4 * i add \$t2, \$s0, \$t1 # \$t2 = a + 4*i sw \$t0, 0(\$t2) # Memory[a[i]] = b + c EE108b Lecture 3 C. Kozyrakis 10 A “short” Array Example • ANSI C requires a short to be at least 16 bits and no longer than an int, but does not define the exact size • For our purposes, treat a short as 2 bytes • So, with a short array c[7] is at c + 7 * 2, shift left by 1 c[7] c[6] c[5] c[4] c[3] c[2] c[1] c[0] 1000 2 bytes c 1014 1004 1008 1012 1016 1002 1006 1010 EE108b Lecture 3 C. Kozyrakis 11 MIPS Integer Load/Store Instruction Example Meaning Comments load word lw \$1, 8(\$2) \$1=Mem[8+\$2]

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 03/08/2011 for the course EE 108B at Stanford.

### Page1 / 14

lect.03.Assembly2.4up - Announcements Urgent: sign up at...

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

View Full Document
Ask a homework question - tutors are online