The AND
and OR
is to perform an operation between two registers, placing the result in another register. For example:
and $a0, $a1, $a2
This puts in $a0
, the result of $a1 AND $a2
.
Now the ANDI
and ORI
is to make the operation between a register and a constant integer, also putting the result in another register. For example:
andi $a0, $a1, 123
This puts in $a0
, the result of $a1 AND 123
.
To make your algorithm, you'd better rewrite it like this:
inicio:
se num1 <= 0 entao goto saida
se num2 <= 0 entao goto saida
x <- 10
se num1 > x entao goto saida
se num2 > x entao goto saida
cont <- num1 + num2
se cont = resultado entao goto parabens
escreval("Você errou!")
escreva("O resultado é: ")
escreva(cont)
goto fim
parabens:
escreval("Parabéns você acertou!")
goto fim
saida:
EscrevaL(" STATUS: ALGO INCOMUM. ")
EscrevaL(" Você digitou os dados corretos? ")
fim:
This form is closest to what you will translate into assembly mips. Use registers to store num1
, num2
, x
, cont
and resultado
. Also use these statements in se
blocks:
-
BLEZ
- Jump conditionally to a label if the value of the register is less than zero.
-
BEQ
- Jump conditionally to a label if the value of the register is equal to that of another register.
-
BGT
- Jump conditionally to a label if the value of one register is greater than another register.
-
J
- Performs an unconditional balance for a label.
The program, except parts of writing texts, will also use LI
and ADD
.
Reference: link