Question

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) > 0) i++;

(P.S. I am relatively new to this material so please use beginner instructions only)

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 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...
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.
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)); }
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...
IV.Translate the following C code fragment to ARM assembly instructions. Assume t, x, y, and z...
IV.Translate the following C code fragment to ARM assembly instructions. Assume t, x, y, and z are stored in registers r0, r1, r2, and r3. unsigned int x, y, z, t; do { x = x + 1; z = t + (z << 1); y = y - x; } while (y != x); V. What does the following sequence of instructions do? Why? RSB r2, r3, r3, LSL #4 RSB r2, r2, r2, LSL #3 VI. Write a...
(MIPS Assembly Language): Assume the following piece of MIPS code: label1: .text 0x4000fc lui $t0, 1022...
(MIPS Assembly Language): Assume the following piece of MIPS code: label1: .text 0x4000fc lui $t0, 1022 ori $t0, $t0, 2048 srl $t1, $t0, 18 sw $t0, 101($t1) slti $t2, $t1, 5 beq $t2, $0, label3 label2:... ... label3:... a) The code modifies a word in memory at the following address (circle one): (i) 1022 (ii) 101 (iii) 5 (iv) 10220000 (v) Other (provide your own answer): _________________ b) The following value is stored in memory (circle one): (i) 0x17 (ii)...
We assume the following $s0 = a $s1 = b $s2 = c $s3 = i...
We assume the following $s0 = a $s1 = b $s2 = c $s3 = i $s4 = address of ar[0] Write MIPS assembly code for the following C code. for (i = 10; i < 30; i ++) { if ((ar[i] > b) || (ar[i] <= c)) ar[i] = 0; else ar[i] = a; }
Can you translate this C code into MIPS assembly with comment? #include <stdio.h> #include <math.h> #include...
Can you translate this C code into MIPS assembly with comment? #include <stdio.h> #include <math.h> #include <stdlib.h> double fact (double); void main () { int angle_in_D; double term, angle_in_R; float sine = 0; unsigned int i = 1; double sign = 1; int n = 1000; printf ("Please enter an angle (Unit: Degree): "); scanf ("%d", &angle_in_D); angle_in_R = angle_in_D * M_PI / 180.0; do { term = pow(-1,(i-1)) * pow (angle_in_R, (2*i - 1)) / fact (2*i - 1);...