Question

In: Computer Science

IN MIPS!!! Question: Change this program to use XOR and ADD and take out XORI and...

IN MIPS!!! Question: Change this program to use XOR and ADD and take out XORI and ADDI.

data
   str1:   .asciiz "Enter a number you want to negate: "
   str2:   .asciiz "Your answer in Decimal is :"
   str3:   .asciiz "\nAnswer in Hex format: "
  
.text

   la $a0, str1
   li $v0, 4
   syscall
  
   li $v0, 5
   syscall
   move $t0, $v0
  
   xori $t0, 0xffffffff
   addi $t0, $t0, 1
  
   la $a0, str2
   li $v0, 4
   syscall
  
   move $a0, $t0
   li $v0, 1
   syscall
  
   la $a0, str3
   li $v0, 4
   syscall
  
   move $a0, $t0
   li $v0, 34
   syscall
  
   # exit program
   li $v0, 10
   syscall

Solutions

Expert Solution

Please up vote ,comment if any query . Thanks for Question .Be safe .

Note : check attached image for output ,code compiled and tested in MARS MIPS simulator .

Program Plan :

  1. to replace xori with xor first load immediate value 0xfffffff into $t1
  2. than use xor instruction
  3. same for addi store immediate 1 into $t1 and use
  4. add instruction .

Program :

.data
   #this program takes a decimal number and convert it into negative
   #and print hex representation of negative number
   #string declaration

   str1:   .asciiz "Enter a number you want to negate: "
   str2:   .asciiz "Your answer in Decimal is :"
   str3:   .asciiz "\nAnswer in Hex format: "

#code section
.text

   #print str1 string to prompt user to enter number
   la $a0, str1
   li $v0, 4 #syscall 4 to print integer
   syscall

   li $v0, 5 #read input from user
   syscall   #syscall 5 to read input
   move $t0, $v0 #store user input in $t0 from $v0
  
   #xori $t0, 0xffffffff
   li $t1,0xffffffff #first load 0xffffffff into $t0 $t1=0xffffffff
   xor $t0,$t0,$t1    #xor $t0 with $t1 and store in $t0 $t0=$t0^$t1

   li $t1,1 #load 1 in $t1 =1

    #t0=$t0+$t1
   add $t0, $t0, $t1 #add t1 into $t0= $t0+$t1

   #print str2 on console
   la $a0, str2
   li $v0, 4 #syscall 4 to print string
   syscall

   #move value of $t0 into $a0 to print it
   move $a0, $t0
   li $v0, 1 #syscall 1 to print integer
   syscall

   #print str3 on console
   la $a0, str3
   li $v0, 4 #syscall 4 to print string
   syscall

   #move integer value(negative) into $a0
   move $a0, $t0
   li $v0, 34 #syscall 34 to print hex repesentation
   syscall

   # exit program
   li $v0, 10 #syscall 10 to terminate program
   syscall

Output :

Please up vote ,comment if any query . i will reply and will make change.


Related Solutions

MIPS Program I'm trying to write a program that will take in two numbers from the...
MIPS Program I'm trying to write a program that will take in two numbers from the user and output the sum at the end. However, I keep getting very wrong answers. For example, I add 2 and 2 and get 268501000. Help would be appreciated. .data #starts data use userIn1:    .word 4 #sets aside space for input    userIn2:    .word 4 #sets aside space for input total:    .word 4 #sets space aside for input    request:   ...
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
How do I write a program in MIPS that will change all the characters in a...
How do I write a program in MIPS that will change all the characters in a string into lowercase. For instance: string: " CANBERRA AUSTRALIA" Output: "canberra australia"
Write a MIPS assembly program that reads 3 add them together and stores the answer in...
Write a MIPS assembly program that reads 3 add them together and stores the answer in memory.
I have to do the following MIPS coding assignment. Question 1 Write a MIPS program that...
I have to do the following MIPS coding assignment. Question 1 Write a MIPS program that meets the following requirements (NOTE: your program statements should follow the order of the requirements and each requirement should correspond to only one assembly instruction): Loads the hexadecimal equivalent of 23710 into register 13 using an immediate bitwise OR instruction Loads the hexadecimal equivalent of 183410 into register 17 using an immediate bitwise OR instruction Performs the bitwise AND operation on the operands stored...
How can I write a simple MIPS program to print out the following elements of an...
How can I write a simple MIPS program to print out the following elements of an array of the size of 10: 5,10,15,20,25,30,35,40,45,50
Use MIPS write an assembly program which asks the user to enter 3 number. The program...
Use MIPS write an assembly program which asks the user to enter 3 number. The program then sorts these numbers, the prints them from largest to smallest.
Use MIPS assembly language program to swap two of the integers in an integer array. The...
Use 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. The main function should: • Pass the starting address of the array in $a0. • Pass the indices of the two elements to swap in $a1 and $a2. • Preserve (i.e. push onto the stack) any T registers that it uses. • Call the Swap...
This is a java program I am trying to figure out how to add a couple...
This is a java program I am trying to figure out how to add a couple methods to a program I am working on. I need to be able to: 1. Remove elements from a binary tree 2. Print them in breadth first order Any help would appreciated. //start BinaryTree class /** * * @author Reilly * @param <E> */ public class BinaryTree { TreeNode root = null; TreeNode current, parent; private int size = 0, counter = 0; public...
python please take it out from class and make it all functions, add subtraction and multiplication...
python please take it out from class and make it all functions, add subtraction and multiplication functions with it. than you so much for helping me out. import random image = 'w' class cal(): def __init__(self, a, b): self.a = a self.b = b def add(self): return self.a + self.b a = random.randint(0, 9) b = random.randint(0, 9) obj = cal(a, b) print("0. Exit") print("1. Add") choice = int(input("Enter choice: ")) cnt = 0 # To hold number of tries...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT