Question

(MIPS Assembly language) Ask user for two decimal numbers and save to memory (not registers). Multiply...

(MIPS Assembly language)

Ask user for two decimal numbers and save to memory (not registers). Multiply these two numbers using adding and shifting only, not the "mul" instruction and print the product to the user as both a base-10 and base-32 (again, no using div/mul/rem). Save the output to a txt file. The program should run 5 times, with no user input needed to continue the program.    

Homework Answers

Answer #1

Program:

.data
textout:.asciiz "please enter 2 numbers "
textout1:.asciiz "The product of the numbers in base10 is: "
textout2:.asciiz "\nThe product of the numbers in base32 is: "
.text
main:
   li $s2,0 #result initialized too zero
  
   la $a0 textout #print prompt string
   li $v0 4
   syscall
  
   li $v0 5
   syscall
   move $s0,$v0
  
   li $v0 5
   syscall
   move $s1,$v0
   j multiply
  
multiply: beqz $s1,end
   andi $t1,$s1,1
   beqz $t1,add_s
   add $s2,$s2,$s0
add_s:   sll $s0,$s0,1
   srl $s1,$s1,1
   j multiply
  
end:   la $a0 textout1
   li $v0 4
   syscall
  
   move $a0,$s2   #print result
   li $v0,1
   syscall  
  
   la $a0 textout2
   li $v0 4
   syscall
  
   move $a0,$s2   #print result
   li $v0,36
   syscall  
  

Output:

Know the answer?
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
Similar Questions
Write a MIPS assembly language procedure that simulates/implements the multiplication of two unsigned integers. The procedure...
Write a MIPS assembly language procedure that simulates/implements the multiplication of two unsigned integers. The procedure receives the mulitiplicand and the multiplier and returns the product. IT CANNOT USE A MULTIPLY INSTRUCTION! Write a MIPS assembly language program that demonstrates your multiplication procedure. Your program should ask the user for two integers to multiply. You can assume that the input integers are positive. Adhere to the procedure call convention.
Use MARS to write and simulate a MIPS assembly language program to swap two of the...
Use MARS to write and simulate a MIPS assembly language program to swap two of the integers in an integer array. The program should include the Swap function to swap the integers and the main function to call the Swap function. Download the template file “P4_template.asm” provided on Blackboard. Add your code to this file. Do not modify any of the code provided in the file. The main function should: • Pass the starting address of the array in $a0....
Assembly Programming in MIPS Write a program in MIPS assembler that performs the following computations: Prompts...
Assembly Programming in MIPS Write a program in MIPS assembler that performs the following computations: Prompts the user to enter two integers and stores the smaller one in the first data memory word (with the lowest address) and the larger one in the second data memory word. Then divides the larger word by the smaller one in integer and stores the integer quotient in the third data memory word and the remainder in the fourth data memory word. Finally, it...
IN MIPS ASSEMBLY Macro File: Create macros to print an int, print a char, print a...
IN MIPS ASSEMBLY Macro File: Create macros to print an int, print a char, print a string, get a string from the user, open file, close file, read file, and allocate heap memory. You can use more macros than these if you like. Main Program File: Allocate 1024 bytes of dynamic memory and save the pointer to the area. The main program is a loop in which you ask the user for a filename. If they enter nothing for the...
Using MIPS Assembly language, sort 3 integers from greatest to smallest. Do this without using an...
Using MIPS Assembly language, sort 3 integers from greatest to smallest. Do this without using an array and instead use conditional branches, using the algorithm below: 1. Get Numbers From User 2.IF(#1 < #2) Swap the two numbers 3.IF(#2 < #3) Swap the two numbers 4.IF(#1 < #3) Swap the two numbers 5. Display Numbers in from greatest to smallest 6. End Program I have not been able to figure out the transfer of control when using branches and am...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Section 2: Using the MARS or SPIM simulator develop a program that will implement the following...
Section 2: Using the MARS or SPIM simulator develop a program that will implement the following conditional statement. If ( n is even) { n = n / 2; } else { n = 3 * n + 1; } In this case, n is to be input by the user (assume they input a non-negative value), the conditional is performed, and the resulting n is to be output. Again, use the system calls for input, output, and exiting the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT