From f08304931b43419767d9f58c20868540dfdb0658 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Mon, 23 Sep 2024 13:39:04 +0200 Subject: [PATCH] Add TP01 answers --- TP01/riscv/README.md | 8 ++++++++ TP01/riscv/asshand.o | Bin 0 -> 1088 bytes TP01/riscv/libprint.o | Bin 0 -> 2576 bytes TP01/riscv/minmax.s | 10 +++++++++- TP01/riscv/sum.s | 19 +++++++++++++++++++ 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 TP01/riscv/README.md create mode 100644 TP01/riscv/asshand.o create mode 100644 TP01/riscv/libprint.o create mode 100644 TP01/riscv/sum.s diff --git a/TP01/riscv/README.md b/TP01/riscv/README.md new file mode 100644 index 0000000..8f7332f --- /dev/null +++ b/TP01/riscv/README.md @@ -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 diff --git a/TP01/riscv/asshand.o b/TP01/riscv/asshand.o new file mode 100644 index 0000000000000000000000000000000000000000..6cae7b24eb61202174b1ddaff527a85de5091dbf GIT binary patch literal 1088 zcmbtT!AiqG5S=teEqJJiAPC|?Jjv1q@hGXH9_$Br3)?i+Koi35w$xtqGkWymKX~+C z`~>gfOtNd^HeTw4WMop85DJ+wAWAtg&9B-Hetuxg^z>R zulr|!?kxsHBBKd7T{Jy0IXg}Kyc4E=-VQlgLqGS!0X=3(Bn9EKWEf{rjEQKc>3G!1 z+eL-H9&UYy;Nn#$E>PFMrJQkj((@wC!O51z1#bzwK%`aI&(ZWB)5qBWQl4b+(|HT) zY*ec=`Isu+2PTy$^@FiQJmO5nQw40m6$jRr5?HYq#+4FDf2?9zJ#2OR5UKPQ*R3N0 z?QdDQy@`E{FTSZo@{3;0o`&drg3MkFeynkO^F7V8mA&y3edenC4)T$k+jUHRqfOkd vPrm-OOiH2W+I!cUc2BoGe-kmgccR?sLO0}8#IC=Mu{!>nPQ0ve$+Y?3a6MF1 literal 0 HcmV?d00001 diff --git a/TP01/riscv/libprint.o b/TP01/riscv/libprint.o new file mode 100644 index 0000000000000000000000000000000000000000..eaa329c0f78e615a65875c95e7ec44af12aa0593 GIT binary patch literal 2576 zcmb_d&ubG=5S}!qwf>@Qq?HP#7Ofx>+E@fHC04AWJ?KFY5z|ewX#)AN>~7LlP}4{& zhzIfF$&gPFc7G&_y6i|RsBz=GJEH7Q)Tt`nab+a;lb&@ zJ)=XJ1i;A)_{7Y#6)%Es7{h>BJU);P8~xF2*yxLD6eYt(IGUhaoUrTZxMjLQQqRS8 zWFwf(7Bc-tA4+Uy{+b;H;KyGr^TW0cu-lWhI+Jv$E7#j8C*6pjXI!mt$-#Z_a=i=) z-d3Zu9~u=lz!gMVYV0>z2e%M!L;gKh8fAZj@deJWv7bgy`kkDMdw>Dyoa1#;J+eo5 z5kBB#0GHW6LEpl$*FCR;zpjJB!HKOlPcmyq(>WU~+l=a2!=8lDNMAP?CW4uqGbC{= zpU=1h4xH1+GwGaOrN&d5$-`?QN}zH&HwH$*w%p+)#STUKAc*_h?Kud+k9jZ(cX3Yq zJsgu0T;+E$hxp#}7F^}`diY*_!BzfM55J9La)PUT>F*BYGi?nLfQ zaFzd-IYIPvi3zUq<$p!%;ZKY+MR1kh&izg6X%=zxf~)*a=F?id=OehvFM0TTJ^F&H zdSSzC*tw@uflBr^4k7P9pT8$t=q)*uwKEC`u-H*wy-A&hk89;*s?DwOm-j8rzb^I!g@C15RBqcpT&x4HmlyLRUzNpkCE}04+ zMT|86b$&lK8%QkJB7Gfp@HJa9VXgd7&4ph#RQur(CT~%(DzG^8~896ECSR i=SMxQ?j0eB@C)f3B_31jx8hjM`TXZ{zkh22>ipl{r)TB> literal 0 HcmV?d00001 diff --git a/TP01/riscv/minmax.s b/TP01/riscv/minmax.s index effe800..91b2eee 100644 --- a/TP01/riscv/minmax.s +++ b/TP01/riscv/minmax.s @@ -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 diff --git a/TP01/riscv/sum.s b/TP01/riscv/sum.s new file mode 100644 index 0000000..91f9d8f --- /dev/null +++ b/TP01/riscv/sum.s @@ -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