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

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"
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 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...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function....
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function. The program should ask for a user's input and print the length of the user's input. Write the main function to call strlen. The main function should: - Prompt the user for input - Pass that input to strlen using registers $a0. - Preserve (i.e. push onto the stack) any T registers that the main function uses. The strlen function should: - Preserve any...
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...
Do Not Use Pseudo Insturctions or li la instructions, etc... Write and test a MIPS program...
Do Not Use Pseudo Insturctions or li la instructions, etc... Write and test a MIPS program consisting of four functions. In the following descriptions, the symbol & means “address of”. void main(): The main function must 1) print your name 2) call the readData function 3) call count function 4) complete the program. The main function must set up all parameters before calling each of the functions. int readData (&array): The starting address of an array is passed to the...
(Make sure in Mips!!!) Use the correct “syscall” to create MIPS programs for the following. !!!...
(Make sure in Mips!!!) Use the correct “syscall” to create MIPS programs for the following. !!! please use comments and ALWAYS use the correct syscall program code to end the program. !!! 1) Write a program in MIPS which asks the user to enter their favorite type of pie. The program should then print out "So you like _____ pie", where the blank line is replaced by the pie type entered. ALSO: What annoying feature of syscall service 4 makes...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT