Doubts Assembly mips

Asked

Viewed 318 times

0

Could someone explain to me how to use And, Andi, Or, Ori, Nor in Assembly mips? Because 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

1 answer

1


The AND and the OR is to do an operation between two registers, placing the result in another registrar. For example:

and $a0, $a1, $a2

That puts in $a0, the result of $a1 AND $a2.

Already the ANDI and the ORI is to do the operation between a register and a constant integer number, also placing the result in another registered one. For example:

andi $a0, $a1, 123

That 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 way is closer to what you will translate into Assembly mips. Use loggers to store num1, num2, x, cont and resultado. Also use these instructions in the blocks se:

  • BLEZ - Conditionally jumps to a label if the register value is less than zero.

  • BEQ - Conditionally jumps to a label if the value of the register is equal to that of another registrar.

  • BGT - Conditionally jumps to a label if the value of a register is greater than that of another register.

  • J - Executes an unconditional balance for a label.

The program, except the parts of writing texts, will also use LI and ADD.

Reference: http://www.di.ubi.pt/~desousa/2011-2012/LFC/mips.pdf

  • I understand your logic perfectly, but I’m having a hard time implementing this same logic using numbers whose result generates a comma number, type 5 / 2 = 2.5, do you understand? and I need to work with that kind of number.

  • Split: div $t0,$t1,$t2 beq $t0, $T3, if j senao if: li $v0, 4 la $A0, equals syscall j terminates senao: li $v0, 4 la $A0, different syscall li $v0, 4 la $A0, resultado2 syscall la $A0, ($t0) li $v0, 1 syscall j terminates

Browser other questions tagged

You are not signed in. Login or sign up in order to post.