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
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);
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...
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; }
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...
Machine Language - 1. Which of the following assembly code represents the high-level Java code below?...
Machine Language - 1. Which of the following assembly code represents the high-level Java code below? int x; int i = 5; if (i < 0) x = -1; else x = 1; @5 D=M @i M=D @BRANCH M;JLT @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END 0;JMP @5 D=M @i M=D @BRANCH M;JGE @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END 0;JMP @5 D=M @i M=D @BRANCH M;JLT @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END...
III. After execution of the following instructions what value will be in register r0? LDR                ...
III. After execution of the following instructions what value will be in register r0? LDR                 r12, =0xA4000000 LDR                 r0, =0x75 LDR                 r1, =0xD2 LDR                 r2, =0x9C LDR                 r5, =0xC STMDB           r12!, {r0-r2, r5} LDR                 r0, [r12, #8] SUB                 r0, #0x77 IV. Assume that the variables f, g, h, i, and j are assigned to registers r0, r1, r2, r3, and r4, respectively. Assume that the base address of the arrays A and...
(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)...
Consider the C code below which reverses the elements in the array A in place. Both...
Consider the C code below which reverses the elements in the array A in place. Both array indexing and pointer versions are given. Assume that A holds doubleword integers and that size is the number of elements in the array. Translate to RISC-V using as few instructions as possible. For your RISC-V code, assume the base address of A is initially in x10 and that the number of elements in the array (i.e., size) is initially in x11. long long...