[SOLVED] 代写 MIPS assembly Lab 5: Subroutines

30 $

File Name: 代写_MIPS_assembly_Lab_5:_Subroutines.zip
File Size: 367.38 KB

SKU: 9336618867 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


Lab 5: Subroutines

Part A:Due Wednesday, 4 December 2019, 11:59 PMPart B:Due Wednesday, 11 December 2019, 11:59 PM
Minimum Submission Requirements
Ensure that your Lab5 folder contains the following files note the capitalization convention:
Lab5.asm
README.txt
Completed Google Form
Commit and push your repository
Note: you are not required to submit a block diagram or pseudocode for this assignment
Objectives
In this lab, you will:
Utilize arrays
Convert numerical ASCII strings to integers
Convert integers to decimal ASCII strings
Implement functions
Manage data on the stack
Use a test file to test functions
Use macros to automate programming
Provided Files
lab5template19q4face12.asm
lab5test19q4face12.asm
lab5blockdiagram19q4face12.png
Preparation
Read
Introduction To MIPS Assembly Language Programmingchapters 5, 6; sections 8.1, 8.2
Macros
ASCII reference table
Watch
Procedureswatch videos 2.72.12
Functionswatch video tutorials 1518
Description
You will be writing subroutines to convert a numerical ASCII string array to an integer array, sort the values, and print the sorted array to the screen in decimal. You will be using a test file to test the subroutines.
You may assume that the array will contain 3 values. For extra credit, you may implement code to take any number of values.
Example
Here are two sample outputs from the main function.
Base Assignment

Input string array
0xFFFFFFFC 0x00000010 0x00000008

Sorted integer array
4 8 16
Extra Credit Option

Input string array
0xFFFFFFFF 0xFFFFFFFC 0x00000010 0x00000008 0x00000004

Sorted integer array
4 1 4 8 16
Specification
You will need to implement a set of specific subroutines indicated in this lab instruction. You are required to start with the skeleton code provided lab5template19q4face12.asm. Dont forget to rename the file to Lab5.asm
A test file lab5test19q4face12.asm is provided that imports and tests each one of your subroutines individually, and all together. In order for your subroutines to function properly, you must use the instructions JAL and JR to enter and exit subroutines.
To receive any credit for your subroutines, Lab5.asm must assemble both on its own and with the test file.
Skeleton Code
Start writing your subroutines using the skeleton code lab5template19q4face12.asm provided. Make sure to rename this file to Lab5.asm.
Test File
The file lab5test19q4face12.asm contains code that you can use to test your subroutines. This file tests each subroutine individually, displaying relevant input and output values before and after each subroutine call. In addition, it prints the values of the save registers before and after each subroutine to ensure that they have not been altered by the subroutine.
To test your subroutines:
Ensure lab5test19q4face12.asm is in the same folder as Lab5.asm
Change the last line of the test file from:.includelab5template19q4face12.asmto.includeLab5.asm
Assemble the test file.
Enter the test case in the program arguments field.
Run the test file.
Note that for some subroutines, the input is hardcoded directly before the subroutine is called. Spend some time reviewing the test file and modifying the test cases.
A sample output from the test file can be found in the appendix.
Syscalls
You may not use syscalls 13, 58, or 3436. You must use either syscall 11 or 4 to print the decimal values to the screen.
Block Diagram
The following diagram describes program flow and subroutine interaction. A full sized version of the diagram can be found here.
Note that a full block diagram for printdecimalarray and printdecimal are not provided. We suggest that you come up with your own block diagram to help you plan this part of the code. Note that you are not required to turn in a block diagram for this assignment.

