Write a MIPS assembly language program that a) Prompt the user for an integer in
ID: 3870697 • Letter: W
Question
Write a MIPS assembly language program that
a) Prompt the user for an integer in the range of 0 to 50. If the user inputs 0 the program stops.
b) Otherwise, the program stores the numbers from 0 up to the input value into an array of words in memory, i.e. initializes the array with values from 0 up to N where N is the value that user has inputted.
c) The program then adds the value of all items of the array together (up to N) by loading them from the main memory then add them up, then prints out the sum with the message "The sum of integers from 0 to N is:". For example, if the user gave 5 as the input the program prints out "The sum of integers from 0 to 5 is 15".
Please include annotation to explain the code
Explanation / Answer
.file 1 "" .section .mdebug.abi32 .previous .nan legacy .module fp=32 .module nooddspreg .abicalls .rdata .align 2 $LC0: .ascii "Ener a number: " .align 2 $LC1: .ascii "%d " .align 2 $LC2: .ascii "the sum is: " .text .align 2 .globl main .set nomips16 .set nomicromips .ent main .type main, @function main: .frame $fp,248,$31 # vars= 216, regs= 2/0, args= 16, gp= 8 .mask 0xc0000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-248 sw $31,244($sp) sw $fp,240($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,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 bne $2,$0,$L2 nop li $4,-1 # 0xffffffffffffffff lw $2,%call16(exit)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,exit 1: jalr $25 nop $L2: sw $0,28($fp) b $L3 nop $L4: lw $2,28($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,28($fp) nop sll $2,$2,2 addiu $3,$fp,24 addu $2,$3,$2 lw $2,12($2) lw $3,24($fp) nop addu $2,$3,$2 sw $2,24($fp) lw $2,28($fp) nop addiu $2,$2,1 sw $2,28($fp) $L3: lw $2,32($fp) lw $3,28($fp) nop slt $2,$3,$2 bne $2,$0,$L4 nop lw $5,24($fp) 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,244($sp) lw $fp,240($sp) addiu $sp,$sp,248 j $31 nop .set macro .set reorder .end main .size main, .-main
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.