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

PLEASE ANSWER QUESTION 1 in MIPS format!! int A[8], B[8], C[8]; void main() { in

ID: 3915957 • Letter: P

Question

PLEASE ANSWER QUESTION 1 in MIPS format!! int A[8], B[8], C[8]; void main() { int i; for (i = 7; i >= 0; i--) { if (A[i] > B[i]) { C[i] = A[i] - 1; } else { C[i] = B[i] + 1; } } } .text lui $s0,0x1001 # $s0 = &(A[0]) addi $s1,$s0,32 # $s1 = &(B[0]) addi $s2,$s0,64 # $s2 = &(C[0]) addi $t6,$0,0x0007 # i=t6[31..0]=0x00000007 loop: slt $t7,$t6,$0 # if (i < 0) , then $t7=1 bne $t7,$0,exit # if $t7=1 , then break from loop add $t1,$t6,$t6 # $t1=2*i add $t1,$t1,$t1 # $t1=4*i add $t2,$s0,$t1 # $t2=4*i + &A[0] add $t3,$s1,$t1 # $t3=4*i + &B[0] lw $t2,0($t2) # $t2=A[i] lw $t3,0($t3) # $t3=B[i] slt $t4,$t3,$t2 # if (B[i] < A[i]) , then $t4=1 add $t1,$t1,$s2 # $t1=4*i + &C[0] beq $t4,$0,else # if $t4=1, then jump to else addi $t5,$t2,-1 # C[i]=A[i]-1 j after else: addi $t5,$t3,1 # C[i]=B[i]+1 after: sw $t5,0($t1) # $t5 = &C[i] addi $t6,$t6,-1 # i=i-1 j loop exit: syscall .data A: .word 1, 9, 3, 7, 5, 5, 7, 3 B: .word 10, 2, 8, 4, 6, 6, 4, 8 C: Q1) Consider an array A of size 5 and containing the integers 33, 20, 18, 45, and 100, respectively. Wire an Assembly code that sorts this array in an ascending manner and stores the sorted integers in a new array B (that is, the elements of A remain in their same order). The elements of B are then divided by 100. Keep in mind that you can use within your code any assembly instruction that is supported by assembler regardless of whether it is being used in the course (i.e. mul, div, ... etc.). PLEASE ANSWER QUESTION 1 in MIPS format!! int A[8], B[8], C[8]; void main() { int i; for (i = 7; i >= 0; i--) { if (A[i] > B[i]) { C[i] = A[i] - 1; } else { C[i] = B[i] + 1; } } } .text lui $s0,0x1001 # $s0 = &(A[0]) addi $s1,$s0,32 # $s1 = &(B[0]) addi $s2,$s0,64 # $s2 = &(C[0]) addi $t6,$0,0x0007 # i=t6[31..0]=0x00000007 loop: slt $t7,$t6,$0 # if (i < 0) , then $t7=1 bne $t7,$0,exit # if $t7=1 , then break from loop add $t1,$t6,$t6 # $t1=2*i add $t1,$t1,$t1 # $t1=4*i add $t2,$s0,$t1 # $t2=4*i + &A[0] add $t3,$s1,$t1 # $t3=4*i + &B[0] lw $t2,0($t2) # $t2=A[i] lw $t3,0($t3) # $t3=B[i] slt $t4,$t3,$t2 # if (B[i] < A[i]) , then $t4=1 add $t1,$t1,$s2 # $t1=4*i + &C[0] beq $t4,$0,else # if $t4=1, then jump to else addi $t5,$t2,-1 # C[i]=A[i]-1 j after else: addi $t5,$t3,1 # C[i]=B[i]+1 after: sw $t5,0($t1) # $t5 = &C[i] addi $t6,$t6,-1 # i=i-1 j loop exit: syscall .data A: .word 1, 9, 3, 7, 5, 5, 7, 3 B: .word 10, 2, 8, 4, 6, 6, 4, 8 C: Q1) Consider an array A of size 5 and containing the integers 33, 20, 18, 45, and 100, respectively. Wire an Assembly code that sorts this array in an ascending manner and stores the sorted integers in a new array B (that is, the elements of A remain in their same order). The elements of B are then divided by 100. Keep in mind that you can use within your code any assembly instruction that is supported by assembler regardless of whether it is being used in the course (i.e. mul, div, ... etc.). PLEASE ANSWER QUESTION 1 in MIPS format!! int A[8], B[8], C[8]; void main() { int i; for (i = 7; i >= 0; i--) { if (A[i] > B[i]) { C[i] = A[i] - 1; } else { C[i] = B[i] + 1; } } } .text lui $s0,0x1001 # $s0 = &(A[0]) addi $s1,$s0,32 # $s1 = &(B[0]) addi $s2,$s0,64 # $s2 = &(C[0]) addi $t6,$0,0x0007 # i=t6[31..0]=0x00000007 loop: slt $t7,$t6,$0 # if (i < 0) , then $t7=1 bne $t7,$0,exit # if $t7=1 , then break from loop add $t1,$t6,$t6 # $t1=2*i add $t1,$t1,$t1 # $t1=4*i add $t2,$s0,$t1 # $t2=4*i + &A[0] add $t3,$s1,$t1 # $t3=4*i + &B[0] lw $t2,0($t2) # $t2=A[i] lw $t3,0($t3) # $t3=B[i] slt $t4,$t3,$t2 # if (B[i] < A[i]) , then $t4=1 add $t1,$t1,$s2 # $t1=4*i + &C[0] beq $t4,$0,else # if $t4=1, then jump to else addi $t5,$t2,-1 # C[i]=A[i]-1 j after else: addi $t5,$t3,1 # C[i]=B[i]+1 after: sw $t5,0($t1) # $t5 = &C[i] addi $t6,$t6,-1 # i=i-1 j loop exit: syscall .data A: .word 1, 9, 3, 7, 5, 5, 7, 3 B: .word 10, 2, 8, 4, 6, 6, 4, 8 Q1) Consider an array A of size 5 and containing the integers 33, 20, 18, 45, and 100, respectively. Wire an Assembly code that sorts this array in an ascending manner and stores the sorted integers in a new array B (that is, the elements of A remain in their same order). The elements of B are then divided by 100. Keep in mind that you can use within your code any assembly instruction that is supported by assembler regardless of whether it is being used in the course (i.e. mul, div, ... etc.).

Explanation / Answer

.data

Array: .word 33, 20, 18, 45, 100

Array_B: .space 20

.text

.globl main

main:

la $t0, Array # Copy the base address of your array into $t1

add $t0, $t0, 20 # 4 bytes per int * 5 ints = 20 bytes   

la $t1, Array_B

add $t1, $t1, 20

la $t0, Array

la $t3, Array_B

LOOP:

beq $t3,$t1,OUT_LOOP

lw $t2,0($t0)

sw $t2,0($t3)

addi $t0,$t0,4

addi $t3,$t3,4

b LOOP

OUT_LOOP:

la $t0, Array_B # Copy the base address of your array into $t1

add $t0, $t0, 20 # 4 bytes per int * 5 ints = 20 bytes   

outterLoop: # Used to determine when we are done iterating over the Array

add $t1, $0, $0 # $t1 holds a flag to determine when the list is sorted

la $a0, Array_B # Set $a0 to the base address of the Array

innerLoop: # The inner loop will iterate ove

lw $t2, 0($a0) # sets $t0 to the current element in array

lw $t3, 4($a0) # sets $t1 to the next element in array

slt $t5, $t2, $t3 # $t5 = 1 if $t0 < $t1

beq $t5, $0, continue # if $t5 = 1, then swap them

add $t1, $0, 1 # if we need to swap, we need to check the list again

sw $t2, 4($a0)

sw $t3, 0($a0)

continue:

addi $a0, $a0, 4   

bne $a0, $t0, innerLoop # If $a0 != the end of Array, jump back to innerLoop

bne $t1, $0, outterLoop # $t1 = 1, another pass is needed, jump back to outterLoop

la $t3, Array_B

la $t1, Array_B

add $t1, $t1, 20

DIV_LOOP:

beq $t3,$t1,OUT_DIV_LOOP

lw $t0,0($t3)

li $t4,100

div $t0,$t4

mflo $t0

sw $t0,0($t3)

addi $t3,$t3,4

b DIV_LOOP

OUT_DIV_LOOP:

li $v0,10

syscall

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