diff --git a/2ano/1semestre/ac1/aula03/AC1-P-Aula3.pdf b/2ano/1semestre/ac1/aula03/AC1-P-Aula3.pdf new file mode 100644 index 0000000..b4e6c9e Binary files /dev/null and b/2ano/1semestre/ac1/aula03/AC1-P-Aula3.pdf differ diff --git a/2ano/1semestre/ac1/aula03/ex1.asm b/2ano/1semestre/ac1/aula03/ex1.asm new file mode 100644 index 0000000..f39f973 --- /dev/null +++ b/2ano/1semestre/ac1/aula03/ex1.asm @@ -0,0 +1,44 @@ + .data +str1: .asciiz "Introduza um numero: " +str2: .asciiz "Valor ignorado\n" +str3: .asciiz "A soma dos positivos e: " + .eqv print_string,4 + .eqv read_int,5 + .eqv print_int,1 + .text + .globl main +# Mapa de registos: +# soma: $t0 +# valor: $t1 +# i: $t2 +main: li $t2,0 # i=0 + li $t0,0 # soma=0 +for: bge $t2,5,endfor # while (i<5) do { + + li $v0,print_string + la $a0,str1 + syscall # printf("Introduza um numero: ") + + li $v0,read_int + syscall # scanf("%d",&valor) + move $t1,$v0 # valor=scanf("%d",&valor) + +if: ble $t1,0,else # if (valor<0) then { + add $t0,$t0,$t1 # soma+=valor + addi $t2,$t2,1 # i+=1 + + j endif +else: li $v0,print_string + la $a0,str2 + syscall # printf("Valor ignorado\n") +endif: j for # } + +endfor: li $v0,print_string + la $a0,str3 + syscall # printf("A soma dos positivos e: %d\n",soma") + + li $v0,print_int + move $a0,$t0 + syscall # printf("%d\n",soma) + + jr $ra # } diff --git a/2ano/1semestre/ac1/aula03/ex2.asm b/2ano/1semestre/ac1/aula03/ex2.asm new file mode 100644 index 0000000..664d701 --- /dev/null +++ b/2ano/1semestre/ac1/aula03/ex2.asm @@ -0,0 +1,46 @@ + .data +str1: .asciiz "Introduza um numero: " +str2: .asciiz "O numero em binario e: " + .eqv print_string, 4 + .eqv read_int, 5 + .eqv print_int, 1 + .text + .globl main + +# Mapa de registos: +# valor: $t0 +# bit: $t1 +# i: $t2 + +main: la $a0, str1 + li $v0, print_string + syscall # Imprime a mensagem "Introduza um numero: " + + li $v0, read_int + syscall # Le o numero introduzido pelo utilizador + move $t0, $v0 # Guarda o numero introduzido em $t0 + + li $v0, print_string + la $a0, str2 + syscall # Imprime a mensagem "O numero em binario e: " + + li $t2, 0 # Inicializa o contador i a 0 + +for: bge $t2, 32, endfor # Se i >= 32, termina o ciclo + li $t3,0x80000000 + and $t1, $t0, $t3 # bit = valor & 0x80000000 + +if: beq $t1, 0, else # Se bit == 0, salta para else + li $a0, 1 # Caso contrario, imprime 1 + j endif + +else: li $a0, 0 # Imprime 0 + +endif: li $v0, print_int + syscall # Imprime o valor de a0 + + sll $t0, $t0, 1 # valor = valor << 1 + + addi $t2,$t2,1 # i+=1 + j for +endfor: jr $ra # Salta para o endereco de retorno