In: Computer Science
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
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 :
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.