Question

In: Computer Science

make multiply function with ‘add’ command, Convert to mips code Don’t use ‘mult’ Use 'add' multiple...

make multiply function with ‘add’ command,

Convert to mips code

Don’t use ‘mult’

Use 'add' multiple times

Get input from key-board and display the result in the console window

Solutions

Expert Solution

.data
prompt1: .asciiz "Please enter the first signed (decimal) integer: "
prompt2: .asciiz "Please enter the second signed (decimal) integer: "
result_msg: .asciiz "The result of these two 16-bit integers\' multiplication is: "
.text
.globl main
main:
li $v0, 4 #print prompt
la $a0, prompt1
syscall

li $v0, 5 #read multiplicand
syscall
move $s0, $v0

li $v0, 4 #print prompt
la $a0, prompt2
syscall

li $v0, 5 #read multiplier
syscall
move $s1, $v0

Mult: ori $t0,$zero,1 #mask
move $s3, $0 #initialize the result register
move $t1, $0


loop: beq $s1, $zero, end #if the multiplier is 0 then finished
and $t1, $t0, $s1 #mask
beq $t1, 1, mult_add   
beq $t1, 0, shift

mult_add: addu $s3, $s3, $s0 #add to get product

shift:
sll $s0, $s0, 1 #shift multiplicand left
srl $s1, $s1, 1 #shift multiplier right

j loop


result: #input the print_string
li $v0, 4
la $a0, result_msg
syscall


exit:
li $v0, 1 #input result
move $a0, $s3
syscall

li $v0, 10 #exit
syscall


Related Solutions

Convert in machine code for MIPS LW S5, 33(S2); Add R1, T3, S5; Sub T4, S3,...
Convert in machine code for MIPS LW S5, 33(S2); Add R1, T3, S5; Sub T4, S3, R3; SW T4, 124(T7);
convert following C++ code into MIPS assembly: int main() {                                 &
convert following C++ code into MIPS assembly: int main() {                                         int x[10], occur, count = 0;                                                              cout << "Type in array numbers:" << endl; for (int i=0; i<10; i++) // reading in integers                               { cin >> x[i];        } cout << "Type in occurrence value:" << endl;                                 cin >> occur;                                                 // Finding and printing out occurrence indexes in the array                                  cout << "Occurrences indices are:" <<...
Please convert this code written in Python to Java: import string import random #function to add...
Please convert this code written in Python to Java: import string import random #function to add letters def add_letters(number,phrase):    #variable to store encoded word    encode = ""       #for each letter in phrase    for s in phrase:        #adding each letter to encode        encode = encode + s        for i in range(number):            #adding specified number of random letters adding to encode            encode = encode +...
Write code in MIPS ,read tow number from the user that do the following: 1- multiply...
Write code in MIPS ,read tow number from the user that do the following: 1- multiply 2- Dividing 3- sum 4- average 5- minimum 6- maximum 7- print message to thank the user for using my program
MIPS ASSEMBLY : 1) Code in MIPS a function that allows to store the text entered...
MIPS ASSEMBLY : 1) Code in MIPS a function that allows to store the text entered by the user in a 300-byte buffer. The function must return the actual size of the entered text in number of bytes. The text could contain lines, that is to say that the symbol '\ n' could be present. The end of reading is defined by both consecutive '\ n' '\ n' symbols. 2) Code in MIPS a function that helps identify if the...
Convert the following code from awk to Perl: (please don't use a2p (awk to perl) command)...
Convert the following code from awk to Perl: (please don't use a2p (awk to perl) command) Here was the original problem: Calculate the grade for each student that appears in the data file. You may calculate the grade based on total earned points, divided by total possible points. Or, for 10 points extra credit; Use the weighted totals for this course; available in the syllabus and on the course home page. Output a list of students, their grade as a...
Convert the following C++ code into MIPS assembely. For testing I will be change the values...
Convert the following C++ code into MIPS assembely. For testing I will be change the values for q,y,x with few different values. //q -> $s0 //y -> $s1 //x -> $s2 int main(){ int q = 5; int y = 17; int x = 77; if ( q < 10){ cout << "inside if"; } elseif ( x > 0 || y < 10) { cout << "inside elseif"; } else { cout << "inside else"; } }
Convert the following to machine code and then back to MIPS instructions: 1) a. addi $s0,...
Convert the following to machine code and then back to MIPS instructions: 1) a. addi $s0, $zero, -15 b. slt $t0, $s0, $s1 c. beq $t0, $zero, LEEQ d. j GRT
Write a simple Java code to make a Binary Tree for the following tree: Don’t use...
Write a simple Java code to make a Binary Tree for the following tree: Don’t use serializable interface implantation /** Class to encapsulate a tree node. */ protected static class Node implements Serializable {
convert this code to Python and make sure you use chained map and filter as well....
convert this code to Python and make sure you use chained map and filter as well. https://book.pythontips.com/en/latest/map_filter.html CODE BELOW IS IN JAVASCRIPT let people = [ {name: "Amy", pounds_weight: 152, inches_height: 63}, {name: "Joe", pounds_weight: 120, inches_height: 64}, {name: "Tom", pounds_weight: 210, inches_height: 78}, {name: "Jim", pounds_weight: 180, inches_height: 68}, {name: "Jen", pounds_weight: 120, inches_height: 62}, {name: "Ann", pounds_weight: 252, inches_height: 63}, {name: "Ben", pounds_weight: 240, inches_height: 72}, ]; //functions to convert pounds to kg and inches to meters let...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT