Spring 2014 jan 24 spring elec 5200 0016200 001

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: 16 bit number Where's the compromise? Spring 2014, Jan 24 . . . Spring ELEC 5200-001/6200-001 Lecture 3 2004 © Morgan Kaufman Publishers 22 Stored Program Concept Instructions are bits Programs are stored in memory Programs to be read or written just like data to Processor Memory memory for data, programs, compilers, editors, etc. Fetch and Execute Cycles Instructions are fetched and put into a special register Opcode bits in the register "control" the subsequent actions Fetch the “next” instruction and continue 2004 © Morgan Kaufman Publishers Spring 2014, Jan 24 . . . Spring ELEC 5200-001/6200-001 Lecture 3 23 Control Decision making instructions – alter the control flow, – i.e., change the "next" instruction to be executed MIPS conditional branch instructions: bne $t0, $t1, Label beq $t0, $t1, Label Example: Example: if (i==j) h = i + j; bne $s0, $s1, Label add $s3, $s0, $s1 Label: .... 2004 © Morgan Kaufman Publishers Spring 2014, Jan 24 . . . Spring ELEC 5200-001/6200-001 Lecture 3 24 Control MIPS unconditional branch instructions: j label Example: if (i!=j) beq $s4, $s5, Lab1 h=i+j; add $s3, $s4, $s5 else j Lab2 h=i-j; Lab1:sub $s3, $s4, $s5 Lab2: ... Can you build a simple for loop? loop 2004 © Morgan Kaufman Publishers Spring 2014, Jan 24 . . . Spring ELEC 5200-001/6200-001 Lecture 3 25 So Far We’ve Learned Instruction add $s1,$s2,$s3 sub $s1,$s2,$s3 lw $s1,100($s2) sw $s1,100($s2) bne $s4,$s5,Label beq $s4,$s5,Label j Label Formats: Meaning $s1 = $s2 + $s3 $s1 = $s2 – $s3 $s1 = Memory[$s2+100] Memory[$s2+100] = $s1 Next instr. is at Label if $s4 ≠ $s5 Next instr. is at Label if $s4 = $s5 Next instr. is at Label R op rs rt rd I op rs rt 16 bit address J op shamt funct 26 bit address 2004 © Morgan Kaufman Publishers Spring 2014, Jan 24 . . . Spring ELEC 5200-001/6200-001 Lecture 3 26 Three Ways to Jump: j, jr, jal j instr jr $ra jal addr Spring 2014, Jan 24 . . . Spring # jjump to machine instruction instr ump instr (unconditional jump) (unconditional # jump to address in register ra (used by calee to go back to caller) (used # set $ra = PC+4 and go to addr set addr (jump and link; used to jump to a procedure) ELEC 5200-001/6200-001 Lecture 3 27 Control Flow We have: beq, bne, what about Branch-if-less-than? New instruction: if $s1 < $s2 then $t0 = 1 slt $t0, $s1, $s2 else $t0 = 0 Can use this instruction to build new “pseudoinstruction” blt $s1, $s2, Label Note that the assembler needs a register to do this, Note — there are policy of use conventions for registers 2004 © Morgan Kaufman Publishers Spring 2014, Jan 24 . . . Spring ELEC 5200-001/6200-001 Lecture 3 28 Pseudoinstructions blt $s1, $s2, reladdr Assembler converts to: slt $1, $s1, $s2 slt bne $1, $zero, reladdr Other pseudoinstructions: bgt, ble, bge, li, move Not implemented in hardware Assembler expands pseudoinstructions into Assembler machine instructions machine Register 1, called $at, is reserved for converting Register pseudoinstructions into machine c...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online