===============
EECS2021 Assignment 1: Due Date July 10th, 11:30 PM EST
Copyright By PowCoder代写 加微信 powcoder
Submission: Online as explained in the Administration slides via:
https://webapp.eecs.yorku.ca/submit/ppy
===============
Assumptions:
You are expected to write RISC-V assembly for 64-bit hardware.
All numbers discussed below are in base ten unless otherwise mentioned.
Your codes for Part A and Part B are fully functional in Ripes
https://github.com/mortbopet/Ripes, as discussed in the class.
Your codes are well-documented via inline comments.
You will submit a.s, b.s, and c.s files for Part A, Part B, and Part C of this assignment.
===============
Part-A (35%) Write a program in RISC-V assembly to calculate a given Fibonacci number (https://en.wikipedia.org/wiki/Fibonacci_number). Example: fib(7) will be 13. Use x10=7 as the input and use x10 to hold the calculated results. Refer to slides for the Factorial example discussed in the class.
int fib(int n)
if (n==0) return 0;
else if (n == 1) return 1;
else return fib(n−1) + fib(n−2);
===============
Part-B (50%) Write a program in RISC-V assembly to convert an ASCII string containing a positive or negative integer decimal string to an integer. Your program should expect register x10 to hold the address of a null-terminated string containing an optional “+” or “−” followed by some combination of the digits 0 through 9. Your program should compute the integer value equivalent to this string of digits, then place the number in register x10. If a non-digit character appears anywhere in the string, your program should stop with the value −1 in register x10. For example, if register x10 points to a sequence of three bytes 50, 52, 0, which represent the null-terminated string “24\0”, then once the program stops, register x10 should contain the integer value of 24 (or 0x18 in hex).
The RISC-V mul instruction takes two registers as input. There is no “muli” instruction. Thus, just store the constant 10 in a register.
For testing purposes: you can add this at the bottom of your assembly file:
mystr: .byte 50, 52, 0
# you can use string as well …
===============
Part-C (15%)Write an assembly RISC-V program that prints the Fibonacci numbers from one to ten in the standard output console.
Assume you are in RISC-V 64bit machine and using Linux operating system and GNU compiler collection tools and assembler. Assume the system call for “Write” is 64. Assume you are using ABI (https://en.wikipedia.org/wiki/Application_binary_interface).
On PRISM execute /cse/fac/bin/navid-risc-vm to get a RISC-V Virtual Machine.
Below code will print HelloWorld!:
.section .rodata
hello_str: .string “Hello World!\n”
.equ hello_str_len, 13
.section .text
.globl _start
_start: # setup the parameters to Write HelloWorld to console.
addi a0, x0, 1 # 1 mean standard output
la a1, hello_str # load address of hello_str
addi a2, x0, hello_str_len # length of our hello_str string
addi a7, x0, 64 # linux write system call
ecall # Call linux to output the string
# setup the parameters to exit the program
addi a0, x0, 0 # Use 0 to indicate zero error happened
addi a7, x0, 93 # System call 93 terminates the program in Linux
ecall # Call linux to terminate the program
===============
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com