Add TP01 answers

This commit is contained in:
augustin64 2024-09-23 13:39:04 +02:00
parent acf775493d
commit f08304931b
5 changed files with 36 additions and 1 deletions

8
TP01/riscv/README.md Normal file
View File

@ -0,0 +1,8 @@
# Installed using:
sudo pacman -S riscv64-elf-binutils riscv64-elf-newlib riscv64-linux-gnu-gcc
yay -S riscv64-unknown-elf-gcc riscv64-unknown-elf-binutils riscv64-unknown-elf-picolibc
yay -S riscv-pk-git # which has a broken repo path, you need to manually edit PKGBUILD
then, run using:
spike /usr/riscv64-linux-gnu/bin/pk ex1.riscv

BIN
TP01/riscv/asshand.o Normal file

Binary file not shown.

BIN
TP01/riscv/libprint.o Normal file

Binary file not shown.

View File

@ -4,7 +4,15 @@ main:
addi sp,sp,-16
sd ra,8(sp)
## TODO Your assembly code there
addi t0, zero, 17
addi t1, zero, 12
blt t0, t1, inf
sb zero, t1, min
j end
inf:
sb zero, t2, min
## END TODO End of user assembly code
end:
ld ra,8(sp)
addi sp,sp,16
ret
@ -15,4 +23,4 @@ mydata:
.dword 7
.dword 42
min:
.dword 0
.dword 8

19
TP01/riscv/sum.s Normal file
View File

@ -0,0 +1,19 @@
.globl main
main:
addi sp,sp,-16
sd ra,8(sp)
addi t0, zero, 0
addi t1, zero, 0
addi t2, zero, 9
loop:
beq t1, t2, end
addi t1, t1, 1
add t0, t0, t1
j loop
end:
addi a0, t0, 0
call print_int
call newline
ld ra,8(sp)
addi sp,sp,16
ret