CSE 410 22wi Homework 2
Out: Friday, 14 January
Due: Friday, 21 January
Turnin: Gradescope
This is a "paper and pencil" assignment about data and instruction representation. Turn-in is online, preferably
as a pdf file.
- Consider the following assembler program:
.text
addi x10, x10, 21
andi x11, x10, 6
xor x12, x10, x11
lw x13, X(x0)
slli x14, x13, 1
and x14, x14, x13
done:
.data
X: .word 49
- Assemble this program by hand to produce machine instructions. Give the instructions as hexadecimal numbers in your answer.
You may find the RISC-V resources referenced in the course documentation page to be useful.
NOTE: The actual RISC-V lw instruction
differs from the one described in class and implemented by the simulator. For this question, assume that addresses in the .data
section start at 0, and that the effective address generated by a lw is the address (index) of a word in the data section, exactly as it works in our simulator.
- What are the values in registers 13 and 14 after the code runs? (Assume it stops when it reaches label
done.) Give your answers in hex.
- Assuming these bit strings are instructions, express their meaning in assembler:
fd010113
02112623
- Suppose register 5 holds the value 0x13579BDF.
- What is the minimum value that when added to register 5 causes overflow when interpretting the values as signed integers?
- What is the minimum value that when added to register 5 causes overflow when interpretting the values as unsigned integers?
- In this assembler code:
add x10,x11,x12
slti x13, x12, 0
slt x14, x10, x11
bne x13, x14, skip
...
skip:
What is the purpose of the three instructions that follow the add instruction?
(You will have to look up the meanings of the slti and slt instructions.
The resources in the documentation section may help, as might just a search.)
- What is the largest immediate value that can be used in an addi instruction?
- What is the value of 0X5768793F as ASCII characters?
- Write assembler that sets x4 to 0 if x3 is divisible by 8 and to 1 otherwise, without using
any multiple or divide instructions.