Write a MIPS assembly language program that accomplishes the following: The prog
ID: 3909677 • Letter: W
Question
Write a MIPS assembly language program that accomplishes the following: The program will prompt the user to enter an integer n between 0 and 10. If n is out of range, the program displays an error message and prompts again else compute Func(n): if (n = 0 or n=1) return 5 else return 7*Func(n-2) – 8*n; repeat
Use ONLY instructions listed in the Integer Instruction Set (especially when it comes to branches – use only beq, bne or comparisons to zero, no blt, bgt, subi, no multi…) You can use li and move.
Explanation / Answer
.file 1 "" .section .mdebug.abi32 .previous .nan legacy .module fp=32 .module nooddspreg .abicalls .text .align 2 .globl Func .set nomips16 .set nomicromips .ent Func .type Func, @function Func: .frame $fp,32,$31 # vars= 0, regs= 2/0, args= 16, gp= 8 .mask 0xc0000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-32 sw $31,28($sp) sw $fp,24($sp) move $fp,$sp .cprestore 16 movz $31,$31,$0 sw $4,32($fp) lw $2,32($fp) nop beq $2,$0,$L2 nop lw $3,32($fp) li $2,1 # 0x1 bne $3,$2,$L3 nop $L2: li $2,5 # 0x5 b $L4 nop $L3: lw $2,32($fp) nop addiu $2,$2,-2 move $4,$2 lw $2,%got(Func)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,Func 1: jalr $25 nop lw $28,16($fp) move $3,$2 move $2,$3 sll $2,$2,3 subu $3,$2,$3 lw $2,32($fp) nop sll $2,$2,3 subu $2,$3,$2 $L4: move $sp,$fp lw $31,28($sp) lw $fp,24($sp) addiu $sp,$sp,32 j $31 nop .set macro .set reorder .end Func .size Func, .-Func .rdata .align 2 $LC0: .ascii "enter number between 0 to 10 " .align 2 $LC1: .ascii "%d " .text .align 2 .globl main .set nomips16 .set nomicromips .ent main .type main, @function main: .frame $fp,40,$31 # vars= 8, regs= 2/0, args= 16, gp= 8 .mask 0xc0000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-40 sw $31,36($sp) sw $fp,32($sp) move $fp,$sp .cprestore 16 movz $31,$31,$0 lw $2,%got($LC0)($28) nop addiu $4,$2,%lo($LC0) lw $2,%call16(printf)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,printf 1: jalr $25 nop lw $28,16($fp) addiu $2,$fp,24 move $5,$2 lw $2,%got($LC1)($28) nop addiu $4,$2,%lo($LC1) lw $2,%call16(__isoc99_scanf)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,__isoc99_scanf 1: jalr $25 nop lw $28,16($fp) lw $2,24($fp) nop move $4,$2 lw $2,%got(Func)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,Func 1: jalr $25 nop lw $28,16($fp) move $4,$2 lw $2,%call16(printf)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,printf 1: jalr $25 nop lw $28,16($fp) move $2,$0 move $sp,$fp lw $31,36($sp) lw $fp,32($sp) addiu $sp,$sp,40 j $31 nop .set macro .set reorder .end main .size main, .-main .ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.