Question: USE RISC-V Language .globl main .text main: # read two positive integers from the console and # save them in s1 and s2 # compute

USE RISC-V Language
.globl main .text main: # read two positive integers from the console and # save them in s1 and s2 # compute the GCD of the two numbers with Euclidean algorithm # while a != b: # if a > b: # a = a - b # else: # b = b - a # print the GCD # GCD examples: # gcd(11, 121) = 11 # gcd(24, 60) = 12 # gcd(192, 270) = 6 # gcd(14, 97) = 1 # use system call 5 to read integers addi a7, x0, 5 ecall addi s1, a0, 0 # a in s1 # using pseudoinstructions li a7, 5 ecall mv s2, a0 # b in s2 # TODO # Add you code here # compute GCD(a, b) and print it # sys call to exit exit: addi a7, x0, 10 ecall
In this lab, we write a program in RISC-V assembly language that finds the GCD of two positive integers. The program reads two positive integers, and then computes and prints their GCD. The algorithm we use is Euclidean algorithm. Although it is common to use division in the algorithm, we will use subtraction only, as originally described by Euclid. The pseudocode is provided below. # Given two positive integers a, b, repeatedly subtract the smaller one from the larger one # until the two integers are the same. WHILE (a != b) IF (a > b) a = a - b ELSE b = b - a Skeleton code in lab1.s already has the instructions to read two integer and save them in si and s2. Implement the following steps with RISC-V instructions to complete the program. Compute the GCD of the two numbers with Euclidean algorithm by subtraction. Do not mix while and if-else code. If-else should be enclosed by, not mixed with, the instructions controlling the loop. Print the GCD in decimal with a system call. There is no need to print a newline character after it. The list of system calls is in RARS's help file. Select menu "Help/Help" and then select "Syscalls" tab. Scroll up to the beginning of the page if necessary. There is an example before the table. The skeleton code has the instructions for reading integers. Check wether you can write the instructions from the information in the system call table. The skeleton code includes some GCD examples. Please test your code with more positive numbers
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
