We have the assembler which takes our RISC-V code and turns it into the executable RISC-V program (binary format)

We have assembler directives, which are directives for the assembler to follow when compiling.

  • .text Read only section containing the program
  • .data Read-write section with program variables
  • .byte [...] Place one (or more) byte(s) at the current location
  • .asciiz "..." Places Places an ASCII string followed by the null terminator
  • .word Places a word (signed/unsigned) at the current location
  • .uword
  • equ name, value Assign a value to a name

We can therefore load an array in memory:

.equ n, 8
.data
my_array: 
	.byte 0x3F, 0xA7, 0x5C, 0x91
	.byte 0xDE, 0x02, 0x6B, 0xB8
my_res:
	.word 0
.text
li t0, n        # load the size of the array into t0
la t1, my_array # load the address of the byte array into t1
la t2, my_res   # load the address of the word into t2

li load immediate la load the address of immediate (or label)

06.7 CPU Performance