RISC-V Assembly
Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
RISC-V Assembly
You may find the RISC-V ISA handout useful for the following questions. Please assume that all registers are initialized to 0, and the instructions in the section below are executed one after another. addi a1, a2, 9
lui a2, 3
addi a3, x0, 3
0CDEF1AF) is written into the register a2? 0x
0CDEF1AF) is written into the register a3? 0x
sub a3, a3, a1
slt a4, a3, zero
sltu a5, a3, zero
0CDEF1AF) is written into register a3? Note that all values are stored as 2's complement numbers. 0x
a4?
a5?
addi a4, zero, 1
beq a5, zero, L1
slli a4, a4, 2
L1:
slli a4, a4, 5
0CDEF1AF) will be inside the register a4 after entire code snippet above is executed? 0x
lui a0, 2
lw a1, 8(a0)
addi a2, a1, 4
sw a2, 0(a0)
unimp
. = 0x2000
.word 0x12345678
.word 0xDEADBEEF
.word 0x50505050
Assume that unimp is a special instruction that tells the processor to stop running.
The code piece below the . = 0x2000 line just means that
- the value
0x12345678resides in the memory location0x2000 - the value
0xDEADBEEFresides in the memory location0x2004 - the value
0x50505050resides in the memory location0x2008
0CDEF1AF) will be written to register a1 after the execution of the code snippet above? 0x
0CDEF1AF) will be written to after the execution of the code snippet above? 0x
0CDEF1AF) will be written to the memory location you found above? 0x
Assembly 2
Consider the following code segment which is independent from the code in the previous section. lui a0, 0x2
addi a7, x0, 0
lw a1, 0(a0)
L1 :
andi a2, a1, 1
beq a2, zero, L2
addi a7, a7, 1
L2 :
srli a1, a1, 1
bne a1, x0, L1
unimp
. = 0x2000
.word 0x12345678
The program seems to be complicated, but we will try to break it down and understand it piece-by-piece.
Once again assume that unimp is a special instruction that tells the processor to stop execution when it is reached.
Consider the following code snippet from the program above:
L1 :
andi a2, a1, 1
beq a2, zero, L2
addi a7, a7, 1
L2 :
srli a1, a1, 1
a1 has a value of 0x84263A01 and the register a7 has a value of 0x00000003 before the execution of this code snippet. What will be written to the register a1 after execution of these four lines of code (answer in 32-bit hexadecimal format like 0x0CDEF1AF)? 0x
a1 with a value of 0x84263A01 and register a7 with a value of 0x00000003 before the execution of the code snippet, what will be written to register a7 after execution of these four lines of code (answer in 32-bit hexadecimal format like 0x0CDEF1AF)? 0x
a1 has an initial value of 0x84263A00 and while register a7 once again has a value of 0x00000003 before execution of the code snippet. What will be written to the register a1 after execution of these four lines of code (answer in 32-bit hexadecimal format like 0x0CDEF1AF)? 0x
a7 after executing this code snippet if register a1 begins with a value of 0x84263A00 and the register a7 begins with a value of 0x00000003 (answer in 32-bit hexadecimal format like 0x0CDEF1AF)? 0x
Now let's look back at the main code
lui a0, 0x2
addi a7, x0, 0
lw a1, 0(a0)
// start of the code piece
L1 :
andi a2, a1, 1
beq a2, zero, L2
addi a7, a7, 1
L2 :
srli a1, a1, 1
// end of the code piece
bne a1, x0, L1
unimp
. = 0x2000
.word 0x12345678
Execution begins with the first instruction lui a0, 0x2 which initializes register a0 to 0x00002000. The next instruction sets register a7 to 0.
lw a1, 0(a0) instruction write into register a1 (answer in 32-bit hexadecimal format like 0x0CDEF1AF)? 0x
Now assume that the code runs until it reaches the bne a1, x0, L1 instruction for the first time.
a1 when the bne a1, x0, L1 instruction is reached for the first time (answer in 32-bit hexadecimal format like 0x0CDEF1AF)? 0x
a7 when the bne a1, x0, L1 instruction is reached for the first time (answer in 32-bit hexadecimal format like 0x0CDEF1AF)? 0x
Now consider the execution of bne a1, x0, L1 for the first time.
Now consider running the code to completion when it reaches the unimp instruction.
andi a2, a1, 1 instruction through the bne a1, x0, L1 instruction) be executed? (answer in positive integer format)
a7 when the execution reaches the unimp instruction? (answer in 32-bit hexadecimal format like 0x0CDEF1AF) 0x