Create divide function in MIPS ASSEMBLY no psuedo code!!!! $a0 – first integer $
ID: 3848160 • Letter: C
Question
Create divide function in MIPS ASSEMBLY no psuedo code!!!!
$a0 – first integer
$a1 – second integer
$v0 – first integer / second integer
$v1 – first integer % second integer
This function is to calculate and return the result of dividing the arguments. Your solution must implement the division algorithm posted below. You must handle both positive and negative numbers plus zero. If the second parameter is zero, set both $v0 and $v1 to zero. Using any version of the div instruction is NOT ACCEPTABLE. NO DIV!
Start 1. Subtract the Divisor register from the Remainder register and place the result in the Remainder register Remainder 20 Test Remainder RemainderExplanation / Answer
global main
MD printf ; c function: prints formatted output
MD strtol ; c function: converts strings to longs
section .text
main:
push rbp ; created stack frame
; rdi contains argc
; if but three, exit
cmp rdi, 3
jl incorrect_usage
; push initial argument as variety
push rsi
mov rdi, [rsi+8]
mov rsi, 0
mov rdx, ten ; base ten
decision strtol
pop rsi
push rax
; push second argument as variety
push rsi
mov rdi, [rsi+16]
mov rsi, 0
mov rdx, ten ; base ten
decision strtol
pop rsi
push rax
; pop arguments and decision get_gcd
pop rdi
pop rsi
decision get_gcd
; print worth
mov rdi, print_number
mov rsi, rax
decision printf
; exit
mov rax, zero ; 0--exit success
pop rbp
ret
incorrect_usage:
mov rdi, bad_use_string
; rsi already contains argv
mov rsi, [rsi]
decision printf
mov rax, zero ; 0--exit success
pop rbp
ret
bad_use_string:
dB "Usage: a method [number1] [number2]",10,0
print_number:
db "%d",10,0
get_gcd:
push rbp ; created stack frame
mov rax, 0
jmp loop
loop:
; keep adding the primary argument
; to itself till a multiple
; is found. then, return
add rax, rdi
push rax
mov rdx, 0
div rsi
cmp rdx, 0
pop rax
je gcd_found
jmp loop
gcd_found:
pop rbp
ret
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.