Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
EE 333 Fall 2006 Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions Lillevik 333f06-l5 University of Portland School of Engineering 1 EE 333 Fall 2006 Last time • MIPS assembly language • Arithmetic and logic instructions • Load and store instructions Lillevik 333f06-l5 University of Portland School of Engineering 2 EE 333 Fall 2006 Write the program? result 6 alpha beta Lillevik 333f06-l5 University of Portland School of Engineering 3 EE 333 Fall 2006 Lets run the program Lillevik 333f06-l5 University of Portland School of Engineering 4 EE 333 Fall 2006 Instruction Classes • √ • √ • • • • • Arithmetic and logic (some more) Load: li, la, lbu, lw Store: sb, sw Comparison Branch and jump Data Movement Floating Point Lillevik 333f06-l5 University of Portland School of Engineering 5 EE 333 Fall 2006 Arithmetic and Logic Instruction Example Meaning And and $s1, $s2, $s3 $s1 = $s2 & $s3 And immediate andi $s1, $s2, 100 $s1 = $s2 & 100 Or or $s1, $s2, $s3 $s1 = $s2 | $s3 Or immediate ori $s1, $s2, 100 $s1 = $s2 | 100 Shift left logical sll $s1, $s2, 10 $s1 = $s2 << 10 Shift right logical srl $s1, $s2, 10 $s1 = $s2 >> 10 Only registers used for operands Lillevik 333f06-l5 University of Portland School of Engineering 6 EE 333 Fall 2006 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 Lillevik 333f06-l5 University of Portland School of Engineering 7 EE 333 Fall 2006 Branch and Jump Instruction Example Meaning Branch on equal beq $s1, $s2, 100 If ($s1 = = $s2 ) go to (PC +4 )+ 100 Branch on not equal bne $s1, $s2, 100 If ($s1 ! = $s2 ) go to (PC +4 )+ 100 Jump j loop Go to loop: Jump and link jal subroutine $ra = PC + 4, go to subroutine Jump Register jr $ra PC = $ra Lillevik 333f06-l5 University of Portland School of Engineering 8 EE 333 Fall 2006 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 Lillevik 333f06-l5 University of Portland School of Engineering 9 EE 333 Fall 2006 Flowchart of loop count = 5 count -- yes count = = 0 ? no Body of loop Lillevik 333f06-l5 University of Portland Body could go ahead of test School of Engineering 10 EE 333 Fall 2006 Loops NOTE: you may place the check after the body How many times is “body” executed? (4 or 5? Lillevik 333f06-l5 University of Portland School of Engineering 11 EE 333 Fall 2006 Lets run the program Lillevik 333f06-l5 University of Portland School of Engineering 12 EE 333 Fall 2006 Write the program? Write a loop that adds 4 to $t2, six times Lillevik 333f06-l5 University of Portland School of Engineering 13 EE 333 Fall 2006 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 Lillevik 333f06-l5 University of Portland NOTE: Result of assembly is a machine instruction School of Engineering 14 EE 333 Fall 2006 Instruction Formats Name Fields Size 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits R type op rs rt rd shamt funct I type op rs rt J type op address/immediate target address 32-bits All instructions are 32-bits long Lillevik 333f06-l5 University of Portland School of Engineering 15 EE 333 Fall 2006 R-format • Operation (op) code All 0x00; exception mfc0 = 0x10, • Funct determines specific instruction add = 0x20, sub = 0x22, mult = 0x18, div = 0x1a • Operands Shamt = shift amount – rd = destination register – rs = first argument – rt = second argument Lillevik 333f06-l5 University of Portland School of Engineering 16 EE 333 Fall 2006 R-format example add $2, $3, $4 add rd, rs, rt R type Fields Size 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits R type op rs rt rd shamt funct 00 0000 0 0011 0 0100 0 0010 0 0000 10 0000 0000 0000 0110 0100 0001 0000 0010 0000 0x 0064 1020 Lillevik 333f06-l5 University of Portland School of Engineering 17 EE 333 Fall 2006 Find machine instruction? sub $10, $6, $16 sub rd, rs, rt R type Fields Size 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits R type op rs rt rd shamt funct 00 0000 0 0110 1 0000 0 1010 0 0000 10 0010 0x00d05022 Lillevik 333f06-l5 University of Portland School of Engineering 18 EE 333 Fall 2006 I-format • Op code examples lw = 0x23, sw = 0x2b, beq = 0x04 • Operands – rs = first argument – rt = second argument • Immediate = sign extended bits [15 – 0] Lillevik 333f06-l5 University of Portland School of Engineering 19 EE 333 Fall 2006 I-format example lw $2, 100($3) lw rt, adr (rs) Name Fields Size 6 bits 5 bits 5 bits 16 bits I type op rs rt address/immediate 10 0011 0 0011 0 0010 0000 0000 0110 0100 1000 1100 0110 0010 0000 0000 0110 0100 0x 8c62 0064 Lillevik 333f06-l5 University of Portland School of Engineering 20 EE 333 Fall 2006 Find machine instruction? sw sw $20, 64($8) rt, adr (rs) Name Fields Size 6 bits 5 bits 5 bits 16 bits I type op rs rt address/immediate 101011 0 1000 1 0100 0000 0000 0100 0000 0xad14 0040 Lillevik 333f06-l5 University of Portland School of Engineering 21 EE 333 Lillevik 333f06-l5 Fall 2006 University of Portland School of Engineering 22 EE 333 Fall 2006 Write the program? Write a loop that adds 4 to $t2, six times Lillevik 333f06-l5 University of Portland School of Engineering 23 EE 333 Fall 2006 Find machine instruction? sub $10, $6, $16 sub rd, rs, rt R type Fields Size 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits R type op rs rt rd shamt funct 00 0000 0 0110 1 0000 0 1010 0 0000 10 0010 0x 00d0 5022 Lillevik 333f06-l5 University of Portland School of Engineering 24 EE 333 Fall 2006 Find machine instruction? sw sw $20, 64($8) rt, adr (rs) Name Fields Size 6 bits 5 bits 5 bits 16 bits I type op rs rt address/immediate 10 1011 0 1000 1 0100 0000 0000 0100 0000 0x ad14 0040 Lillevik 333f06-l5 University of Portland School of Engineering 25