RISC-V Assembly Language

Project #1

Convert the program below to print hexadecimal.

Project #2

Convert the program below to print 32-bit floats. For example:

  1. 12.45 + 37.9
  2. 968.459 - 0.318
  3. Others. Your choice.

Project #3

Write a function to convert single-precision float numbers (IEEE 574 standard) to a string in scientific notation. Print it to the console.

Program Code

# =============================================================== # test printing an integer and integer arithmetic # # Note: add multiply and divide examples to this code. # # 32-bit assembly language # =============================================================== .data newline: .asciz "\n" x: .word 10 y: .word 2 .text .global _start _start: lw s0, x # load x into s0 lw s1, y # load y into s1 # add: a1 = so + s1 add a1, s0, s1 # add s0 + s1 # print a1, s0, s1 li a7, 1 # syscall number, print integer mv a0, a1 # copy a1 to a0 ecall # syscall li a7, 4 # syscall number, print string la a0, newline # address of newline char/string ecall # syscall li a7, 1 # syscall number, print integer mv a0, s0 # copy s0 to a0 ecall # syscall li a7, 4 # syscall number, print string la a0, newline # address of newline char/string ecall # syscall li a7, 1 # syscall number, print integer mv a0, s1 # copy s1 to a0 ecall # syscall li a7, 4 # syscall number, print string la a0, newline # address of newline char/string ecall # syscall # subtract: a1 = s0 - s1 sub a1, s0, s1 # subtract s0 - s1 li a7, 1 # syscall number, print integer mv a0, a1 # copy a1 to a0 ecall # syscall li a7, 4 # syscall number, print string la a0, newline # address of newline char/string ecall # syscall # subtract: a2 = s1 - s0 sub a1, s1, s0 # subtract s1 - s0 li a7, 1 # syscall number, print integer mv a0, a1 # copy a1 to a0 ecall # syscall li a7, 4 # syscall number, print string la a0, newline # address of newline char/string ecall # syscall # exit program li a7, 93 # syscall number, exit program li a0, 0 # return code ecall # syscall