2. This question concerns RISC-V code generation, to evaluate arithmetic expressions in a simple memory model. In this question, you will write (short) RISC-V assembly programs for four different...

This question concerns RISC-V code generation, to evaluate arithmetic expressions
in a simple memory model.
In this question, you will write (short) RISC-V assembly programs for four different
tasks. Your programs may only use instruction labels for branching, the registers x0,
a0, t1, t2, sp, and fp, and the following RISC-V assembly commands:
Please see the attached PDF file, thanks.



2. This question concerns RISC-V code generation, to evaluate arithmetic expressions in a simple memory model. In this question, you will write (short) RISC-V assembly programs for four different tasks. Your programs may only use instruction labels for branching, the registers x0, a0, t1, t2, sp, and fp, and the following RISC-V assembly commands: lw register1 offset (register2 ) load a word of data at offset from an address stored inregister2 , intoregister1 . sw register1 offset (register2 ) store the value of register1 into memory at offset from an address stored in register2 . add register1 register2 register3 add the values stored in register3 and register2 , and store the result in register1 . mul register1 register2 register3 multiply the values stored in register3 and register2 , and store (the lowest 32 bits of) the result in register1 . addi register1 register2 constant add the signed 16-bit value constant to the value stored in register2 and and store the result in register1 . b address jump to the instruction at address . beq register1 register2 address if the contents of register1 and register2 are equal, jump to the instruction at address . bne register1 register2 address if the contents of register1 and register2 are different, jump to the instruction at address . Each instruction is to be written on a separate line. Use the convention that the stack grows “downwards” (i.e., that the front of the stack is at a lower address than the rest of the stack) and that sp points at an unused word in memory below the front of the stack. (a) Write a RISC-V assembly program that pushes the value 0 onto the front of the stack. [10 marks] (b) Write a RISC-V assembly program to add two numbers at the front of the stack, explicitly popping each of those stored numbers off of the stack in doing so, and separately pushing the result onto the stack. [10 marks] (c) Write a RISC-V assembly program, which reads elements from the front of the stack, popping them off the stack as it goes and adding them to a running total, stopping when it encounters a value of 0 on the stack (without popping that 0 value off the stack). You may assume that there is at least one non-zero value on the stack to be added. The result should be pushed onto the stack after the first 0 value found on the stack. [10 marks] Turn over/ (d) Write a RISC-V assembly program, which reds elements z1, z2, z3, and z4, from the stack (where z1 is at the front, z2 is next from the front, etc.) popping them off the stack as it does so; computes the value (2z1 + 3z2)2 + z3 · z4 (with the usual order of operations); and pushes the result back on the stack. Only use the instructions provided above. You may assume that the final result and all intermediate results can be stored as 32-bit integers without overflow. [20 marks] Coversheet G5035-2021-exam-resit.pdf
Aug 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here