Name: Date:
HW5 solution
-
(22 points) As discussed on pages 132–134 (Section 2.12 "Assembler"), pseudoinstructions are not part of the RISC-V instruction set, but often appear in RISC-V programs. For each pseudoinstruction in the following table, produce a minimal sequence of core RISC-V instructions to accomplish the same thing.
You may need to use
x31for some of the sequences, which the CSSE232-assembler treats as an "assembler temporary" register. In the following tables,BIGrefers to a specific number that requires 32 bits to represent andSMALLto a number that can fit in 11 bits. You may need to refer to portions of the immediates using indices (e.g. BIG[11:0]). Unless otherwise specified assume all integers are signed.Note: pseudoinstructions can have the same name as core instructions but use different operands than the core instructions.
Pseudoinstruction What it accomplishes Actual instructions move x5, x6x5 = x6add x5, x6, x0clear x5x5 = 0add x5, x0, x0li x5, SMALLx5 = SMALLaddi x5, x0, SMALLli x6, BIGx6 =big
assume
BIG[11] = 0lui x6 BIG[31:12]addi x6, x6, BIG[11:0]li x6, BIGx6 =big
assume
BIG[11] = 1lui x6 BIG[31:12]+1addi x6, x6, BIG[11:0]beq x5, SMALL, Lif (x5 == SMALL) goto L
careful...addi x31, x0, SMALLbeq x31, x5, Lbeq x6, BIG, Lif (x6 == big) goto L
assume
BIG[11] = 0lui x31, BIG[31:12]addi x31 x31 BIG[11:0]beq x31 x6 L
| Pseudoinstruction | What it accomplishes | Actual instructions |
|---|---|---|
ble x9, x11, L |
if (x9 <= x11) goto L |
bge x11, x9, L |
bgt x9, x11, L |
if (x9 > x11) goto L |
blt x11, x9, L |
bge x9, x11, L |
if (x9 >= x11) goto L solve this without using bge/blt |
slt x31, x9, x11beq x31, x0, L |
addi x6, x13, BIG |
x6 = x13 + big careful... |
lui x31, BIG[31:12] + BIG[11] addi x31, x31, BIG[11:0]add x6, x13, x31 |
lw x11, BIG(x13) |
x11 = Mem[x13 + big] |
lui x31, BIG[31:12] + BIG[11] addi x31, x31, BIG[11:0]add x31, x31, x13lw x11, 0(x31) |