diff --git a/2ano/2semestre/ac2/README.md b/2ano/2semestre/ac2/README.md new file mode 100644 index 0000000..a384c44 --- /dev/null +++ b/2ano/2semestre/ac2/README.md @@ -0,0 +1,5 @@ +# Arquitetura de Computadores 2 +### Projetos + resoluções de exercícios organizados por aulas + +--- +*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new) diff --git a/2ano/2semestre/ac2/aula01/AC2-P-Aula01.pdf b/2ano/2semestre/ac2/aula01/AC2-P-Aula01.pdf new file mode 100644 index 0000000..9cee9d5 Binary files /dev/null and b/2ano/2semestre/ac2/aula01/AC2-P-Aula01.pdf differ diff --git a/2ano/2semestre/ac2/aula01/part1.s b/2ano/2semestre/ac2/aula01/part1.s new file mode 100644 index 0000000..71d2468 --- /dev/null +++ b/2ano/2semestre/ac2/aula01/part1.s @@ -0,0 +1,13 @@ + .equ PRINT_STR, 8 + + .data +msg: .asciz "AC2 - Aulas praticas\n" + + .text + .globl main + +main: la $a0, msg + li $v0, PRINT_STR + syscall # printStr("AC2 - Aulas praticas\n"); + li $v0, 0 # return 0; + jr $ra diff --git a/2ano/2semestre/ac2/aula01/part2-a.s b/2ano/2semestre/ac2/aula01/part2-a.s new file mode 100644 index 0000000..36ae541 --- /dev/null +++ b/2ano/2semestre/ac2/aula01/part2-a.s @@ -0,0 +1,35 @@ + .equ GET_CHAR, 2 + .equ PUT_CHAT, 3 + .equ PRINT_INT, 6 + .equ PRINT_STR, 8 + .data + + .text + .globl main + +# Mapa de registos +# $t0: cnt +# $t1: c + +main: li $t0, 0 + +do: # do { + li $v0, GET_CHAR + syscall + move $t1, $v0 # c = getChar(); + + li $v0, PUT_CHAT + addi $a0, $t1, 0 + syscall # putChar(c); + + addi $t0, 1 # cnt++; + + bne $t1, '\n', do # } while (c != '\n'); + +fi: li $v0, PRINT_INT + move $a0, $t0 + li $a1, 10 + syscall + + li $v0, 0 + jr $ra diff --git a/2ano/2semestre/ac2/aula01/part2-b.s b/2ano/2semestre/ac2/aula01/part2-b.s new file mode 100644 index 0000000..ca2c172 --- /dev/null +++ b/2ano/2semestre/ac2/aula01/part2-b.s @@ -0,0 +1,38 @@ + .equ INKEY, 1 + .equ GET_CHAR, 2 + .equ PUT_CHAT, 3 + .equ PRINT_INT, 6 + .equ PRINT_STR, 8 + .data + + .text + .globl main + +# Mapa de registos +# $t0: cnt +# $t1: c + +main: li $t0, 0 + +do: # do { + li $v0, INKEY + syscall + move $t1, $v0 # c = inkey(); + +if: beq $t1, 0, fi # if (c != 0) { + move $a0, $t1 # putchar(c); + +fi: li $v0, PUT_CHAT + syscall # getchar(); + + addi $t0, 1 # cnt++; + + bne $t1, '\n', do # } while (c != '\n'); + +fi: li $v0, PRINT_INT + move $a0, $t0 + li $a1, 10 + syscall + + li $v0, 0 + jr $ra diff --git a/2ano/2semestre/ac2/aula01/part2-c.s b/2ano/2semestre/ac2/aula01/part2-c.s new file mode 100644 index 0000000..188881a --- /dev/null +++ b/2ano/2semestre/ac2/aula01/part2-c.s @@ -0,0 +1,75 @@ + .equ GET_CHAR, 2 + .equ PUT_CHAT, 3 + .equ READ_INT10, 5 + .equ PRINT_INT, 6 + .equ PRINT_INT10, 7 + .equ PRINT_STR, 8 + .data + +input: .asciiz "\nIntroduza um inteiro (sinal e modulo): " +out_10: .asciiz "\nValor em base 10 (signed): " +out_2: .asciiz "\nValor em base 2: " +out_16: .asciiz "\nValor em base 16: " +out_u10: + .asciiz "\nValor em base 10 (unsigned): " +out_u10f: + .asciiz "\nValor em base 10 (unsigned), formatado: " + + .text + .globl main + +main: la $a0, input + li $v0, PRINT_STR + syscall # printStr(input); + + li $v0, READ_INT10 + syscall + move $t0, $v0 # value = readInt10(); + + la $a0, out_10 + li $v0, PRINT_STR + syscall # printStr(10 signed); + + move $a0, $t0 + li $v0, PRINT_INT10 + syscall # printInt10(value); + + la $a0, out_10 + li $v0, PRINT_STR + syscall # printStr(2); + + move $a0, $t0 + li $a1, 2 + li $v0, PRINT_INT + syscall # printInt(value, 2); + + la $a0, out_10 + li $v0, PRINT_STR + syscall # printStr(16); + + move $a0, $t0 + li $a1, 16 + li $v0, PRINT_INT + syscall # printInt(value, 16); + + la $a0, out_10 + li $v0, PRINT_STR + syscall # printStr(10 unsigned); + + move $a0, $t0 + li $a1, 10 + li $v0, PRINT_INT + syscall # printInt(value, 10); + + la $a0, out_u10f + li $v0, PRINT_STR + syscall # printStr(10 unsigned, formatado); + + move $a0, $t0 + li $a1, 5 + sll $a1, $a1, 16 + ori $a1, $a1, 5 + li $v0, PRINT_INT + syscall # printInt(value, 10 | 5 << 16); + + j main