Question

In MIPS assembly, write an assembly language version of the following C code segment: int A[100],...

In MIPS assembly, write an assembly language version of the following C code segment:

int A[100], B[100];

for (i=1; i < 100; i++) {

A[i] = A[i-1] + B[i];

}

Homework Answers

Answer #1

Answer:---------
An Assembly language version of the following C code segment:

Given, C code segment:

int A[100], B[100];

for (i=1; i < 100; i++) {

A[i] = A[i-1] + B[i];

}

Corresponding Assembly Code:-----
li $t0, 1 # Starting index of i
li $t5, 100 # Loop bound
loop:
lw $t1, 0($a1)   # Load A[i-1]
lw $t2, 4($a2) # Load B[i]
add $t3, $t1, $t2 # A[i-1] + B[i]
sw $t3, 4($a1) # A[i] = A[i-1] + B[i]
addi $a1, 4 # Go to i+1
addi $a2, 4 # Go to i+1
addi $t0, 1 # Increment index variable
bne $t0, $t5, loop # Compare with Loop Bound
halt:
nop

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
a. Write MIPS assembly code for the following machine code. Assume that the segment is placed...
a. Write MIPS assembly code for the following machine code. Assume that the segment is placed starting at location 8000. Create labels for branch and jump instructions and indicate the 0001 0001 0010 1000 0000 0000 0000 0011 1000 1110 0001 0001 0000 0000 0000 1000 0010 0010 0010 1000 0000 0000 0000 0110 0000 1000 0000 0000 0000 0001 0000 0010 b. Translate the following C function into MIPS assembly code. int f1(int ar1[], int ar2[], int n) {...
2.     Explain each line of the following MIPS assembly language code segment. Write the corresponding C...
2.     Explain each line of the following MIPS assembly language code segment. Write the corresponding C language code and indicate the content of each register with the corresponding variable in C-code. muli $t2, $s1, 4    add $t2, $t4, $t2    lw $t15, 0($t2)    lw $t16, 4($t2)    sw $t16, 0($t2)    sw $t15, 4($t2)
(MIPS Assembly Language): Write the following sequence of code using *native* MIPS instructions: x = x...
(MIPS Assembly Language): Write the following sequence of code using *native* MIPS instructions: x = x - y[0] + y[1]; In memory x, y are stored beginning at 0x010000cc. Use registers $s1 for x,  and $s2 for the base address of y. Make sure your code includes all necessary declarations such that it could run in SPIM.
Question: Write down the corresponding MIPS machine language of the following assembly language code. lw $S0,...
Question: Write down the corresponding MIPS machine language of the following assembly language code. lw $S0, 64($S1) add $t0,$S0,$S1 sub $t1,$S3,$S4 sw $t1,100($S1) addi $S4,$S6,100
Write the following code segment in MARIE's assembly language: if x <= y then Y =...
Write the following code segment in MARIE's assembly language: if x <= y then Y = Y+1; else if x! =x then Y= Y -1; else z=z+1
This is to be done in MIPS assembly language. Define an int array of size 12....
This is to be done in MIPS assembly language. Define an int array of size 12. Initialize this array with number from 12 to 1. Display this array.
Translate the following C function into MIPS assembly code. Note that function f1 is defined somewhere...
Translate the following C function into MIPS assembly code. Note that function f1 is defined somewhere else. int f2(int x, int y) { int i, z = 0; for (i = x; i <= y; i++) z = z + f1(i, 5); return z; }
Consider the function with header: int foo(int s, int n, int a, int b). Write MIPS...
Consider the function with header: int foo(int s, int n, int a, int b). Write MIPS assembly code for the following statement located inside the above function: return(s+n);
Write and test code in MIPS assembly language program to implement algorithms "The Non-Restoring Algorithm "of...
Write and test code in MIPS assembly language program to implement algorithms "The Non-Restoring Algorithm "of an 8-bit integer the user shoud insert the number then by the algo well find the square root
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