Figure: Block Diagram
Program Flow
The general flow of the main function is described below
mainfunctionlab519q4face12 is called
printstrarray is called and ASCII input array is printed to screen
strtointarray is called
subroutine loops through ASCII strings, converting each to its corresponding integer value using strtoint, and saved to an array
sortarray is called
printdecimalarray is called
subroutine loops through integer array, printing the values in decimal to the screen
Note that exitprogram is not called in the main function.
The Stack
In this lab, you will use the program stack to handle the preservation of certain register values at the start of a subroutine so that they can be restored at the end of a subroutine. The stack should be used to preserve the jump and link return address, ra, so you can navigate out of nested subroutines. In addition, the values in registers s0s7 must be preserved across subroutine calls, i.e. if you use any of the s registers in a subroutine, you must push them at the beginning of the subroutine and pop them after the end of the subroutine. There is no need to push registers to the stack that you dont use.
Subroutines
Lab5.asm will contain the subroutines to execute the program. You must use the JAL instruction to enter subroutines. Each subroutine will be tested individually; your subroutines must function in isolation.
Nested Subroutines
The required subroutines are nested as shown:
mainfunctionlab5q4face12
printstrarray
strtointarray
strtoint
sortarray
printdecimalarray
printdecimal
The subroutines printstrarray, strtointarray, and sortarray, and printdecimalarray are called from mainfuntionlab5ce12. The subroutines strtoint and printdecimal are called from strtointarray and printdecimalarray, respectively.
In order to properly execute these nested subroutines, you must use the stack to handle the return address register, ra.
Required Subroutines

mainfunctionlab519q4face12

Calls printstrarray, strtointarray, sortarray,
printdecimalarray.

You may assume that the array of string pointers is terminated by a
32bit zero value. You may also assume that the integer array is large
enough to hold each converted integer value and is terminated by a
32bit zero value.

arguments:a0pointer to integer array

a1double pointer to string array pointer to array of
addresses that point to the first characters of each
string in array

returns:v0minimum element in array 32bit int
v1maximum element in array 32bit int

printstrarray

Prints array of ASCII inputs to screen.

arguments:a0array length optional

a1double pointer to string array pointer to array of
addresses that point to the first characters of each
string in array

returns:na

strtointarray

Converts array of ASCII strings to array of integers in same order as
input array. Strings will be in the following format: 0xABCDEF00

i.e zero, lowercase x, followed by 8 hexadecimal digits, with AF
capitalized

arguments:a0array length optional

a1double pointer to string array pointer to array of
addresses that point to the first characters of each
string in array

a2pointer to integer array

returns:na

strtoint

Converts ASCII string to integer. Strings will be in the following
format: 0xABCDEF00

i.e zero, lowercase x, followed by 8 hexadecimal digits, capitalizing
AF.

argument: a0pointer to first character of ASCII string

returns:v0integer conversion of input string

sortarray

Sorts an array of integers in ascending numerical order, with the
minimum value at the lowest memory address. Assume integers are in
32bit twos complement notation.

arguments:a0array length optional
a1pointer to first element of array

returns:v0minimum element in array
v1maximum element in array

printdecimalarray

Prints integer input array in decimal, with spaces in between each
element.

arguments:a0array length optional
a1pointer to first element of array

returns:na

printdecimal

Prints integer in decimal representation using only syscalls 4 and 11.

arguments:a0integer to print

returns:na

exitprogram given

Exits program.

arguments:na

returns:na

Optional Subroutines
These are suggested nested subroutines that you might want to implement in your program. You will not be graded on the functionality of these subroutines and it is not necessary to follow this format. You are welcome to add additional subroutines as you see fit.

getarraylength optional

Determines number of elements in array.

argument: a0double pointer to string array pointer to array of
addresses that point to the first characters of each
string in array

returns:v0array length

savetointarray optional

Saves a 32bit value to a specific index in an integer array

argument: a0value to save
a1address of int array
a2index to save to

returns:na

Subroutine Printed Output Examples
mainfunctionlab519q4face12
This subroutine prints the headers along with the input string array and output integer array.

Input string array
0xFFFFFFFC 0x00000010 0x00000008

