Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Last time MIPS assembly language Arithmetic and logic instructions Load and store instructions
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Write the program?
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Lets run the program
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Instruction Classes Arithmetic and logic (some more) Load: li, la, lbu, lw Store: sb, sw Comparison Branch and jump Data Movement Floating Point √ √
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Arithmetic and Logic InstructionExampleMeaning Andand $s1, $s2, $s3$s1 = $s2 & $s3 And immediateandi $s1, $s2, 100$s1 = $s2 & 100 Oror $s1, $s2, $s3$s1 = $s2 | $s3 Or immediateori $s1, $s2, 100$s1 = $s2 | 100 Shift left logicalsll $s1, $s2, 10$s1 = $s2 << 10 Shift right logicalsrl $s1, $s2, 10$s1 = $s2 >> 10 Only registers used for operands
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Instruction Classes Arithmetic and logic: add, sub, and, or Load: li, la, lbu, lw Store: sb, sw Comparison Branch and jump Data Movement Floating Point √ √ √
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Branch and Jump InstructionExampleMeaning Branch on equalbeq $s1, $s2, 100If ($s1 = = $s2 ) go to (PC +4 )+ 100 Branch on not equalbne $s1, $s2, 100If ($s1 ! = $s2 ) go to (PC +4 )+ 100 Jumpj loopGo to loop: Jump and linkjal subroutine$ra = PC + 4, go to subroutine Jump Registerjr $raPC = $ra
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Loops in assembly Initialize loop counter Modify counter (decrement, increment) Check if counter = = end condition –True, leave loop –False, continue with loop Body of loop Continue with next pass in loop
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Flowchart of loop count = 5 count -- count = = 0 ? Body of loop no yes Body could go ahead of test
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Loops NOTE: you may place the check after the body How many times is “body” executed? (4 or 5?
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Lets run the program
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Write the program? Write a loop that adds 4 to $t2, six times
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Machine Instructions Definition: numeric (hex) versions of instruction Memory: contains binary number or machine instruction, it’s what the hardware executes Formats –R, register –I, immediate –J, jump NOTE: Result of assembly is a machine instruction
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Instruction Formats NameFields Size 6 bits5 bits 6 bits R typeoprsrtrdshamtfunct I typeoprsrtaddress/immediate J typeoptarget address All instructions are 32-bits long 32-bits
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering R-format Operation (op) code All 0x00; exception mfc0 = 0x10, Funct determines specific instruction add = 0x20, sub = 0x22, mult = 0x18, div = 0x1a Operands –rd = destination register –rs = first argument –rt = second argument Shamt = shift amount
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering R-format example R typeFields Size 6 bits5 bits 6 bits R typeoprsrtrdshamtfunct add$2, $3, $4 addrd, rs, rt x
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Find machine instruction? 0x00d05022 R typeFields Size 6 bits5 bits 6 bits R typeoprsrtrdshamtfunct sub$10, $6, $16 sub rd, rs, rt
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering I-format Op code examples lw = 0x23, sw = 0x2b, beq = 0x04 Operands –rs = first argument –rt = second argument Immediate = sign extended bits [15 – 0]
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering I-format example lw$2, 100($3) lwrt, adr (rs) x 8c NameFields Size 6 bits5 bits 16 bits I typeoprsrtaddress/immediate
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Find machine instruction? NameFields Size 6 bits5 bits 16 bits I typeoprsrtaddress/immediate sw$20, 64($8) swrt, adr (rs) 0xad
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Write the program? Write a loop that adds 4 to $t2, six times
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Find machine instruction? 0x 00d R typeFields Size 6 bits5 bits 6 bits R typeoprsrtrdshamtfunct sub$10, $6, $16 sub rd, rs, rt
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Find machine instruction? NameFields Size 6 bits5 bits 16 bits I typeoprsrtaddress/immediate sw$20, 64($8) swrt, adr (rs) 0x ad