Hi, I have been trying to do the following exercise but I cannot get my code to
ID: 3795673 • Letter: H
Question
Hi,
I have been trying to do the following exercise but I cannot get my code to compile. i would really appreciate some help. Thank you!
Write an equivalent MIPS32 assembly subroutine for the function to calculate x raised to the power y, int power (int x, unsigned int y), where the pseudocode procedure is listed below. Note that all variables in the pseudocode procedure must be represented by data segment variables in the MIPS32 assembly fragment. This fragment is working with 32-bit integers. Follow register conventions established in class. Input: int x, unsigned int y (these must be passed in through registers) f y 2. Return 1 3. Else if y 2 4. Return (power (x, y/2) power (x, y/2)) 5. Else 6. Return (x power (x, y/2) power (x, y/2))Explanation / Answer
.data str1: .asciiz "Give integer X from 1 to 20 " str2: .asciiz "Give integer Y from 0 to 5 " errormsg: .asciiz "Out of range. " nline: .asciiz " " result1: .asciiz " raised to " result2: .asciiz " gives: " .text error: li $v0,4 #print string1 la $a0,errormsg syscall beq $s2,$zero,getX j getY .globl main main: addi $s0,$zero,21 #s0=21 addi $s1,$zero,6 #s1=6 getX: addi $s2,$zero,0 #s2=0 to input x and 1 to input y li $v0,4 la $a0,str1 syscall #print string1 li $v0,5 syscall #read int slt $s3,$v0,$s0 #$s3=($v0Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.