Question

Mars Assignment Procedures Consider the ordering of the nibbles in a word as shown below Write procedures to do the followingTest putNibble: 100 into nibble 4 of $s0 a0 has $s0 Sa1 has 100 in nibble Sa0032 45 12 -10 0 100 0 $a2-4 32 45 100 12 -10 swa

Mars Assignment Procedures Consider the ordering of the nibbles in a word as shown below Write procedures to do the following A procedure named getNibble that has two parameters $a0 is a word value and $a1 is a nibble number (per the diagram above). This procedure should return in $v0 the nibble in Sa0 selected by Sa1. The retrieved nibble should be placed in nibble 0 of Svo 1) A procedure named putNibble that has two parameters $a0 is a word value, Sal is a "nibble value" (word with 0 in nibbles 1-7 and the desired nibble in nibble 0) and Sa2 is a nibble number (per 2) the diagram above). This procedure should put nibble O in $a1 into the word contained in $a0. The procedure will return the result value in $vO 3) A procedure named swapNibble that has three parameters: Sa0 is a word value, Sa1 and Sa2 are two nibble positions. The proc indicated positions swapped. When writing swapNibbles use the procedures ge putNibble,_this is a forced requirement even if you found a wa using getNibbles and putNibbles, Return the result in ŚvO edure will return the original value with the nibbles in the tNibble and erform the task without now write code to test the routines. Later you will be given additional instructions to use the procedures. Suppose $s0 has these values 32 45 2 7 12 -10 4 0 Test getnibble: Get the 6th nibble in Moving $s0 to $a0 and placing 6 into Sal, getNibble would return the 6h nibble in $ao in SvO as shown. 0 0 45 2
Test putNibble: 100 into nibble 4 of $s0 a0 has $s0 Sa1 has 100 in nibble Sa0032 45 12 -10 0 100 0 $a2-4 32 45 100 12 -10 swapNibbles: Swap nibbles 6 and 2 in SsO Suppose $s0 has these values 32 45 2 12 -10 Moving $s0 to $a0 and placing 6 into $a1 and 2 into Sa2 (order of $a1 and $a2 does not matter), swapNibbles would return the value below in $vio 32 12 45 -10
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot

Edlt Execute rogras starts esat nord i 50 Hore to eGet iadez in 42 l petHile 19 0eet 1ime Line: 117 Column: 11Show Line Numbe-----------------------------------------------------------------------

Program

#Create a word
.data
   Word: .byte -10 4 -5 12 7 2 45 32
   putWord: .byte 100 0 0 0 0 0 0 0
#Program starts here
.text
    #Get word in s0
    la $s0,Word
    #Move to a0
    add $a0,$0,$s0
    #Get index in a1
    addi $a1,$0,6
    #Call function, return value at index 6
    jal getNibble
    #Display nibble
    add $a0,$0,$v0
    addi $v0,$0,1
    syscall
    #Get line feed
    li $v0,11
    addi $a0,$0,10
    syscall
    #Check to put nibble
    #Get s0 into a0
    add $a0,$0,$s0
    #Get put nibble word in a1
    la $a1,putWord
    #nibble index in a2
    addi $a2,$0,4
    #Call function, return word in v0
    jal putNibble
    #Display word
    move $t0,$v0
    addi $t1,$0,0
loop:
     beq $t1,8,next
     li $v0,1
     lb $a0,7($t0)
     syscall
     li $v0,11
     addi $a0,$0,32
     syscall
     addi $t1,$t1,1
     addi $t0,$t0,-1
     j loop
next:
    #Get line feed
    li $v0,11
    addi $a0,$0,10
    syscall
    #Move word to a0 for swap
    add $a0,$0,$s0
    #Swap indexes
    addi $a1,$0,2
    addi $a2,$0,6
    #Call method
    jal swap
    #Display word
    move $t0,$v0
    addi $t1,$0,0
   #After swap
   after:
     beq $t1,8,end
     li $v0,1
     lb $a0,7($t0)
     syscall
     li $v0,11
     addi $a0,$0,32
     syscall
     addi $t1,$t1,1
     addi $t0,$t0,-1
     j after
    #End of the program
