Simple Assembly Language 1How many clock cycles does the fol

Simple Assembly Language

1.How many clock cycles does the following code take.

li $t2, -64

lw $t1, 0($t6)

mul $t1, $t1, $t2

sw $t1, 0($t6)

2.Rewrite the code in question 1 to make it significantly faster.

Solution

li $t2, -64 // loads the numeric value(-64) into the register $t2 this instruction takes one clock cycle.

lw $t1, 0($t6) // here the operands is in memory and it is loaded into the register

$t1 // the address is the sum of register the operand value 0($t6)…B[i+2] this instruction takes one clock cycle.

mul $t1, $t1, $t2//multiply the operands of register $t1 and $t1 and the result of these two will be stored in another register and then it will be multiply with the 3rd value. This instruction takes three cylces

sw $t1, 0($t6)//store the integer2 in $t1 and then save it in the location in the address where other instruction are loaded and

hene the instruction takes only three clock cycle.

The MIPS assembly sequence is as follows:

li $t2, -64               #load Address of A

lw $t1, 0($t6)         #loadB[i+2],

mul $t1, $t1, $t2    # A[i] * B[i+2]

sw $t1, 0($t6)          #save and return the address

After rewriting the code it will run significantly faster and will take only one clock cylce

lw $t1, 0($t6)

li $t2, -64              

mul $t1, $t1, $t2   

sw $t1, 0($t6)        

Simple Assembly Language 1.How many clock cycles does the following code take. li $t2, -64 lw $t1, 0($t6) mul $t1, $t1, $t2 sw $t1, 0($t6) 2.Rewrite the code in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site