When the following instruction executes (i.e., after it has been read into memory), the instruction copies the address of the constant a, without reading its value from the memory, in a register.
For the purposes of this question, a register is not considered a memory location.
ld $a, r0
The following instruction is legal, and when it executes it reads a value from memory and places it in a register.
Assume that the registers have been preloaded with appropriate values.
For the purposes of this question, a register is not considered a memory location.
ld (r0), r1
The following instruction is legal, and when it executes it copies a value from one memory location to another.
Assume that the registers have been preloaded with appropriate values.
For the purposes of this question, a register is not considered a memory location.
st r0, (r1)
If r1 = r2 = r1?
add r1, $21add r1, r2add r2, r1add $21, r1r[1] ← r[1] + r[2]Select all possible options that apply.
Assume r1 = r1?
shl $2, r1
ld $2, r2
mul r2, r1
mul $2, r1
ld $1, r2
shr r2, r1
shl $1, r1
shr $2, r1
[ ] (g)
[ ] (h)
shr $1, r1
ld $1, r2
shl r2, r1
Select all possible options that apply.
Assume r1 = r1?
ld $8, r2
div r2, r1
div $8, r1
shl $8, r1
ld $8, r2
shr r2, r1
shr $8, r1
ld $3, r2
shl r2, r1
shl $3, r1
shr $3, r1
Select all possible options that apply.
.question { margin-top: 1em; } div.question:not(:last-child) { padding-bottom: 1em; border-bottom: 1px dotted grey; }
Given the following description (in RTL or human-readable text), write out the corresponding assembly and machine language translation.
Make sure your answer follows these rules:
0 in the assembly
ld 0(r3), r4 and not ld (r3), r4, although both are valid in the simulator.F instead.
ld $1, r1 would have the machine language translation 01FF00000001.inc r70x63F7deca r70x66F7Which of the following assembly-language instructions would be a way to compute the following C statement (where b is a static array of ints)?
b[3] = 18;
Assume that registers have already been initialized with the following values:
r0 = 18
r1 = base address of b
r2 = 3
r3 = 12
[ ] (a)
ld r0, 12(r1)
add r3, r1
ld r0, (r1)
st r0, (r2, r1, 4)
ld r0, (r1, r2, 4)
st r0, 12(r1)
st r0, (r1, r2, 4)
ld r0, (r1)
add r3, r1
st r0, (r1)
st r0, (r1)
Select all possible options that apply.
Consider the following assembly code:
.pos 0x100
ld $1, r0
ld $a, r1
ld (r1, r0, 4), r2
inca r0
st r2, (r1, r0, 4)
.pos 0x1000
a: .long 13
.long 19
.long 18
.long 10
.long 9
What are the values of the array a after this code executes?
[13, 19, 18, 10, 9]
Consider the following assembly code:
.pos 0x100
ld $a, r0
ld $b, r1
ld (r0), r0
ld (r1, r0, 4), r2
ld (r1, r2, 4), r3
ld (r1, r3, 4), r4
st r2, (r1, r4, 4)
.pos 0x1000
a: .long 0
b: .long 2
.long 3
.long 1
.long 0
What are the values stored in array b after this code executes?
[2, 3, 1, 2]
Consider the following C global variable declaration.
int array[20];
int var;
Translate the following C statement into assembly language.
Use labels to refer to the memory address of each variable. Assume that these labels have already been defined; i.e., do not include their definition in your answer. Also, do not include any assembly directives such as .pos or .long.
Translate this C code
var = var + 1
Into SM213 Assembly code
ld $var, r0
ld (r0), r1
inc r1
st r1, (r0)