end:
    li $v0,10
    syscall
#Function to get specified nibble value
getNibble:
    #Get specified nibble index
    add $a0,$a0,$a1
    #Get nibble
    lb $v0,($a0)
    #Return
    jr $ra
#function to put value into specified nibble
putNibble:
    #Store word in t1
    move $t1,$a0
    #Get specified nibble index
    add $a0,$a0,$a2
    #Get value to put
    lb $a1,0($a1)
    #Put value
    sb $a1,($a0)
    #get word in v0
    add $v0,$0,$t1
    #Return
    jr $ra
#Function to swap nobbles
swap:
#Store word
   add $t1,$0,$a0
   #Get first index value
   add $a0,$a0,$a1
   lb $t0,($a0)
   #Get second index nibble
   add $a0,$0,$t1
   add $a0,$a0,$a2
   lb $t2,($a0)
   #Store first nibble into second index
   sb $t0,($a0)
   #Store second nibble into first index
   add $a0,$0,$t1
   add $a0,$a0,$a1
   sb $t2,($a0)
   add $v0,$0,$t1
   #Return
   jr $ra

----------------------------------------

Output

45
32 45 2 100 12 -5 4 -10
32 -5 2 100 12 45 4 -10
-- program is finished running --

Add a comment
Know the answer?
Add Answer to:
Mars Assignment Procedures Consider the ordering of the nibbles in a word as shown below Write pr...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

  • == Programming Assignment == For this assignment you will write a program that controls a set...

    == Programming Assignment == For this assignment you will write a program that controls a set of rovers and sends them commands to navigate on the Martian surface where they take samples. Each rover performs several missions and each mission follows the same sequence: deploy, perform one or more moves and scans, then return to base and report the results. While on a mission each rover needs to remember the scan results, in the same order as they were taken,...

  • Instructions: Below are both crater images (some of the work is already done for you on...

    Instructions: Below are both crater images (some of the work is already done for you on the Southern image). At the bottom left you will see scale bars and a set of circles to help you do the actual counting. We have already identified craters that are 8 km across with red dots, so you only need to worry about craters greater than the outlined ones. Do not recount those craters that have already been marked with red dots. To...

  • Need help with C++ assignment Assignment 1 and .txt files are provided at the bottom. PART...

    Need help with C++ assignment Assignment 1 and .txt files are provided at the bottom. PART A PART B Assignment 1 #include <iostream> #include <string> #include <fstream> #include <iomanip> #include <stdio.h> #include <ctype.h> #include <string.h> #include <algorithm> using namespace std; /** This structure is to store the date and it has three integer fields **/ struct Date{    int day;    int month;    int year; }; /** This structure is to store the size of the box and it...

  • Assignment Predator / Prey Objectives Reading from and writing to text files Implementing mathematical formulas in...

    Assignment Predator / Prey Objectives Reading from and writing to text files Implementing mathematical formulas in C++ Implementing classes Using vectors Using command line arguments Modifying previously written code Tasks For this project, you will implement a simulation for predicting the future populations for a group of animals that we’ll call prey and their predators. Given the rate at which prey births exceed natural deaths, the rate of predation, the rate at which predator deaths exceeds births without a food...

  • Part B. Gross Income Inclusions & Exclusions For each Q-6 through Q-19 below, determine whether the...

    Part B. Gross Income Inclusions & Exclusions For each Q-6 through Q-19 below, determine whether the item described should be INCLUDED IN or EXCLUDED FROM the Gross Income of the taxpayer who receives the item. • Darken Box A on the Scantron sheet if the item should be INCLUDED IN gross income • Darken Box B on the Scantron sheet if the item should be EXCLUDED FROM gross income 6. $25,000 scholarship for tuition and books received by a full-time...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT