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

Hello I\'m having a problem with MIPS. Routine split is called with four argumen

ID: 2079445 • Letter: H

Question

Hello I'm having a problem with MIPS.

Routine split is called with four arguments. Register a0 holds the number of elements in an input array, register a1 holds the address of the input array. The input array consists of 4-byte elements. Register a2 holds the address of a 4-byte-element output array and register a3 holds the address of a 2-byte-element output array. Complete split so that it copies elements from the input array to the 2-byte output array (if it fits), otherwise to the 4-byte output array. The return value, in register v0, should be the number of elements in the 4-byte output array when copying is done.

# CALL VALUES:

# $a0: Number of elements in input array.

# $a1: Address of input array. Elements are 4 bytes each.

# $a2: Address of output array, elements are 4 byte each.

# $a3: Address of output array, elements are 2 byte each.

#

# RETURN:

# $v0, Number of elements in 4-byte output array.

# Write small elements in $a3 array and large elements in $a2.

#

# Note:

# Can modify $t0-$t9, $a0-$a3

Any help with this problem would be great, thank you very much.

Explanation / Answer

## Main Routine # This routine runs the test code for the problems It does not have to # be modified but it can be if it would help. If you're thinking of # improving your grade by deleting the test cases which your code gets # wrong you'll need to come up with a better plan. .data array: .word 1 7 4 3 8 arraym: .word 12 1 7 4 3 8 arrayb: .word 50 99 10 51 98 83 70 40 30 35 19 arraydull: .word 1 1 1 1 1 1 no_more_arrays: .word 0 # Keep label above word-aligned products: .double 672. .double 8064. .double 1147045048380000000. .double 1. arrays: .word array .word arraym .word arrayb .word arraydull .word no_more_arrays .word 0 descriptions: .asciiz "Minimum element first." .asciiz "Maximum element first." .asciiz "Middle element first." .asciiz "All ones." msg_element: .asciiz "%/t5/s %/t1/2d " msg_running_test: .ascii "Running test: %/a2/s, XX below shows any sort error position. " .asciiz "Before: " msg_bye: .asciiz "Done with tests. " msg_before: .asciiz "Before: " msg_after: .asciiz "After : " msg_null: .asciiz "" msg_xx: .asciiz "XX" msg_eol: .asciiz " " msg_prod: .asciiz "Product of:" msg_prod_is: .asciiz " returned is %/f0/.2f, correct is %/f2/.2f. " .text .globl __start __start: la $s0, arrays la $s1, descriptions la $s2, products MSLOOP: lw $a1, 4($s0) beq $a1, $0 MSEXIT nop jal product lw $a0, 0($s0) addi $v0, $0, 11 la $a0, msg_prod syscall lw $a0, 0($s0) la $a2, msg_null jal show lw $a1, 4($s0) ldc1 $f2, 0($s2) addi $s2, $s2, 8 la $a0, msg_prod_is addi $v0, $0, 11 syscall jal strlen addi $a0, $s1, 0 add $s1, $s1, $v0 addi $s1, $s1, 1 j MSLOOP addi $s0, $s0, 4 la $s0, arrays la $s1, descriptions MSEXIT: la $s0, arrays la $s1, descriptions MLOOP: lw $a1, 4($s0) beq $a1, $0 MEXIT lw $a0, 0($s0) jal runsort addi $a2, $s1, 0 jal strlen addi $a0, $s1, 0 add $s1, $s1, $v0 addi $s1, $s1, 1 j MLOOP addi $s0, $s0, 4 MEXIT: la $a0, msg_bye addi $v0, $0, 11 syscall addi $v0, $0, 10 syscall ################################################################################ ## runsort: Call sort routine on array. # # Print descriptive message, array $A0-$A1 (before version), call sort, # then print array again, showing an XX at between first misordered # elements (if any). # CALL VALUE: $a0 Address of array. # CALL VALUE: $a1 Address of array end. (Element after last.) # CALL VALUE: $a2 Address of string describing array. runsort: sw $ra, -4($sp) sw $s0, -8($sp) sw $s1, -12($sp) addi $sp, $sp, -12 addi $s0, $a0, 0 addi $s1, $a1, 0 addi $v0, $0, 11 la $a0, msg_running_test syscall addi $a0, $s0, 0 la $a2, msg_null jal show nop addi $a0, $s0, 0 addi $a1, $s1, 0 jal sort nop la $a0, msg_after addi $v0, $0, 11 syscall la $a2, msg_xx addi $a0, $s0, 0 jal show addi $a1, $s1, 0 addi $v0, $0, 11 la $a0, msg_eol syscall addi $sp, $sp, 12 lw $ra, -4($sp) lw $s0, -8($sp) jr $ra lw $s1, -12($sp)

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