Sorted integer array
4 8 16
printstrarray
Only the ASCII strings, separated by spaces in the order they appear in the test case are printed to the screen. No header is printed.
0xFFFFFFFC 0x00000010 0x00000008
strtointarray
no printed output
strtoint
no printed output
sortarray
no printed output
printdecimalarray
The decimal values are printed with 1 space in between each value. No header is printed.
4 8 16
printdecimal
Only one decimal value is printed to the screen.
4
Turn Off Delayed Branching
Make sure delayed branching is turned off. See the appendix for more information.
MIPS Memory Configuration
Your program must run in the default memory configuration. See the appendix for more information.
Automation
Note that our grading script is automated, so it is imperative that your programs output matches the specification exactly. Output that deviates from the spec will cause point deduction.
Lab5.asm must assemble on its own, AND with the test file for any credit for subroutines.
Extra Credit
Modify your code to accept any number of ASCII string inputs.
Testing
Your program must work properly with the test program provided lab5test19q4face12.asm.
For grading, each subroutine will be tested individually; your subroutines must function in isolation.
Lab5.asm must assemble on its own, AND with the test file for any credit for subroutines.
Macros
You are not required to use macros, but you might find that they will help expedite your coding. It might help to spend some time studying the macros that are implemented in the template and the test file.
Submission
This assignment will be submitted in two parts. Late hours will not be used for any part of this assignment.
Part A: Subroutine Implementation for printstrarray, strtoint, printdecimal
Lab5.asm
This file should contain the implementation of the functions printstrarray, strtoint, and printdecimal. You will not be penalized if your program has additional functionality, but your .asm file must assemble for credit. Note that we pull the last commit before the deadline.
Part B: Complete Program Functionality, README, Google Form
Lab5.asm
This file should contain all subroutine implementations.
README.txt
Instructions for the README can be found here.
Google Form
You are required to answer questions about the lab in this Google Form. Question answers, excluding the ones asking about resources used and collaboration should total at the very least 150 words.
https:forms.gle7N9xbW5SEZPA6E997
Note
You are not required to submit pseudocode or a block diagram for this assignment.
A Note About Academic Integrity
Please review the syllabus on acceptable and unacceptable collaboration.
Grading Rubric TBA
Each subroutine will be graded individually. In addition to testing the specified functionality, we will test to ensure that each subroutine will preserve s register values.
Lab5.asm must assemble on its own, AND with the test file for any credit for subroutines.

Appendix
Turn Off Delayed Branching
Make sure delayed branching is turned off. From the settings menu, make sure Delayed branching is unchecked
Checking this option will insert a delay slot which makes the next instruction after a branch execute, no matter the outcome of the branch. To avoid having your program behave in unpredictable ways, make sure Delayed branching is turned OFF. In addition, add a NOP instruction after each branch instruction. The NOP instruction guarantees that your program will function properly even if you forgot to turn off delayed branching. For example:
LI t1 2LOOP: NOPADDI t0 t0 1BLTt0 t1 LOOPNOPnop added after the branch instructionADDt3 t5 t6

MIPS Memory Configuration
The test file file will only run in the default memory configuration as discovered by your instructor.
Do not hardcode any memory addresses in your program. Make sure to test your program thoroughly using the Default memory configuration.

What does it mean to hardcode an address?
Lets say after compiling our program, we discover that the address of the first character of the first program argument is 0x00003ff2 as shown below.

With this knowledge, we could access the first character of the first program argument like this:
li t1 0x00003ff2
lb t2 t1
However, in this code snippet, we are hardcoding the address to t1. However, its possible that when this code is run on a different machine, the program argument could be assigned to a different memory location and the code may not work.

Test File Sample Output

testing getarraylength

s0 before getarraylength: 0xc0ffeeee
s1 before getarraylength: 0xc0ffeeee
s2 before getarraylength: 0xc0ffeeee
s3 before getarraylength: 0xc0ffeeee
s4 before getarraylength: 0x7fffefe8
s5 before getarraylength: 0xc0ffeeee
s6 before getarraylength: 0xc0ffeeee
s7 before getarraylength: 0xc0ffeeee

entering subroutine…

getarraylength return values

array length, v0: 5

