Assembly MIPS Name your assembly language source code file hw3-4-s. The greatest
ID: 3674181 • Letter: A
Question
Assembly MIPS
Name your assembly language source code file hw3-4-s. The greatest common divisor (GCD) of two integers a and b is the largest (most positive) integer g that divides both a and 6. We say that a number n divides m if the remainder after dividing m by n is zero. Euclid's algorithm^1 is an elegant way to calculate the GCD of two integers. Here is the algorithm in pseudo code. a and b can be negative integers and one. but not both, of them can be zero. Since GCD(a, b) is the largest (most positive) integer that divides both a and b, it will be a positive integer. It is true that GCD(a, b) = GCD(, |6) so we start by setting x to be the larger (by absolute value) of a and b, and y to the smaller. For this exercise, you are to write a complete MIPS32 assembly language program that displays prompts asking the user to enter values for a and b. The program shall compute and display GCD(a, b). Here is a sample run: make your program work similarly,Explanation / Answer
.text
.globl main
main:
# Prompt for user input
la $a0, prompt # $a0 holds prompt
li $v0, 4 # print string in $a0
syscall
# read in the integers
li $v0, 5 # "read integer" code
syscall
move $a0, $v0 # store input in A
li $v0, 5
syscall
move $a1, $v0 # store B
loop:
beq $a1, $0, done
div $a0, $a1
move $a0, $a1
mfhi $a1
j loop
done:
move $v0, $a0
la $a0, answer
li $v0, 4
syscall
lw $a0, A # load A to be displayed
li $v0, 1 # display A
syscall
li $v0, 10
syscall
.data
A: .word 0 # create blank A/B
B: .word 0
prompt:
.asciiz "Please type 2 integers, A and B; Enter after each: "
answer:
.asciiz " GCD = " # answer =
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.