Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is a good way of tackelling this problem, I would like detailed process of

ID: 3879635 • Letter: W

Question

What is a good way of tackelling this problem, I would like detailed process of how the answer is derived, this would help allot , thank you!

Consider a program that declares global integer variables x, y[10]. These variables are allocated starting at a base address of decimal 1000. All these variables have been initialized to zero. The base address 1000 has been placed in $gp. The program executes the following assembly instructions:
lw $s1, 0($gp)
addi $s1, $s1, 25
sw $s1, 0($gp)
lw $s2, 12($gp)
add $s2, $s2, $s1
sw $s2, 8($gp)
sw $s2, 12($gp)

A) What are the memory addresses of variables x, y[0], and y[1]?

B) What are the values of variables x, y[0], y[1], and y[2] at the end of the program?

Explanation / Answer

Explanation of Code:

lw $s1, 0($gp) #load value in base address to $s1
addi $s1, $s1, 25 #increment it by 25
sw $s1, 0($gp) #store it back to same location
lw $s2, 12($gp) #load value in 1000 + 12 y[2] in $s2
add $s2, $s2, $s1 #add it by value in $s1 because it is initialised to 0. $s2 = 25
sw $s2, 8($gp) #store it in y[1] 1000+8
sw $s2, 12($gp) #store it in y[2] 1000+12

A. Base address is 1000 and variable x, y[10] array are stored from there. Assuming variables are of type int, each variable occupies a memory of 4Bytes

x has address of 1000

y[0] has address of 1000 + 4 = 1004

y[1] has address of 1008

y[2] has address of 100C and so on.

B.

x = 25

y[0] = 0

y[1] = 25

y[2] = 25

Hope I've given sufficient explanation of how it works. Reach out in the comments section if need further clarification.

Do Upvote! :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote