Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 677 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mips: Computing the sum of two inputs

#1
It seems very simple but I think my program won't compile because I'm overwriting the $v0 register? Thanks in advance

UPDATE:nevermind got it, my order was wrong when I made the syscall for printing the sum...
fixed in case anyone needs reference.


.data
prompt1: .asciiz "\n\n Enter the first integer please:"
prompt2: .asciiz "Enter the second integer please:"
result: .asciiz "The result is:"

.text

main:

#t0-to hold first integer
#t1-to hold second integer
#t2- used to hold the sum of t$1 and t$2

#first number

li $v0, 4 #syscall to print string
la $a0, prompt1 #address of string to print
syscall

li $v0, 5 #syscall to read an integer
syscall
move $t0, $v0 #move the number to read into $t0

#second number
li $v0, 4
la $a0, prompt2
syscall

li $v0,5
syscall
move $t1,$v0

add $t2, $t1, $t0 #compute the sum

#print out sum of $t2
li $v0, 4 # load syscall print int into $v0
move $a0, $t2 #move the number to print into $a0
li, $v0,1
la, $a0, result
syscall


Done:

li $v0, 10 #syscall to exit
syscall
Reply

#2


.data
prompt1: .asciiz "\n\n Enter the first integer please:"
prompt2: .asciiz "Enter the second integer please:"
result: .asciiz "The result is:"

.text
main:
#t0-to hold first integer
#t1-to hold second integer
#t2- used to hold the sum of t$1 and t$2
#first number
li $v0, 4 #syscall to print string
la $a0, prompt1 #address of string to print
syscall
#
li $v0, 5 #syscall to read an integer
syscall
move $t0, $v0 #move the number to read into $t0
#second number
li $v0, 4
la $a0, prompt2
syscall
#
li $v0,5
syscall
move $t1,$v0
#
#print out sum of $t2
li $v0, 4
la $a0, result
syscall
#
add $a0, $t1, $t0 #compute the sum
li $v0, 1
syscall
#
li $v0, 10
syscall
Reply

#3
Actually you messed up in this section:

` #print out sum of $t2
li $v0, 4 # load syscall print int into $v0
move $a0, $t2 #move the number to print into $a0
li, $v0,1
la, $a0, result
syscall`

Lets do it line by line:
`li $v0, 4 #You are ready to indicate that you want to print string`
`la $a0, result #you have loaded the address of string now`
`syscall # Now you will see: "The result is: `

Now lets print the number
`li $v0, 1`
`move $a0, $t2`
`syscall`

Footnote: Everytime you indicate you will use syscall, you should complete that command first.
for example, if you want to print something, you must complete syscall for that set and then move on to print integer.

example:
Lets say we want to print something like this,.
Number : 1

MIPS code would be:
` .data
prompt: .asciiz "Number : "
.text
main:
#Now lets read a number
li $v0, 5
syscall # -> note syscall is done for each instruction
#Lets complete printing first
li $v0, 4
la $a0, prompt
syscall`

#We have the number in $t0 right now
#if we do
`li $v0, 1
la $a0, prompt
syscall `
#ask question and answer yourself. what will be printed.
#the numbe we had entered or adress of prompt
#what do you need to modify here?
Reply

#4
.text
main:
#print the msg1
li $v0 4
la $a0 msg1
syscall

#read the num 1
li $v0 5
syscall

sw $v0 a1

#print the msg2
li $v0 4
la $a0 msg2
syscall

#read the Num 2
li $v0 5
syscall

sw $v0 a2

#print the msg3
li $v0 4
la $a0 msg3
syscall

lw $t0 a1
lw $t1 a2


li $v0 1
add $a0 $t0 $t1
syscall
.data
msg1: .asciiz "Enter the first number :"
msg2: .asciiz "Enter the second number :"
a1 : .word 0
a2 : .word 0
msg3: .asciiz "The sum is = "

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through