Add TP01 answers
This commit is contained in:
parent
acf775493d
commit
f08304931b
8
TP01/riscv/README.md
Normal file
8
TP01/riscv/README.md
Normal 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
BIN
TP01/riscv/asshand.o
Normal file
Binary file not shown.
BIN
TP01/riscv/libprint.o
Normal file
BIN
TP01/riscv/libprint.o
Normal file
Binary file not shown.
@ -4,7 +4,15 @@ main:
|
|||||||
addi sp,sp,-16
|
addi sp,sp,-16
|
||||||
sd ra,8(sp)
|
sd ra,8(sp)
|
||||||
## TODO Your assembly code there
|
## 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 TODO End of user assembly code
|
||||||
|
end:
|
||||||
ld ra,8(sp)
|
ld ra,8(sp)
|
||||||
addi sp,sp,16
|
addi sp,sp,16
|
||||||
ret
|
ret
|
||||||
@ -15,4 +23,4 @@ mydata:
|
|||||||
.dword 7
|
.dword 7
|
||||||
.dword 42
|
.dword 42
|
||||||
min:
|
min:
|
||||||
.dword 0
|
.dword 8
|
||||||
|
19
TP01/riscv/sum.s
Normal file
19
TP01/riscv/sum.s
Normal 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
|
Loading…
Reference in New Issue
Block a user