Question

In: Computer Science

Basic arithmetic calculation. Use instruction “li” to initialize register $t1 with a constant value 10. li...

  1. Basic arithmetic calculation.
    1. Use instruction “li” to initialize register $t1 with a constant value 10.

li $t1, 10   # [$t1] <- 10

finish the following calculation using MIPS assembly code.

$t2 = $t1 + $t1

$t3 = $t1 << 2 (shift to left by 2 bits)

$t4 = $t1 & 0x0000ffff (bitwise AND)

$t5 = $t1 | 0x0000fffff (bitwise OR)

$t6 = $t2 + $t3 + $t4 + $t5

Write MIPS assembly code to finish the above calculation and print out the result, value of $t6.

Solutions

Expert Solution

Write MIPS assembly language code to perform the following calculation and print the result in $t6:

$t1 = 10

$t2 = $t1 + $t1

$t3 = $t1 << 2 (shift to left by 2 bits)

$t4 = $t1 & 0x0000ffff (bitwise AND)

$t5 = $t1 | 0x0000fffff (bitwise OR)

$t6 = $t2 + $t3 + $t4 + $t5

Answer:

li $t1, 10

add $t2, $t1, $t1

sll $t3, $t1, 2

andi $t4, $t1, 0xFFFF

ori $t5, $t1, 0xFFFF

add $t8, $t2, $t3

add $t9, $t4, $t5

add $t6, $t8, $t9

li $v0, 1

move $a0, $t6

syscall

Description:

Assembly code:

Instruction Description:

li $t1, 10 # load the immediate value 10 in $t1 register.

add $t2, $t1, $t1 # addition of $t1 and $t1 and then store the result in $t2 register.

sll $t3, $t1, 2 # shift left logical $t1 by 2 bits and store the result in $t3 register.

andi $t4, $t1, 0xFFFF # Bitwise and immediate of $t1 and 0xFFFF, store the result in $t4.

ori $t5, $t1, 0xFFFF # Bitwise or immediate of $t1 and 0xFFFF, store the result in $t5.

add $t8, $t2, $t3 #  addition of $t2 and $t3 and then store the result in $t8 register.

add $t9, $t4, $t5 # addition of $t4 and $t5 and then store the result in $t9 register.

add $t6, $t8, $t9 # $t6 = $8 + $t9 = $t2 + $t3 + $t4 + $t5

li $v0, 1 # $v0 = 1 system call means that we want to display or print an integer

move $a0, $t6 # System call will look at $a0 to print the value. (move $t6 to $a0)

syscall


Related Solutions

a) What is the static instruction count and what is the dynamic instruction count? li $t1,...
a) What is the static instruction count and what is the dynamic instruction count? li $t1, 10 addi $s2, $0, 0 LOOP: slt $t2, $0, $t1 beq $t2, $0, DONE addi $t1, $t1, -1 addi $s2, $s2, 2 j LOOP DONE:
Consider the following C code: (10 marks) // write a MIPS instruction to initialize s0 to...
Consider the following C code: // write a MIPS instruction to initialize s0 to 6 t0 = ((s03 - 93)2 + s0 ) << 2 t1 = t0 / 4 Q2.1: Write a MIPS program that performs the operation of the above C program. Q2.2: What is the value of $t0 and $t1 after running your MIPS program (write your answer in a comment at the end of the code). Submit your answer to Q2 in a file named A2_Q2.asm
Assume that for a given program 70% of the executed instruction are arithmetic, 10% are load/store,...
Assume that for a given program 70% of the executed instruction are arithmetic, 10% are load/store, and 20% are branch. i. Given the instruction mix and the assumption that an arithmetic instruction requires 2 cycles, a load/store instruction takes 6 cycles, and a branch instruction takes 3 cycles, ?nd the average CPI. ii. For a 25% improvement in performance, how many cycles, on average, may an arithmetic instruction take if load/store and branch instructions are not improved at all.
What is the Opcode? What is the Operand? What is the value in Register 5 after the instruction is executed?
What is the Opcode? What is the Operand? What is the value in Register 5 after the instruction is executed?
Complete the corresponding assembly language fragments by selecting the correct instruction, register, or value: (Choices in...
Complete the corresponding assembly language fragments by selecting the correct instruction, register, or value: (Choices in bold) a) Consider the following fragment of C code: if(a == b) {        x += 10;        A[50] = A[50] +x; } else {         y += 10;         A[50] = A[50] + y; } Assume that variables a, b, x and y are assigned to $s0, $s1, $s2 and $s3 respectively and the base address for array A is in $s4. Only...
> * Read the high value. > 1- First, initialize the constant NUMS as 3: NUMS=3...
> * Read the high value. > 1- First, initialize the constant NUMS as 3: NUMS=3 2- Print the title of the application. >---=== Python Temperature Analyzer ===---< Enter the high value for day 1: < (or day 2, or day 3) Enter the low value for day 1: < (or day 2, or day 3) 3- Using a for loop, prompt the user to enter the high and low values for each of NUMS days. The values entered must...
3.21 [10] <§3.5> If the bit pattern 0×0C000000 is placed into the Instruction Register, what MIPS...
3.21 [10] <§3.5> If the bit pattern 0×0C000000 is placed into the Instruction Register, what MIPS instruction will be executed? 3.22 [10] <§3.5> What decimal number does the bit pattern 0×0C000000 represent if it is a floating point number? Use the IEEE 754 standard. Given the following 32-bit binary sequences representing single precision IEEE 754 floating point numbers: a = 0100 0000 1101 1000 0000 0000 0000 0000 b = 1011 1110 1110 0000 0000 0000 0000 0000 Perform the...
* Read the high value. > 1- First, initialize the constant NUMS as 3: NUMS=3 2-...
* Read the high value. > 1- First, initialize the constant NUMS as 3: NUMS=3 2- Print the title of the application. >---=== Python Temperature Analyzer ===---<. 3- Using a for loop, prompt the user to enter the high and low values for each of NUMS days. The values entered must be between -40 and 40, and high must be greater than low. Print the following messages: > Enter the high value for day 1: < (or day 2, or...
The value of the solubility product constant for silver carbonate is 8.5 × 10-12 and that...
The value of the solubility product constant for silver carbonate is 8.5 × 10-12 and that of silver chromate is 1.1 × 10-12. From this data, what is the value of Kc for the reaction, Ag2CO3(s) + CrO42-(aq) ⇆ Ag2CrO4(s) + CO32-(aq)
Use the solubility-product constant for Cr (OH) 3 ( Ksp = 6.7×10?31) and the formation constant...
Use the solubility-product constant for Cr (OH) 3 ( Ksp = 6.7×10?31) and the formation constant for Cr (OH) ?4 from the following table to determine the concentration of Cr (OH) ?4 in a solution that is buffered at pH= 11 and is in equilibrium with solid Cr (OH) 3. Table Formation Constants for Some Metal Complex Ions in Water at 25 ?C Complex Ion Kf Equilibrium Equation Ag(NH3)+2 1.7×107 Ag+(aq)+2NH3(aq)?Ag(NH3)+2(aq) Ag(CN)?2 1×1021 Ag+(aq)+2CN?(aq)?Ag(CN)?2(aq) Ag(S2O3)3?2 2.9×1013 Ag+(aq)+2S2O2?3(aq)?Ag(S2O3)3?2(aq) CdBr2?4 5×103 Cd2+(aq)+4Br?(aq)?CdBr2?4(aq)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT