assembly代做 | assignment | 作业mips – CS230 MIPS practice

CS230 MIPS practice

assembly代做 | assignment | 作业mips – 这道题目是利用assembly进行的编程代写任务, 涉及了assembly/mips等代写方面, 这个项目是assignment代写的代写题目

mips汇编代写 代写汇编 assembly

assignment 3

Coverage:Module 2

  • All questions are equally weighted.
  • Solutions will be automatically tested, so it is essential that they match the requirements exactly. This means in particular, you must adhere to the register restrictions and any labels that are specified.
  • All submissions are to be completed through MarkUs (https://markus.student.cs.uwaterloo.ca/markus_cs230_w/en/assignments)
  • The files submitted must be either plain text files with a.asmextension. When creating plain text files outside of Unix, choose a good simple editor. Programs like Microsoft Word are not a good choice for generating plain text files.
  • Read the policy described in Learn regarding late submissions.
  • Solutions for assignments will not be posted. Read the policy in Learn for more informa- tion.
  1. Write an assembly program that reads a string input from the keyboard, and outputs a substring. The program should read a single line of input in other words, read all characters typed until you enter a new line character. Assume the characters of the string are indexed starting at position 0. The newline character is not considered part of the input string. The output will be the characters of the input string from the index position found in register $1up to, but not including, the character at index position found in register$2. Use thetwointsfrontend to initialize the index values of the substring you are required to output. Your program should print a newline character following the substring. For example, if the user entered the values 4 and 7 in thetwointsfront end, and then used the keyboard to enter the stringcomputer science, the output would be:ute Notes:
  • If the value$1and$2are not valid index positions in the string that is entered, nothing should be printed and then the value in$3should be set to 1. Otherwise the value of$3should be 0. Valid index positions are 0$1$2length of the string.
  • The ASCII code value of a newline character is the hex number0xA.
  • For this question, there are no extra restrictions on the use of the registers.
Submit the filea3q1.asm.
  1. Assume that an array has been initialized with integers, where the array location is in register$1and the array length is in register$2. Write a program that calculates the sum of the numbers in that array that are strictly greater than the average of the numbers in that array. The sum you calculate must be placed in register$1. For example, if the array contains the values 2, 5, 8, -3, 1, then the result in register$1would be 13 , since 2, -3, and 1 are less than or equal to the average, and 5 and 8 are strictly greater than the average. If the size of the array is 0, then the total is 0. Notes: – Some marks for this question will be assigned to the use of registers. You must use as few registers as possible to receive full marks. – Most of the the tests will be on data with positive average. However, there will be at least one test where the average is less than 0.
Submit the filea3q2.asm.
  1. For this question, you will be submitting two separate files. However, you may choose to develop the solution in a single file, and divide the code into separate files before submitting the final versions. You should test the final versions of you solutions by concatenating the files before assembling them. Here is how you can do that inLinux: cat a3q3b.asm a3q3a.asm > a3q3.asm /u/cs230/pub/binasm < a3q3.asm > a3q3. mips The first command concatenates the two files from part b) and part a) into a single file (note the order of the files). The second command assembles the joint files. When we test your solution, we will providing our own versions of each part. In other words, when we test your part a), we will use our own version of part b) and vice versa. This means your solution for each part should not depend on any details of the other part. It is very important that the solutions for this question follow the register conventions described on slide 64 of Module 2.
(a) Recall the map function from CS115/135. This is an abstract list function that
consumes a function and a list and produces a list where each element has been
transformed by the function. For example(map sqr (1 2 3))produces the list
(1 4 9).
For this part, create a subroutine that is labelledmapthat has three arguments: the
address of a function that itself has one parameter, the address of the first element of
an array, and the size of the array. The subroutine will create a copy of the elements
of the array, where each element has been transformed by the function that was
provided. The copy should appear in the memory addresses immediately following
the original array. The subroutine should return the address of the first element of
the newly created array. For example, if themap subroutine is given the address
of a subroutine that will calculate the square of a number, and the address of an
array with values1, 2, 3and the size 3 , then the values1, 4, 9would appear in
memory locations immediately following1, 2, 3.
Note that this subroutine will be calling another subroutine. This means that it
is both a callee and acaller. The subroutine it calls has the right to change any
registers that are designated astemporary. So, if this is an issue, you should save the
important register values ofmapon the stack before calling another subroutine.
Submit the filea3q3a.asm.

(b) Write a program that uses themapsubroutine from part a) to create a new array of transformed integers. The program will use thearrayfront end, where the address of the first element is in register$1and the size of the array is in register$2. Assume that the array is filled with positive integers. The new array will contain integers that are the sum of the digits of the elements in the original array. The address of the new array should appear in register$2. The program must include a subroutine called sumdigits. This subroutine has a single argument that is a positive integer and returns an integer representing the sum of the digits. For example, if the subroutine is given the integer 123 , it will return the integer 6. The code for the subroutine should appear at the end of the file, after the instructionjr $31of the main program. The basic structure of this file will be:

;; Set up registers to call map subroutine
;; Call map subroutine
jr $
sumdigts:
;; Code for sumdigits subroutine
jr $
Note that this program should not work directly with the arrays. There will be
a severe loss of correctness marks for solutions of part b) that directly access the
elements of the arrays usinglwandsw.
Submit the filea3q3b.asm.