Riscv Program 1
Short Description
asdasfsafsafasf...
Description
Assembly programming using RISCV-ISA simulator tool chain 1. Testing esting the RISCV RISCV-T -Tool ool chain chain
All the lab machines have been installed with the RISC-V tools. To check if the installation is correct, please run the followin code to check the spike RISCV ISA simulator. !" mkdi mkdirr risc riscvv-te test stss #" cd ris riscv cv-t -tes ests ts $" echo -e %&include 'stdio.h()n int main*void" + printf*ello world))n"/ return 0/ 1% ( hello.c 2" riscv32-unknown-elf-cc -o hello hello.c 4" spike pk hello Alternatel5 5ou ma5 install the riscv-tool chain on 5our laptops b5 followin the steps at the link https677ithub.com7riscv7riscv-tools . 2. Getting Getting starte started d ith RISC RISC-V -V assemb assembly ly progra programs ms
a. Create a file called link.ld in the current workin director5 with the followin contents. 89T:9T;ARC* riscv " S 0?#00/ .te?t 6 + @*.te?t" 1 .data AIB=*0?!000" 6 + @*.data" 1 .bss 6 + @*.bss" 1 ;end > ./ 1
b. All 5our RISC-V asm prorams that 5ou code in this tutorial will have the followin code at the beinnin in the 5our;file.s .globl _start; _start:
& :ut 5our own code here
_exit:
c. To compile please use ! riscv$#-unknown-elf-cc -nostdlib -nostartfiles -march>rv$#i -T.7link.ld 5our;file.s d. To e?ecute please use6 spike pk a.out
". #rogramming $uestions
8nce the hello world proram is workin, the oal of this tutorial is to write the below prorams usin RISCV ISA in assembl5 lanuae. a" Compute the sum of nD natural numbers assumin reister ?4 has the value n. et the result of the sum be in reister ?3. Test 5our assembl5 proram for different values of n *i" ! *ii" !0#2 *iii" #02E and *iv" 20F3 . Rename these prorams as sum;!.s, sum;!0#2.s, sum;#02E.s, and sum;20F3.s respectivel5 before submission. b" The Gibonacci numbers are the numbers in the followin inteer seHuence, called the Gibonacci seHuence, and characteried b5 the fact that ever5 number after the first two is the sum of the two precedin ones6 !,!,#,$,4,E,!$,#!,$2,44,EF J Assume an inteer nD is in reister ?4 and compute the last inteer in a seHuence of n Gibonacci numbers. Return the last inteer in reister ?3. Test 5our assembl5 proram for different values of n *i" ! *ii" # *iii" !0 *iv" !4 and *v" #0 Rename these prorams as fib;!.s,fib;#.s, fib;!0.s, fib;!4.s and fib;#0.s respectivel5 before submission. c" Compute the reatest common divisor *cd" of two inteers, assumin the two inteers are in reisters ?4 and ?3. :ut the result of the computation in ?K. Test 5our assembl5 proram for different values of ?4 and ?3 for the followin6 *i" 0,4 *ii" 4,0 *iii" $, 4 *iv" #43,#02E *v" 20F4, !4 Rename these prorams as cd;0;4.s, cd;4;0.s, cd;$;4.s, cd;#43;#02E.s and cd;20F4;!4.s respectivel5 before submission.
2. %oodle submission Tar ip the folder with all the appropriatel5 named assembl5 prorams and submit the ip file with 5our roll number as the ip file name.
Challenge $uestion Currentl5 the proram after e?ecutin prints the contents of all the i. reisters and the statement An illeal instruction was e?ecutedD. 8ne eas5 wa5 of overcomin this statement is b5 loopin back to the last instruction, b5 addin e?it6 Lal e?it to the end of the assembl5 proram.
8ther than loopin back to the last instruction an5 other interestin wa5s of overcomin the above illeal instruction messae are welcome. owever, the proram does e?ecute and chane the reister values despite this messae and 5ou can check the contents of the reisters for 5our proram correctness.
View more...
Comments