From c591feac7d7a4e999428bf9927b326230b96ed53 Mon Sep 17 00:00:00 2001 From: TiagoRG Date: Mon, 23 Oct 2023 11:51:33 +0100 Subject: [PATCH] [AC1] Finish aula03 ex2 Signed-off-by: TiagoRG --- 2ano/1semestre/ac1/aula03/ex2.asm | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/2ano/1semestre/ac1/aula03/ex2.asm b/2ano/1semestre/ac1/aula03/ex2.asm index 664d701..a87e470 100644 --- a/2ano/1semestre/ac1/aula03/ex2.asm +++ b/2ano/1semestre/ac1/aula03/ex2.asm @@ -11,6 +11,7 @@ str2: .asciiz "O numero em binario e: " # valor: $t0 # bit: $t1 # i: $t2 +# flag: $t4 main: la $a0, str1 li $v0, print_string @@ -29,17 +30,22 @@ main: la $a0, str1 for: bge $t2, 32, endfor # Se i >= 32, termina o ciclo li $t3,0x80000000 and $t1, $t0, $t3 # bit = valor & 0x80000000 + beq $t4, 0, if1_2 + beq $t4, 1, if2 -if: beq $t1, 0, else # Se bit == 0, salta para else +if1_2: beq $t1, 0, endif1 + +if2: li $t4, 1 # flag = 1; + beq $t1, 0, else2 # Se bit == 0, salta para else li $a0, 1 # Caso contrario, imprime 1 - j endif + j endif2 -else: li $a0, 0 # Imprime 0 +else2: li $a0, 0 # Imprime 0 -endif: li $v0, print_int +endif2: li $v0, print_int syscall # Imprime o valor de a0 - sll $t0, $t0, 1 # valor = valor << 1 +endif1: sll $t0, $t0, 1 # valor = valor << 1 addi $t2,$t2,1 # i+=1 j for