Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Write an assembly program that asks for the number of integers to be read. It then dynamically allocates an array of that size. It will

Write an assembly program that asks for the number of integers to be read. It then dynamically allocates an array of that size. It will stop reading integers when the array is full. After all the integers are read and validated, the program displays the entries in reverse order, the sum of the entries, and the average of the entries to 4 decimal places using only MIPS Integer commands. There will be at least 4 subprograms.

The first subprogram allocate_array will ask the user for the number of integers to be read and dynamically declares an array to hold them. It receives no arguments IN and has two arguments OUT, the base address of the dynamically declared array and it size. Do not forget to validate array size (array size should be greater than zero).

The second subprogram read_values which receives two arguments IN, the array base address and its size. Also, it makes sure that each entered number is non-negative and divisible by 2 and 3. It returns (OUT) the sum of valid numbers read in the appropriate registers.

The third subprogram print_backwards receives the base address of the array and its size as arguments IN. It has no arguments OUT. It outputs the array in reverse order one number per line at a time.

Hint: Ex: Your array length = 6. Element type = Word / Integer.

#element0

#element1

#element2

#element3

#element4

#element5

You need to print the last element first. So, at the beginning of your printing backwards iteration, at least one of your register should hold the address of theArrow_Marked location of your array.

The fourth subprogram print_average which receives as arguments IN the total and count and has no arguments OUT. It outputs the average of the numbers read to 4 decimal places using only integer commands.

Hint: Take just a pencil and paper. Now try to divide 7 / 3 by hand till 4th decimal point (X. XXXX). How are you obtaining the values after the decimal point? Replicate that same step by step operation in MIPS to get the values after decimal point.

In main, you will call all 4 subprograms and declare and use static variables to hold the base address of the array, count of element, and the sum of values of the elements. This is what i have so far:

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

# Program Description

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

# Register Usage

# $t0

# $t1

# $t2

# $t3

# $t4

# $t5

# $t6

# $t7

# $t8

# $t9

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

.data

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

.text

main:

li $v0, 10 #End Program

syscall

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

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

# Subprogram Description

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

# Arguments In and Out of subprogram

#

# $a0

# $a1

# $a2

# $a3

# $v0

# $v1

# $sp

# $sp+4

# $sp+8

# $sp+12

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

# Register Usage

# $t0

# $t1

# $t2

# $t3

# $t4

# $t5

# $t6

# $t7

# $t8

# $t9

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

.data

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

.text

jr $ra #return to calling location

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

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

# Subprogram Description

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

# Arguments In and Out of subprogram

#

# $a0

# $a1

# $a2

# $a3

# $v0

# $v1

# $sp

# $sp+4

# $sp+8

# $sp+12

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

# Register Usage

# $t0

# $t1

# $t2

# $t3

# $t4

# $t5

# $t6

# $t7

# $t8

# $t9

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

.data

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

.text

jr $ra #return to calling location

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

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

# Subprogram Description

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

# Arguments In and Out of subprogram

#

# $a0

# $a1

# $a2

# $a3

# $v0

# $v1

# $sp

# $sp+4

# $sp+8

# $sp+12

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

# Register Usage

# $t0

# $t1

# $t2

# $t3

# $t4

# $t5

# $t6

# $t7

# $t8

# $t9

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

.data

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

.text

jr $ra #return to calling location

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

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

# Subprogram Description

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

# Arguments In and Out of subprogram

#

# $a0

# $a1

# $a2

# $a3

# $v0

# $v1

# $sp

# $sp+4

# $sp+8

# $sp+12

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

# Register Usage

# $t0

# $t1

# $t2

# $t3

# $t4

# $t5

# $t6

# $t7

# $t8

# $t9

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

.data

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

.text

jr $ra #return to calling location

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

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

# Subprogram Description

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

# Arguments In and Out of subprogram

#

# $a0

# $a1

# $a2

# $a3

# $v0

# $v1

# $sp

# $sp+4

# $sp+8

# $sp+12

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

# Register Usage

# $t0

# $t1

# $t2

# $t3

# $t4

# $t5

# $t6

# $t7

# $t8

# $t9

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

.data

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

.text

jr $ra #return to calling location

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

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_2

Step: 3

blur-text-image_3

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

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students explore these related Databases questions