Question: Assembly language LC2200 write an assembly language program equivalent to the following: a = 0; for (int i = 0; i < d; i++) {

Assembly language LC2200

write an assembly language program equivalent to the following:

a = 0;

for (int i = 0; i < d; i++)

{

if (c != d)

a += b + (c - d) + b;

else if (c == b)

a += c + c + c + c;

else

a += (b + b) - (c + c);

}

where:

a is located in $fp + 1

b is located in $fp + 2

c is located in $fp + 3

d is located in $fp + 4

Values should be read in from memory to start with and a should be written to memory when done. You can reorder

operations as long as they produce the same result as the statement above. You should be able to run this assembly file with

different data files.

The variable i can be located in a variable or just kept in a register, whichever you prefer. This code expects that d > 0.

Inside for loop:

lw $t0, $fp, 2 lw $t1, $fp, 3 lw $t2, $fp, 4 beq $t0, $t1, cbequal

nand $t2, $t2, $t2 addi $t2, $t2, 1 #convert $t2 for negative add $t1, $t2, $t1 #c-d = t1 add $t0, $t0, $t0 add $t0, $t1, $t0 lw $t2, $fp,1 add $t2, $t0, $t2 sw $t2, $fp, 1 halt

cbequal: beq $t1, $t2, equal

add $t0, $t0, $t0 add $t1 ,$t1, $t1 nand $t1 ,$t1, $t1 addi $t1, $t1, 1 add $t0, $t0, $t1 lw $t1, $fp, 1 add $t1, $t1, $t0 sw $t1, $fp, 1 halt

equal:add $t0, $t1, $t1 add $t0, $t1, $t0 add $t0, $t1, $t0 lw $t2, $fp, 1 add $t0, $t0, $t2 sw $t0, $fp, 1 halt

And tomake for loop work I have to use jalr, but I have no clue how to make for loop work...

Thank you in advance.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!