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:
Initially, SP is 12000. Execution begins at address 4096. All displayed addresses and constants are decimal. Assume no interrupts or other changes to the machine state.
4096: CALL 8192 4100: NOP 8192: PUSH LR 8196: CALL 12288 8200: POP LR 8204: RET 12288: SUB SP, SP, 12 12292: ADD SP, SP, 12 12296: RET
For the original program, determine the minimum value reached by SP, the return-address value saved by PUSH LR, and the program-counter value immediately after the RET at address 8204. Then consider a separate run from the same initial state in which the instruction at address 8200 is replaced by NOP. Determine the program-counter value immediately after the first execution of the RET at address 8204 in that modified run.
Give all four answers as exact decimal integers in bytes: stack and program-counter answers are byte addresses, and the saved value is a return byte address.
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.
Tracing a conditional accumulation loop
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:
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.