Lab 7 Given 1010 1100 0101 0000 0000
Lab 7
• Given: 1010 1100 0101 0000 0000 Two’s complement integer -231 + 229 + 227 + 226 + 222 + 220 A single precision floating-point number 010 1100 0 two = 88, bias = 127 1. 101 two = 1 + 1*2 -1+1*2 -3 = 1. 625 -1. 625 × 288 -127 A MIPS instruction sw $16, 0($2)
To add slt to 32 -bit ALU that support OR, AND, addition 1. Expand the multiplexor of each bit of the ALU by adding one more input (called LESS line, denoted by LESS 0, LESS 1, … LESS 31) – to output 0 for all the 31 higher bits and 0/1 for the least significant bit. 2. Hard wire the LESS lines of all the 31 higher bits of the ALU to 0 3. Connect SUM 31 to LESS 0. (Set the control of the ALU to 0111. )
Given: 8 -bit floating-point format mimic IEEE 75 Sign Exp s 3 bits Bias = 3 – 2. 75 = 1 Significand 4 bits 100 0110 0 101 0011 = 4. 75 Smallest non-zero number = 0. 015625 0 0001
Proj 2 • Input 2 integer number. • Input operation +, -, /, *. • Print out the calculated result. – Shouldn’t use mul*, div*.
System Calls (Reminder) Service System call code Arguments Result print_int 1 $a 0 = integer print_float 2 $f 12 = float print_double 3 $f 12 = double print_string 4 $a 0 = string read_int 5 integer (in $v 0) read_float 6 float (in $f 0) read_double 7 double (in $f 0) read_string 8 $a 0=buffer, $a 1=len sbrk 9 $a 0 = amount exit 10 address (in $v 0)
. text. globl main: # $s 0 = the first integer # $s 1 = the second integer # $s 2 = the operation # Print out $s 0 $s 2 $s 1 = li $v 0, 10 syscall. data input_str 1: . asciiz “Please enter the first operand: ” input_str 2: . asciiz “Please enter the second operand: ” op_str: . asciiz “Please enter the operation (+, -, /, *): ” op: . space 3
Multiplication slt $s 4, $s 0, 0 if ( $s 4 == 1) $s 0 = $zero - $s 0; slt $s 5, $s 1, 0 if ( $s 5 == 1) $s 1 = $zero - $s 1; $s 3 = $s 0 * $s 1 $t 0 = $s 4 + $s 5 if($t 0 == 1) $s 3 = $zero - $s 3;
Multiplication If Multiplier is 0?
Multiplication • Check if the least significant bit is 1 – and $t 0, $t 1, 1 $s 3 = 0; // $s 3 will store the result do{ if($s 1 == 0) break; and $t 0, $s 1, 1 if ( $t 0 == 1) $s 3 = $s 3 + $s 0; $s 0 = $s 0 << 1 $s 1 = $s 1 >> 1 }while (true)
Division slt $s 4, $s 0, 0 if ( $s 4 == 1) $s 0 = $zero - $s 0; slt $s 5, $s 0, 0 if ( $s 5 == 1) $s 1 = $zero - $s 1; $s 3 = $s 0 / $s 1 $t 0 = $s 4 + $s 5 if($t 0 == 1) $s 3 = $zero - $s 3; If divisor == 0, return error message.
Division Divisor register Start: Place Dividend in Remainder Divisor Remainder register Dividend 1. Subtract the Divisor register from the Remainder register, and place the result in the Remainder register. Remainder 0 2 a. Shift the Quotient register to the left setting the new rightmost bit to 1. Test Remainder < 0 2 b. Restore the original value by adding the Divisor register to the Remainder register, & place the sum in the Remainder register. Also shift the Quotient register to the left, setting the new least significant bit to 0. 3. Shift the Divisor register right 1 bit. 33 repetition? No: < 33 repetitions Yes: 33 repetitions Done
- Slides: 12