s0 after getarraylength: 0xc0ffeeee
s1 after getarraylength: 0xc0ffeeee
s2 after getarraylength: 0xc0ffeeee
s3 after getarraylength: 0xc0ffeeee
s4 after getarraylength: 0x7fffefe8
s5 after getarraylength: 0xc0ffeeee
s6 after getarraylength: 0xc0ffeeee
s7 after getarraylength: 0xc0ffeeee

testing printstrarray

s0 before printstrarray: 0xc0ffeeee
s1 before printstrarray: 0xc0ffeeee
s2 before printstrarray: 0xc0ffeeee
s3 before printstrarray: 0xc0ffeeee
s4 before printstrarray: 0x7fffefe8
s5 before printstrarray: 0xc0ffeeee
s6 before printstrarray: 0xc0ffeeee
s7 before printstrarray: 0xc0ffeeee

Printed output from subroutine will appear between
the following horizontal lines.

0x00000000 0xFFFFFFF8 0XFFFFFFFC 0x00000010 0x00000008

s0 after printstrarray: 0xc0ffeeee
s1 after printstrarray: 0xc0ffeeee
s2 after printstrarray: 0xc0ffeeee
s3 after printstrarray: 0xc0ffeeee
s4 after printstrarray: 0x7fffefe8
s5 after printstrarray: 0xc0ffeeee
s6 after printstrarray: 0xc0ffeeee
s7 after printstrarray: 0xc0ffeeee

testing strtoint

s0 before strtoint: 0xc0ffeeee
s1 before strtoint: 0xc0ffeeee
s2 before strtoint: 0xc0ffeeee
s3 before strtoint: 0xc0ffeeee
s4 before strtoint: 0x7fffefe8
s5 before strtoint: 0xc0ffeeee
s6 before strtoint: 0xc0ffeeee
s7 before strtoint: 0xc0ffeeee

strtoint input value

a0: 0xFFFFFFFF

entering subroutine…

strtoint return values

integer output, v0: 0xffffffff

s0 after strtoint: 0xc0ffeeee
s1 after strtoint: 0xc0ffeeee
s2 after strtoint: 0xc0ffeeee
s3 after strtoint: 0xc0ffeeee
s4 after strtoint: 0x7fffefe8
s5 after strtoint: 0xc0ffeeee
s6 after strtoint: 0xc0ffeeee
s7 after strtoint: 0xc0ffeeee

testing strtointarray

s0 before strtointarray: 0x00000005
s1 before strtointarray: 0xc0ffeeee
s2 before strtointarray: 0x10010024
s3 before strtointarray: 0xc0ffeeee
s4 before strtointarray: 0x7fffefe8
s5 before strtointarray: 0xc0ffeeee
s6 before strtointarray: 0xc0ffeeee
s7 before strtointarray: 0xc0ffeeee

int array contents before strtointarray

0x00000000
0x00000000
0x00000000
0x00000000
0x00000000

entering subroutine…

int array contents after strtointarray

0x00000000
0xfffffff8
0xfffffffc
0x00000010
0x00000008

s0 after strtointarray: 0x00000005
s1 after strtointarray: 0xc0ffeeee
s2 after strtointarray: 0x10010024
s3 after strtointarray: 0xc0ffeeee
s4 after strtointarray: 0x7fffefe8
s5 after strtointarray: 0xc0ffeeee
s6 after strtointarray: 0xc0ffeeee
s7 after strtointarray: 0xc0ffeeee

testing sortarray

s0 before sortarray: 0x00000003
s1 before sortarray: 0x1001102c
s2 before sortarray: 0x10010024
s3 before sortarray: 0xc0ffeeee
s4 before sortarray: 0x7fffefe8
s5 before sortarray: 0xc0ffeeee
s6 before sortarray: 0xc0ffeeee
s7 before sortarray: 0xc0ffeeee

int array contents before sortarray

0xffffffff
0xfffffffc
0x00000000

entering subroutine…

sortarray return values

min element, v0: 0xfffffffc
max element, v1: 0x00000000

int array contents after sortarray

0xfffffffc
0xffffffff
0x00000000

