Question: Using MIPS(MARS4.5) In this problem, youll complete another assembly program, found in hw2_inserts.asm, where you will insert the integer 42 into the front of an
Using MIPS(MARS4.5)
In this problem, youll complete another assembly program, found in hw2_inserts.asm, where you will insert the integer 42 into the front of an array of 4-byte integers. This program takes command line arguments for an array. An example command line arguments: 1 2 3 4 beware of the restrictive formatting: (single-digit positive, decimal integers) Starting state for the example regi s ter $s 0 = 3 ( th e n u mb er o f el emen ts i n the array) register $s1 = 0x10040000 (address of the start of the array) input array (stored in memory) 0x10040000 1 0x10040004 2 0x10040008 3 0x1000400C 4 At the end of your program, the array should contain the number 42 at the front, with everything else moved down. 0x10040000 42 0x10040004 1 0x10040008 2 0x1000400C 3 0x10004010 4 Not
This is code of hw2_inserts.asm
.data error_string: .asciiz "ERROR: invalid arguments "
.text main: # Do not modify this code. It is responsible for # command line parsing. See further below. addiu $a0,$a0,4 blt $a0,3,error addiu $s0, $a0, -1 divu $s0, $s0, 2 move $t9, $s0 sll $t8, $t9, 2 sll $t7, $t9, 3 li $v0, 9 move $a0, $t7 # sbrk 4*num * 2 bytes syscall move $s1, $v0 addu $s2, $s1, $t8 move $s3, $s1 charloop1: lw $t0, 0($a1) lb $t1, 0($t0) addiu $t1,$t1,-48 sw $t1, 0($s3) addiu $s3, $s3, 4 addiu $t9, $t9, -1 addiu $a1, $a1, 4 bgt $t9, $zero, charloop1
# $s0 contains the number of elements in the array # $s1 contains the address of the array of integers # Your job is to insert the number 42 into the front # of the array, moving over all the other elements. # # The array is fixed in memory; don't just insert 42 in the address before the start of the array # # E.g. (here the value in $s0 would be 3) # values in the array before: # [1, 2, 3, ?] # values in the array after: # [42, 1, 2 3]
# YOUR SOLUTION GOES HERE exit: # exit cleanly li $v0, 10 syscall error: la $a0, error_string li $v0, 4 # print syscall j exit
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
