An RV32I sensor-processing routine reads selected words from the memory shown below. All addresses and signed contents are decimal.
Initially, x10 = 2048, x11 = 4, x12 = 0, and x13 = 5. Register x0 always contains zero. The routine executes:
loop: lw x14, 0(x10) addi x10, x10, 8 beq x14, x13, skip add x12, x12, x14 skip: addi x11, x11, -1 bne x11, x0, loop
Execution stops immediately after the final bne is not taken. All memory accesses are valid and aligned, and no arithmetic overflow occurs. What signed value does x12 contain at that point? Answer as a decimal integer with no decimal places.
Unlock full course notes by signing up
Encoding a signed immediate instruction
Encode addi x18, x9, -24 for an RV32I controller. The instruction's fields appear from most significant bit to least significant bit in this order:
For addi, funct3 is 000 and the opcode is 0010011. Use 12-bit two's complement for the immediate.
Report the immediate field interpreted as an unsigned decimal integer, with no decimal places. Also report the complete 32-bit machine word as exactly eight hexadecimal digits, without a prefix or spaces.
Testing a branch and locating its target
An RV32I simulator is about to execute beq x5, x6, target at byte address 400. Both source registers contain 12, and target labels the instruction at byte address 416. All addresses are decimal, instructions are four bytes long, and execution raises no exception. Select every true statement.
Fetching instruction words from memory bytes
A teaching processor uses byte-addressed memory and fixed-width, 16-bit machine instructions. Its endianness is the rule assigning significance to the bytes within each instruction word. Little-endian instruction fetch treats the lower-addressed byte as the least significant byte; big-endian instruction fetch treats it as the most significant byte.
A debugger reports the following memory contents. Every address and byte value shown is decimal.
Complete the table with each fetched 16-bit word, interpreted as an unsigned decimal integer. Use exact integers. Compare the two fetch configurations using the same stored bytes without rearranging memory; you do not need to determine whether the resulting words encode valid operations.
Preserving a return address across a nested call
A teaching processor has 32-bit registers, byte-addressed memory, and four-byte instructions. Its link register, LR, holds a return address. Its stack pointer, SP, holds the address of the current top of a downward-growing stack.
For this processor, use these exact instruction rules:
CALL target writes the address of the instruction immediately following the call into LR, then transfers execution to target.