Repetition loop in assembly

4

How can I do a repetition a certain number of times in assembly (in the MIPS )?

Example in pseudocode, assuming that the variable registrador is a register that I want to receive all numbers from 1 to 6 (one at a time, obviously)

var i = 1;
while(i <= 6)
{
    registrador = i;
    i = i + 1;
}
    
asked by anonymous 16.05.2017 / 20:59

3 answers

2

Something like that?

MIPS Instruction Reference.

.globl main

 main:
    li $v0, 0               # registrador
    li $t0, 1               # valor inicial do índice do laço

loop:
    bgt $t0, 5, exit        # se $t0 > 5, interrompa laço
    move $v0, $t0           # registrador = $t0
    addiu $t0, $t0, 1       # incrementa índice
    j loop                  # vá para o label [loop:]

exit:
    
16.05.2017 / 21:16
3

I made a slightly simpler version of the other answer. Without using move - I changed my mind shortly after.

main:
    li $t0, 0             # $t0 é o incrementador (o "i" da pergunta)
    li $t1, 6             # $t1 é o valor máximo (serão 5 loops)

loop: 
    beq $t0, $t1, done    # se o $t0 for igual a $t1, vai para 'done' (acabou o loop)
    addi $t0, $t0, 1      # incrementar $t0 em 1
    j loop                # pular para (goto) 'while'

done:
    
18.05.2017 / 17:00
0

program simq1; uses crt; var i, k: integer;     vet: array [1..10] of integer;

begin      clrscr;      writeln ('Which are the 10 numbers?');      for i: = 1 to 10 of      begin           readln (vet [i]);      end;      for i: = 1 to 10 of      begin           for k: = 1 to 10 of           begin                if (i

31.10.2018 / 13:14