Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Would appreciate the help in SPIM. Write a program in assembly language using th

ID: 3717642 • Letter: W

Question

Would appreciate the help in SPIM.

Write a program in assembly language using the MIPS instruction set to calculate the nth Fibonacci number. This must be done in an iterative loop. Your program will read from input the value of n. Be sure to validate user input and report errors when necessary. n must be a natural number that can not be too large that the value of f(n) cannot be expressed with a 32-bit unsigned integer and can be output to the console in SPIM. While iterating through this loop, store the value of f(n) in an array. Ths array should be large enough to contain N values (where N is the largest permissible value of n.) Your program should then output the nth Fibonacci number then output the portion of the sequence stored in the array.

Explanation / Answer

fibo_iter: .frame $fp,32,$31 # vars= 16, regs= 1/0, args= 0, gp= 8 .mask 0x40000000,-4 .fmask 0x00000000,0 .set noreorder .set nomacro addiu $sp,$sp,-32 sw $fp,28($sp) move $fp,$sp sw $4,32($fp) li $2,1 # 0x1 movz $31,$31,$0 sw $2,8($fp) li $2,1 # 0x1 sw $2,12($fp) li $2,1 # 0x1 sw $2,16($fp) li $2,3 # 0x3 sw $2,20($fp) b $L2 nop $L3: lw $3,12($fp) lw $2,8($fp) nop addu $2,$3,$2 sw $2,16($fp) lw $2,12($fp) nop sw $2,8($fp) lw $2,16($fp) nop sw $2,12($fp) lw $2,20($fp) nop addiu $2,$2,1 sw $2,20($fp) $L2: lw $3,20($fp) lw $2,32($fp) nop slt $2,$2,$3 beq $2,$0,$L3 nop lw $2,16($fp) move $sp,$fp lw $fp,28($sp) addiu $sp,$sp,32 j $31 nop .set macro .set reorder .end fibo_iter .size fibo_iter, .-fibo_iter .rdata .align 2 $LC0: .ascii "Enter the integer n to find nth fibonnaci no.(0 to exit)" .ascii ": " .align 2 $LC1: .ascii "%d" .align 2 $LC2: .ascii "The array is %d" .text .align 2 .globl main .set nomips16 .set nomicromips .ent main .type main, @function main: .frame $fp,448,$31 # vars= 416, regs= 2/0, args= 16, gp= 8 .mask 0xc0000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-448 sw $31,444($sp) sw $fp,440($sp) move $fp,$sp .cprestore 16 $L10: 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,32 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,32($fp) nop beq $2,$0,$L13 nop lw $2,32($fp) nop move $4,$2 lw $2,%got(fibo_iter)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,fibo_iter 1: jalr $25 nop lw $28,16($fp) sw $2,28($fp) sw $0,24($fp) b $L8 nop $L9: lw $2,24($fp) nop sll $2,$2,2 addiu $3,$fp,24 addu $2,$3,$2 lw $3,28($fp) nop sw $3,12($2) lw $2,24($fp) nop addiu $2,$2,1 sw $2,24($fp) $L8: lw $2,24($fp) nop slt $2,$2,101 bne $2,$0,$L9 nop b $L10 nop $L13: nop lw $2,36($fp) nop move $5,$2 lw $2,%got($LC2)($28) nop addiu $4,$2,%lo($LC2) 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,444($sp) lw $fp,440($sp) addiu $sp,$sp,448 j $31 nop

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote