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

2. Write a MIPS assembly language program that a) Prompt the user for an integer

ID: 3870267 • Letter: 2

Question

2. 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".

Explanation / Answer

.file 1 "" .section .mdebug.abi32 .previous .nan legacy .module fp=32 .module nooddspreg .abicalls .rdata .align 2 $LC0: .ascii "Enter number of elements: " // getting number of elements .align 2 $LC1: .ascii "%d" .align 2 $LC2: .ascii "Enter %d element: " // getting each element .align 2 $LC3: .ascii "The sum of integers from 0 to %d is %d." // printing sum .text .align 2 .globl main .set nomips16 .set nomicromips .ent main .type main, @function main: .frame $fp,88,$31 # vars= 56, regs= 2/0, args= 16, gp= 8 .mask 0xc0000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-88 sw $31,84($sp) sw $fp,80($sp) move $fp,$sp .cprestore 16 movz $31,$31,$0 sw $0,28($fp) sw $0,32($fp) 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,36 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) sw $0,24($fp) b $L2 nop $L5: lw $2,24($fp) nop addiu $2,$2,1 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) addiu $3,$fp,40 lw $2,24($fp) nop sll $2,$2,2 addu $2,$3,$2 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 sll $2,$2,2 addiu $3,$fp,24 addu $2,$3,$2 lw $2,16($2) nop beq $2,$0,$L7 nop lw $2,24($fp) nop sll $2,$2,2 addiu $3,$fp,24 addu $2,$3,$2 lw $2,16($2) lw $3,28($fp) nop addu $2,$3,$2 sw $2,28($fp) lw $2,32($fp) nop addiu $2,$2,1 sw $2,32($fp) lw $2,24($fp) nop addiu $2,$2,1 sw $2,24($fp) $L2: lw $2,36($fp) lw $3,24($fp) nop slt $2,$3,$2 bne $2,$0,$L5 nop b $L4 nop $L7: nop $L4: lw $2,32($fp) nop addiu $2,$2,-1 lw $6,28($fp) move $5,$2 lw $2,%got($LC3)($28) nop addiu $4,$2,%lo($LC3) 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,84($sp) lw $fp,80($sp) addiu $sp,$sp,88 j $31 nop .set macro .set reorder .end main .size main, .-main .ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609"

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