[AC2] Aula01

- Missing addicional exercises

Signed-off-by: TiagoRG <tiago.rgarcia@ua.pt>
This commit is contained in:
Tiago Garcia 2024-03-01 10:25:46 +00:00
parent c2e1776156
commit 77493290ae
Signed by: TiagoRG
GPG Key ID: DFCD48E3F420DB42
6 changed files with 166 additions and 0 deletions

View File

@ -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)

Binary file not shown.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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