s0 after sortarray: 0x00000003
s1 after sortarray: 0x1001102c
s2 after sortarray: 0x10010024
s3 after sortarray: 0xc0ffeeee
s4 after sortarray: 0x7fffefe8
s5 after sortarray: 0xc0ffeeee
s6 after sortarray: 0xc0ffeeee
s7 after sortarray: 0xc0ffeeee

testing printdecimal

s0 before printdecimal: 0x00000003
s1 before printdecimal: 0x1001102c
s2 before printdecimal: 0x10010024
s3 before printdecimal: 0xc0ffeeee
s4 before printdecimal: 0x7fffefe8
s5 before printdecimal: 0xc0ffeeee
s6 before printdecimal: 0xc0ffeeee
s7 before printdecimal: 0xc0ffeeee

printdecimal input value

a0: 0x00000040

Printed output from subroutine will appear between
the following horizontal lines.

64

s0 after printdecimal: 0x00000003
s1 after printdecimal: 0x1001102c
s2 after printdecimal: 0x10010024
s3 after printdecimal: 0xc0ffeeee
s4 after printdecimal: 0x7fffefe8
s5 after printdecimal: 0xc0ffeeee
s6 after printdecimal: 0xc0ffeeee
s7 after printdecimal: 0xc0ffeeee

testing printdecimalarray

s0 before printdecimalarray: 0x00000004
s1 before printdecimalarray: 0x10011854
s2 before printdecimalarray: 0x10010024
s3 before printdecimalarray: 0xc0ffeeee
s4 before printdecimalarray: 0x7fffefe8
s5 before printdecimalarray: 0xc0ffeeee
s6 before printdecimalarray: 0xc0ffeeee
s7 before printdecimalarray: 0xc0ffeeee

int array contents before printdecimalarray

0xfffffffc
0xffffffff
0x00000002
0x00000003

Printed output from subroutine will appear between
the following horizontal lines.

4 1 2 3

int array contents after printdecimalarray

0xfffffffc
0xffffffff
0x00000002
0x00000003

s0 after printdecimalarray: 0x00000004
s1 after printdecimalarray: 0x10011854
s2 after printdecimalarray: 0x10010024
s3 after printdecimalarray: 0xc0ffeeee
s4 after printdecimalarray: 0x7fffefe8
s5 after printdecimalarray: 0xc0ffeeee
s6 after printdecimalarray: 0xc0ffeeee
s7 after printdecimalarray: 0xc0ffeeee

testing mainfunctionlab519q4face12

s0 before mainfunctionlab519q4face12: 0x00000004
s1 before mainfunctionlab519q4face12: 0x10011854
s2 before mainfunctionlab519q4face12: 0x10010024
s3 before mainfunctionlab519q4face12: 0xc0ffeeee
s4 before mainfunctionlab519q4face12: 0x7fffefe8
s5 before mainfunctionlab519q4face12: 0xc0ffeeee
s6 before mainfunctionlab519q4face12: 0xc0ffeeee
s7 before mainfunctionlab519q4face12: 0xc0ffeeee

int array contents before mainfunctionlab519q4face12

0x00000000
0x00000000
0x00000000
0x00000000
0x00000000

Printed output from subroutine will appear between
the following horizontal lines.

Input string array
0x00000000 0xFFFFFFF8 0XFFFFFFFC 0x00000010 0x00000008

Sorted integer array
8 4 0 8 16

int array contents after mainfunctionlab519q4face12

0xfffffff8
0xfffffffc
0x00000000
0x00000008
0x00000010

s0 after mainfunctionlab519q4face12: 0x00000004
s1 after mainfunctionlab519q4face12: 0x10011854
s2 after mainfunctionlab519q4face12: 0x10010024
s3 after mainfunctionlab519q4face12: 0xc0ffeeee
s4 after mainfunctionlab519q4face12: 0x7fffefe8
s5 after mainfunctionlab519q4face12: 0xc0ffeeee
s6 after mainfunctionlab519q4face12: 0xc0ffeeee
s7 after mainfunctionlab519q4face12: 0xc0ffeeee

program is finished running

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 代写 MIPS assembly Lab 5: Subroutines
30 $