Allocate storage to store a 3 row by 3 column two demensional array of integers.
ID: 3841682 • Letter: A
Question
Allocate storage to store a 3 row by 3 column two demensional array of integers. Call the array A. Initialize the array with each element's valus as follows: A[0][0]=1 A[0][1]=2 A[0][2]=3 A[1][0]=4 A[1][1]=5 A[1][2]=6 A[2][0]=7 A[2][1]=8 A[2][2]=9 Then , have the program use a loop to continually ask the user to input a pair of integers. The first integer is the row number(row) and the second integer is the column number (column) of an element in the array A.One of these three actions will be performed depending on the value of the row number and column number inputted: 1, if the row number is -1 and the column number is -1 then terminate the loop and the program. 2, or , check to make sure the row number and column number are valid indices for the array A. A valid index for array A is 0,1or2. if either the row number or the column number (or both) are invalid then do nothing and return to the beginning of the loop to ask for a new pair of numbers. 3, if the row numberand the column number are vaild indices then load the value of element A[row][column] from memory and print out value. then , return to the beginning of the loop to ask for a new pair of numbers. You must use subroutines in your program as much as possible. MIPS assembly language program Program Input and Output Program input : Type -1 for the row number and -1 for the column number to terminate terminate the program. Otherwise type 0,1or2for the row number and 0,1,or2 for the column number. Enter a row number. Enter a column number. Program Output: Only if the row number and column number are valid will the program print. For example, if the row number inputted as 1 and column number inputted is 2, then the program output for this input will be: The value for element A[1][2] is 6.
Explanation / Answer
$LFB0 = .
main:
addiu $sp,$sp,-80
sw $31,76($sp)
sw $fp,72($sp)
move $fp,$sp
lui $2,%hi($LC0)
addiu $3,$fp,32
addiu $2,$2,%lo($LC0)
li $4,36 # 0x24
move $6,$4
move $5,$2
move $4,$3
jal memcpy
nop
lui $2,%hi($LC1)
addiu $4,$2,%lo($LC1)
jal puts
nop
addiu $2,$fp,28
move $6,$2
addiu $2,$fp,24
move $5,$2
lui $2,%hi($LC2)
addiu $4,$2,%lo($LC2)
jal scanf
nop
lw $3,24($fp)
li $2,-1 # 0xffffffffffffffff
beq $3,$2,$L9
nop
lw $3,28($fp)
li $2,-1 # 0xffffffffffffffff
beq $3,$2,$L9
nop
lw $2,24($fp)
nop
bltz $2,$L9
nop
lw $2,24($fp)
nop
slt $2,$2,4
beq $2,$0,$L9
nop
lw $2,28($fp)
nop
bltz $2,$L9
nop
lw $2,28($fp)
nop
slt $2,$2,4
beq $2,$0,$L9
nop
lw $3,24($fp)
lw $4,28($fp)
move $2,$3
sll $2,$2,1
addu $2,$2,$3
addu $2,$2,$4
sll $2,$2,2
addiu $3,$fp,24
addu $2,$3,$2
lw $2,8($2)
nop
move $5,$2
lui $2,%hi($LC3)
addiu $4,$2,%lo($LC3)
jal printf
nop
b $L8
nop
nop
b $L6
nop
move $2,$0
move $sp,$fp
lw $31,76($sp)
lw $fp,72($sp)
addiu $sp,$sp,80
j $31
nop
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.