Question

Convert each of the below C code snippet to LEGv8 assembly code. Assume variable a, b,...

Convert each of the below C code snippet to LEGv8 assembly code. Assume variable a, b, and c is stored in registers X19, X20, and X21 respectively. Base address of d is stored in register X22. Comment your assembly code. (24 Points)

a. if (a > b) d[a] = b + 8;

else d[a] = b - 16;

b. for (i=0;i<a; i++)

a = d[i] + c;

c. i = 0;

while ( d[i] == b)

if(( a - i ) > 0) i++;

Homework Answers

Answer #1

let a= s0, b= s1, d[a]= s2, whileb is not considered let c= s1

a) bgez $s0, $s1, greater           \\ if (a > b)

blez $s0, $s1, smaller               \\ if (a < b)

greater: addu $s2, $s1, 8            \\ d[a] = b + 8

smaller: sub $s2, $s1,16            \\ d[a] = b - 16

b) ori $s5, $s0, 0                       \\ i=0

la $s6, d                                     \\ $s6= d;

l1: bge $s5, $s1, done               \\ i<a   

lw s7 ,0($s6)                              \\ $s7= d[i]

addu $s0, $s7, $s1                    \\ a = d[i] + c

j update

update: addi $s5, $s5, 1           \\ i++

addi $s6, $s6, 4

j l1

done: .data                      \\ initialize data

c) ori $s5, $s0, 0             \\ i=0

lw $s7 ,0($s6)​                   \\ $s7= d[i]

l1: bne $s7, $s1, done

sub $s4, $s0, $s5

ble $s4, done

add $s1, $s1, 1

j l1

done: exit

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Convert each of the below C code snippet to LEGv8 assembly code. Assume the variables a,...
Convert each of the below C code snippet to LEGv8 assembly code. Assume the variables a, b, and c are stored in registers X19, X20, and X21 respectively. Base address of d is stored in register X22. Comment your assembly code. a. if (a > b) d[a] = b + 8; else d[a] = b - 16; b. for (i=0;i 0) i++; a = d[i] + c; c. i = 0; while (d[i] == b) if ((a - i) >...
Write the C55x assembly code for each of the following C snippet code shown below. Assume...
Write the C55x assembly code for each of the following C snippet code shown below. Assume the 8-bit values a, b, c, and d are stored in locations 0x600, 0x601, 0x602, and 0x603 respectively in the memory. Store the result x in location 0x604 and y in location 0x60C. Do not use software to generate the assembly code and comment your code. x = (a - b)3 - (c*d); for (j=0;j<=200;j++)   y = y + (a * b);
Implement the following C code in LEGv8 assembly. Hint: Remember that the stack pointer must remain...
Implement the following C code in LEGv8 assembly. Hint: Remember that the stack pointer must remain aligned on a multiple of 16. int fib (int n) { if (n==0) return 0; else if (n == 1) return 1; else return fib(n−1) + fib(n−2); } please "LEGv8" ! thanx :-)
2. (7 pts) Translate the following block of C code to MIPS assembly: if (i >...
2. (7 pts) Translate the following block of C code to MIPS assembly: if (i > 10) MemArray[i] = 0; else MemArray[i] = - MemArray[i]; Assume that the variable i is bound to register $t0, and that the base address of array MemArray is in register $s0.
For the MIPS assembly instructions below, what is the corresponding C statement? Assume that the variables...
For the MIPS assembly instructions below, what is the corresponding C statement? Assume that the variables f, g, h, and I are assigned to registers $s0 - $s3, respectively. Assume that the base address of arrays X, Y, and Z are in registers $s4 - $s6, respectively. Be conservative and use a single temp register as possible. It is a C arithmetic command with two source operands and a destination. Each part is 3 points. Add $t0, $s0, $s1 addi...
2.  Suppose we have 3 arrays A, B, and C, array A’s base address is in $S3,...
2.  Suppose we have 3 arrays A, B, and C, array A’s base address is in $S3, B’s base address is in $S4, C’s base address is in $S5. You can only use two temporal registers $t0 and $t1. Convert the following code into MIPS assembly language code. Suppose every array element occupies 1 word in MIPS (32 bits). A[21] = B[0] + C[16];
Create three address code from the program snippet below. int a = 2, b = 8,...
Create three address code from the program snippet below. int a = 2, b = 8, c = 4, d; for (j = 0; j <= 10; j ++) ( a = a * (j * (b / c)); d = a * (j * (b / c)); }
1. Given Hexadecimal EDCC16 Detail steps are required. 1) What is the binary representation? 2) What...
1. Given Hexadecimal EDCC16 Detail steps are required. 1) What is the binary representation? 2) What is the negation of EDCC in HEX? 3) Convert it to decimal number if this is a 2s-complement signed binary representation in 16- bit register 4) Convert it to decimal number if this is an unsigned binary representation in 16-bit 2. Suppose we have 3 arrays A, B, and C, array A’s base address is in $S3, B’s base address is in $S4, C’s...
1a. Using the MIPS program below (with bugs intact), determine the instruction format for each instruction...
1a. Using the MIPS program below (with bugs intact), determine the instruction format for each instruction and write the decimal values of each instruction field. addi $v0, $zero, 0 loop: lw $v1, 0($a0) sw $v1, 0($a1) sll $a0, $a0, 2 add $a1, $a1, $a0 beq $v1, $zero, loop 1b. Translate the following C/Java code to MIPS assembly code. Assume that the values of a, i, and j are in registers $s0, $t0, and $t1, respectively. Assume that register $s2 holds...
This is a homework assignment for Computer Architecture and some question use MIPS Assembly language. 1.    ...
This is a homework assignment for Computer Architecture and some question use MIPS Assembly language. 1.     In the following MIPS assembly code, translate all the instructions to their corresponding machine code in hexadecimal format. This code is stored in the memory from address 0x1fff0000. Loop: sw $t1, 4($s0)        addi $t1, $t1, -1    sll $t1, $t1, 2        bne $t1, $s5, Exit    addi $s0, $s0, 4          j Loop Exit: … 2.     Find the MIPS...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT