Assignment Description: An array of integers can be assigned to a memory address
ID: 3743944 • Letter: A
Question
Assignment Description: An array of integers can be assigned to a memory address in the .data section of a MIPS assembly language program as show below. Here the length of the array is stored first, and then the elements of the array numbers next. You are given the following C program that will ask a user to enter two integers and they should be stored into variables named, index and num2. Using the first integer, index, it should examine each integer in the array up to the index to see if it is divisible by the second entered integer, num2. (You can divide each integer by the entered integer to see if its remainder is zero) and if it is, then the number should be multiplied by the second number, num2. If the first entered integer, index is less than 0, then no integer in the array should be changed. If the first entered integer, index is more than 10, then all integers in the array should be examined to see if they should be changed (by multiplying by the second number). After modifying the array, each integer in the array should be printed. Implement a MIPS assembly language program to perform the functionality of the following C program and print the updated array content, by listing each integer in it For instance, if a user enters 5, then enters 3, then the output will be the following: -81 46 72 -5 14 -18 12 35 i.e., the numbers that are located until the index 5: (-27, 3, 46, -7, 11, 24) are examined to see if cach of them is divisible by the second entered number, 3. In this case, -27, 3, 24 that are divisible by 3, thus they are multiplied by the second entered number 3, then we get (-81, 9, 46, -7, 11, 72, -5, 14, -18, 12, 35) If your program causes an infinite loop, press Control and 'C' keys at the same time to stop it. Name your source code file assignment5.s. numbers_len: numbers: data word word -27, 3, 46,7, 11, 24, -5, 14, -18, 12, 35Explanation / Answer
.file 1 "" .section .mdebug.abi32 .previous .nan legacy .module fp=32 .module nooddspreg .abicalls .section .rodata.str1.4,"aMS",@progbits,1 .align 2 $LC1: .ascii "Enter an integer: " .align 2 $LC2: .ascii "%d " .align 2 $LC3: .ascii "Enter another integer: " .align 2 $LC4: .ascii "Result Array Content: " .align 2 $LC5: .ascii "%d
" .rdata .align 2 $LC0: .word -27 .word 3 .word 46 .word -7 .word 11 .word 24 .word -5 .word 14 .word -18 .word 12 .word 35 .section .text.startup,"ax",@progbits .align 2 .globl main .set nomips16 .set nomicromips .ent main .type main, @function main: .frame $sp,104,$31 # vars= 56, regs= 5/0, args= 16, gp= 8 .mask 0x800f0000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-104 lw $5,%got($LC0)($28) lw $25,%call16(memcpy)($28) sw $18,92($sp) addiu $18,$sp,24 movz $31,$31,$0 li $6,44 # 0x2c sw $31,100($sp) .cprestore 16 addiu $5,$5,%lo($LC0) sw $16,84($sp) sw $19,96($sp) sw $17,88($sp) .reloc 1f,R_MIPS_JALR,memcpy 1: jalr $25 move $4,$18 lw $28,16($sp) nop lw $4,%got($LC1)($28) lw $25,%call16(puts)($28) nop .reloc 1f,R_MIPS_JALR,puts 1: jalr $25 addiu $4,$4,%lo($LC1) lw $28,16($sp) addiu $5,$sp,72 lw $16,%got($LC2)($28) lw $25,%call16(__isoc99_scanf)($28) nop .reloc 1f,R_MIPS_JALR,__isoc99_scanf 1: jalr $25 addiu $4,$16,%lo($LC2) lw $28,16($sp) nop lw $4,%got($LC3)($28) lw $25,%call16(puts)($28) nop .reloc 1f,R_MIPS_JALR,puts 1: jalr $25 addiu $4,$4,%lo($LC3) lw $28,16($sp) addiu $5,$sp,68 lw $25,%call16(__isoc99_scanf)($28) nop .reloc 1f,R_MIPS_JALR,__isoc99_scanf 1: jalr $25 addiu $4,$16,%lo($LC2) lw $28,16($sp) lw $6,72($sp) lw $5,68($sp) move $4,$18 move $3,$0 li $7,11 # 0xb $L2: slt $2,$6,$3 bne $2,$0,$L6 nop lw $2,0($4) nop bne $5,$0,1f div $0,$2,$5 break 7 1: mfhi $8 nop bne $8,$0,$L3 mult $2,$5 mflo $2 sw $2,0($4) $L3: addiu $3,$3,1 bne $3,$7,$L2 addiu $4,$4,4 $L6: lw $4,%got($LC4)($28) lw $25,%call16(puts)($28) nop .reloc 1f,R_MIPS_JALR,puts 1: jalr $25 addiu $4,$4,%lo($LC4) lw $28,16($sp) move $16,$0 lw $17,%got($LC5)($28) li $19,44 # 0x2c addiu $17,$17,%lo($LC5) addu $2,$18,$16 $L11: lw $25,%call16(__printf_chk)($28) lw $6,0($2) move $5,$17 li $4,1 # 0x1 .reloc 1f,R_MIPS_JALR,__printf_chk 1: jalr $25 addiu $16,$16,4 lw $28,16($sp) bne $16,$19,$L11 addu $2,$18,$16 lw $31,100($sp) lw $19,96($sp) lw $18,92($sp) lw $17,88($sp) lw $16,84($sp) move $2,$0 j $31 addiu $sp,$sp,104
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.