[AC1] Finish aula03 ex2
Signed-off-by: TiagoRG <tiago.rgarcia@ua.pt>
This commit is contained in:
parent
39266b408e
commit
d19d44b7d2
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue