Answer
Create a new Freedom Studio project using the same steps as in Exercise 1 in this chapter. Locate the hello.c
file in the src
folder in the Project window.
- Right-click on the file and rename it to
hello.s
. - Create your assembly language source code within the
hello.s
file. TheEx__3_riscv_expr.s
file contains the following example solution to this exercise:.section .text .global main main: # Reserve stack space and save the return address addi sp, sp, -16 sd ra, 0(sp) # Print the leading output string la a0, msg1 jal ra, puts # Compute [(129 – 66) * (445 + 136)] / 3 addi a0, zero, 129 addi a0, a0, -66 addi a1, zero, 445 add a1, a1, 136 mul a0, a1, a0 addi a1, zero, 3 divu a0, a0, a1 # Print the upper byte of the result sw a0, 8(sp) srl a0, a0, 8 jal ra, print_byte # Print the lower byte of the result lw a0, 8(sp) jal...