Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This lab is fully written, including main and all other subprograms. However, there are numerous errors scattered throughout the program, and your task is to

This lab is fully written, including main and all other subprograms.

However, there are numerous errors scattered throughout the program, and your task is to locate each one and fix it. These range from syntax errors (errors that show up when you try to load the file into QtSpim) to logic errors (errors that either cause the program to crash at runtime, or causes the program to do the wrong thing.)

There are 23 total errors that you will need to locate and fix. Some helpful hints:

  1. It is suggested to look for the all of the syntax errors first.
  2. The subprogram sort_array has no errors in it at all.Do not change anything in sort_array!
  3. All areas where there are errors are marked with a #To do comment. There may be some places where more than one change needs to be made.
  4. You may find it helpful to write comments where you made changes to keep track of what was changed and why.

###########################################################

# Lab 6 - Debugging

# Name:

# Date:

#

# Objective:

# The purpose of this lab assignment is to help you understand

# debugging processes in assembly language using debug tools

# provided by QtSpim

#

# Description:

# 1) Syntax, logic, and comment errors exist in:

# - main

# - print_array

# - read_array

# - allocate_array

# 2) Find and fix the syntax, logical, and comment errors

# *** Hint: Find all the \"#To do\" and fix bugs ***

# *** There are 23 total bugs to fix! ***

# 3) Test the code. If the code is working, submit to

# the Lab #6 dropbox on Canvas

#

# Note:

# sort_array subprogram is correct and has no bug, do not modify sort_array!

#

# Sample run:

# Enter size of the array to allocate (size > 0): 5

# Enter an integer: 4

# Enter an integer: 3

# Enter an integer: 2

# Enter an integer: 1

# Enter an integer: -5

# Array: 4 3 2 1 -5

# Array: -5 1 2 3 4

#

###########################################################

.data

array_pointer_p: .word 0 # holds address of dynamic array (address)

array_size_p: .word 0 # hold size of dynamic array (value)

newline_p: .asciiz \" \"

###########################################################

.text

main:

# set up arguments for allocate_array subprogram

la $a0, array_pointer_p # load the address of static variable array_pointer into register $a0

la $a1, array_size_p # load the address of static variable array_size into register $a1

jal allocate_array # call subprogram allocate_array

# arguments IN: address of static variable \"array_pointer\" & \"array_size\"

# arguments OUT: NONE

# set up arguments for read_array subprogram

#To do: Think about the logic and syntax and fix errors

la $a0, array_pointer_p # load the address of variable array_pointer into register $a0

la $a1, array_size_p # load the address of variable array_size into register $a1

jal read_array # call subprogram read_array

# arguments IN: true address of dynamic array and array size value

# arguments OUT: NONE

# calling subprogram print_array

#To do: Think about the logic and syntax and fix errors

la $a0, array_pointer_p # load the address of variable array_pointer into register $a0

la $a1, array_size_p # load the address of variable array_size into register $a1

jal print_array # calling subprogram print_array

# print newline character

la $a0, newline_p # prints newline character

li $v0, 4

syscall

# calling subprogram sort_array

#To do: Think about the logic and syntax and fix errors

la $a0, array_pointer_p # load the address of variable array_pointer into register $a0

la $a1, array_size_p # load the address of variable array_size into register $a1

jal sort_array # calling subprogram sort_array

# calling subprogram print_array

#To do: Think about the logic and syntax and fix error

la $a0, array_pointer_p # load the address of variable array_pointer into register $a0

la $a1, array_size_p # load the address of variable array_size into register $a1

jal print_array # calling subprogram print_array

mainEnd:

li $v0, 4

syscall # Halt

###########################################################

# Arguments IN and OUT of subprogram

# $a0 Holds array pointer (address)

# $a1 Holds array size pointer (address)

# $a2

# $a3

# $v0

# $v1

# $sp

# $sp+4

# $sp+8

# $sp+12

###########################################################

# Register Usage

# $t0 Holds array pointer (address)

# $t1 Holds array size pointer (address)

# $t2 Holds array size, temporarily

###########################################################

.data

allocate_array_prompt_p: .asciiz \"Enter size of the array to allocate (size > 0): \"

allocate_array_invalid_p: .asciiz \"Array size you entered is incorrect (size > 0)! \"

###########################################################

.text

allocate_array:

# save arguments so we do not lose them

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions

Question

What is the measure of reliability of a confidence interval?

Answered: 1 week ago