For Exercises 1-4, Use the MARS simulator to write and execute MIPS assembly cod
ID: 3793397 • Letter: F
Question
For Exercises 1-4, Use the MARS simulator to write and execute MIPS assembly code that will perform the high level language pseudocode.
# Do this in a single program source file. Use comments to clearly indicate which assembly instructions correspond to each exercise and
# separate each exercise by a line of blank space. Use temporary storage registers as appropriate for more complex operations.
####################################################################################################################################
#Only use the following instructions: add, addi, sub, and, or, nor, slt, sll, srl, lb, lh, lw, sll, srl, beq, bne, j
#Do All of exercises 1-4 sequentially in a single source file. Once each exercise has been completed with code comments,
# copy the contents of your mips assembly source file to a file named mipsasm2.txt and upload to the beachboard dropbox named MIPS Asm 2
####################################################################################################################################
.data
arrayb: .byte 0, 0, 0, 0
arrayh: .half 30, 7, 14, 5, 12
arrayw: .word 123, 249, 327, 445, 971, 323, 232
.text
####################################################################################################################################
#Exercise 1: Put arrayh elements in ascending order using only addi, load, and store instructions
####################################################################################################################################
#Exercise 2: After Exercise 1 is complete, write a loop to traverse arrayh, calculate the difference between
# each pair of arrayh elements and store each difference in arrayb
#HINT: for(i = 0; i < 5; i++) arrayb[i] = arrayh[i+1] - arrayh[i];
####################################################################################################################################
#Exercise 3: Use a loop to do linear search on arrayh for the value 0x1E. Put the array index number of where the value was found into into arrayw[5]
####################################################################################################################################
#Exercise 4: Use a while loop type of instruction sequence to count the consecutive number of odd values starting at the beginning of arrayw
Explanation / Answer
#Exercise 1:
arrayb: .byte 0, 0, 0, 0
arrayh: .half 30, 7, 14, 5, 12
arrayw: .word 123, 249, 327, 445, 971, 323, 232
.text
Exercise 2:
Arrays As you know from lecture, an array is a data structure that holds a fixed number of elements of a certain type. When you initialize an array, you specify both its size and the type of element it stores. Arrays can be one-dimensional or multidimensional (a 2-dimensional array is just an array of arrays). int[] numbers = new int[10]; // initializes 1D int array of size 10 HeadTA[] headtas = new HeadTA[4]; // 1D array of HeadTAs (size 4) Square[][] chessBoard = new Square[8][8]; // 2D array of Squares
Looping Through Arrays In Java, when we initialize an array, each of its elements is initialized to the default value of the array’s element type. This means that when you initialize an array of ints with “int[] numbers = new int[10]; ”, each element starts out as 0. When you initialize an array of booleans, each element starts out as false. When you initialize an array of objects, each element starts out as null. Loops are a useful tool for navigating arrays. One use case is populating an array with the values we want to store. Here’s a short code example that creates a 1-dimensional array of booleans and uses a for loop to set each element. boolean[] myBoolArray = new boolean[5]; // declare, initialize array for (int i = 0; i < myBoolArray.length; i++) { // for all array’s indices: myBoolArray[i] = true; // set element at current index to true
Exercise 3:
task is to consider a number of exams for a class of students The score for each exam is to be weighted dierently to compute the nal score and grade For example the rst exam may contribute of the nal score the second may contribute and the third contribute We must compute a weighted average of the scores for each student The sum of the weights for all the exams must add up to ie Here is our task WTDAVG Read the exam scores from a le for several exams for a class of students Read the percent weight for each of the exams Compute the weighted average score for each student Also compute the averages of the scores for each exam and for the weighted average scores We can think of the exam scores and the weighted average score for a single student as a data record and and represent it as a row of information The data records for a number of students then is a table of such rows Here is our conceptual view of this collection of data exam exam exam weighted avg student student
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.