Questions Assembly mips

0

Could someone explain me how to use And, Andi, Or, Ori, Nor in Assembly mips? I would like to do something like this:

se (num1 > 0) e (num2 > 0) entao
    se (num1 <= 10) e (num2 <= 10) entao
       cont <- num1 + num2
       se (cont = resultado) entao
          escreval ("Parabéns você acertou!")
       seNao
          escreval ("Você errou!")
          escreva ("O resultado é: ")
          escreva (cont)
       fimSe
    seNao
       EscrevaL(" STATUS: ALGO INCOMUM. ")
       EscrevaL(" Você digitou os dados corretos? ")
    fimSe
 seNao
    EscrevaL(" STATUS: ALGO INCOMUM. ")
    EscrevaL(" Você digitou os dados corretos? ")
 fimSe
    
asked by anonymous 19.01.2017 / 17:20

1 answer

1

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

    
19.01.2017 / 17:51