CS312-CH2 - Ch 2 Instructions: Language of the Computer...

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

View Full Document Right Arrow Icon
Click to edit Master subtitle style 8/27/09 Ch 2 Instructions: Language of the Computer
Background image of page 1

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

View Full DocumentRight Arrow Icon
8/27/09 Introduction Instructions are the language of computer hardware Specific hardware uses a specific instruction set We will use the MIPS instruction set MIPS – Microprocessor without Interlocked Pipeline Stages
Background image of page 2
8/27/09 Operations - arithmetic Each instruction does one operation Takes three operands #this is a comment a = b + c + d+ e a = b + 10 add a, b, c # a = b + c add a, b, c # a = b + c add a, a, d # a = a + d add a, a, e # a = a + e addi a, b, 10 # a = b + 10
Background image of page 3

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

View Full DocumentRight Arrow Icon
8/27/09 Operations – arithmetic Subtraction: Why only allow 3 operands? We are now dealing closely with hardware Simplicity is favorable over flexibility Higher layers of abstraction can add extra operands. sub a, b, c # a = b - c
Background image of page 4
8/27/09 Operations – arithmetic Practice: f = (a + b) – (c – d) Use two temporary variables t0 and t1. add t0, a, b sub t1, c, d sub f, t0, t1
Background image of page 5

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

View Full DocumentRight Arrow Icon
8/27/09 Operands We are also restricted to a set of operands by the hardware MIPS has 32 registers Each is 32 bits long (word size) MIPS assembly language uses a naming convention like: $s0, $s1, $s2 for variable names and $t0 for temporary variables
Background image of page 6
8/27/09 Operands Observation: The compiler associates variables with registers Translate the following C statement to MIPS f = (a + b) – (c – d) assume the compiler has made the following register assignments f:$s0 a:$s1 b:$s2 c:$s3 d:$s4 add $t0, $s1, $s2 # $t0 = a + b sub $t1, $s3, $s4 # $t1 = c – d sub $s0, $t0, $t1 # f = $t0 - $t1 or (a + b) – (c – d)
Background image of page 7

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

View Full DocumentRight Arrow Icon
8/27/09 Memory Operands What about more complex data types? Much to large for our register set Must use the computers memory Utilizes the processor with data transfer instruction This is a load, the actual MIPS
Background image of page 8
8/27/09 Operands lw – load word transfer data from memory to register lw $s0 2($s3) # $s0 gets contents of ($s3 + 2) operation destination register address constan t offset base register
Background image of page 9

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

View Full DocumentRight Arrow Icon
8/27/09 Memory Operands Load word 16 1 9 9 316 12 F 5 C 116 8 B 0 2 816 4 7 F F 216 0 0 5 A 716 Dat a Addre ss lw $s1, 8($s2) # $s1 = Memory[$s2+8]
Background image of page 10
8/27/09 Operands Translate the following C statement to MIPS g = h + A[8]; assume the following register mappings: g:$s1 h:$s2 A:$s3 lw $t0 8($s3) # load A[8] into $t0 add $s1, $s2, $t0 # g = h + A[8]
Background image of page 11

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

View Full DocumentRight Arrow Icon
8/27/09 Memory Operands Of course we can store words also: sw sw $t1, 40($s3) #$memory[s3 + 40] = $t1
Background image of page 12
8/27/09 ch3-Instructions.ppt
Background image of page 13

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

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

Page1 / 43

CS312-CH2 - Ch 2 Instructions: Language of the Computer...

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

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