diff --git a/2ano/1semestre/ac1/aula04/AC1-P-Aula4.pdf b/2ano/1semestre/ac1/aula04/AC1-P-Aula4.pdf new file mode 100644 index 0000000..b4c2056 Binary files /dev/null and b/2ano/1semestre/ac1/aula04/AC1-P-Aula4.pdf differ diff --git a/2ano/1semestre/ac1/aula04/ex01-addicional.asm b/2ano/1semestre/ac1/aula04/ex01-addicional.asm new file mode 100644 index 0000000..f360bfb --- /dev/null +++ b/2ano/1semestre/ac1/aula04/ex01-addicional.asm @@ -0,0 +1,72 @@ + .data + .eqv SIZE, 20 + .eqv print_string, 4 + .eqv read_string, 8 +str: .space 21 +str1: .asciiz "Introduza uma string: " + + .text + .globl main + +# Mapa de registos +# $t0: p +# $t1: *p + +main: li $v0, print_string + la $a0, str1 + syscall # print_string("Introduza uma string: "); + + la $a0, str + li $a1, SIZE + li $v0, read_string + syscall # read_string(str, SIZE); + +# --- CONVERTER PARA MAIÚSCULAS --- + + la $t0, str # p = str; + +while1: lb $t1, 0($t0) + beq $t1, 0x00, endw1 # while (*p != '\0') { + +if1: blt $t1, 0x61, else1 # if (*p >= 'a') + bgt $t1, 0x7A, else1 # if (*p <= 'z') + + addiu $t1, $t1, -0x20 # *p = *p - 'a' + 'A'; + sb $t1, 0($t0) + +else1: addiu $t0, $t0, 1 # p++ + j while1 # } + +endw1: li $v0, print_string + la $a0, str + syscall + +# --------------------------------- + + li $v0, 11 + li $a0, '\n' + syscall + +# --- CONVERTER PARA MINÚSCULAS --- + + la $t0, str # p = str; + +while2: lb $t1, 0($t0) + beq $t1, 0x00, endw2 # while (*p != '\0') { + +if2: blt $t1, 0x41, else2 # if (*p >= 'a') + bgt $t1, 0x5A, else2 # if (*p <= 'z') + + addiu $t1, $t1, 0x20 # *p = *p - 'a' + 'A'; + sb $t1, 0($t0) + +else2: addiu $t0, $t0, 1 # p++ + j while2 # } + +endw2: li $v0, print_string + la $a0, str + syscall + +# --------------------------------- + + jr $ra diff --git a/2ano/1semestre/ac1/aula04/ex01-addicional.c b/2ano/1semestre/ac1/aula04/ex01-addicional.c new file mode 100644 index 0000000..ccaaf72 --- /dev/null +++ b/2ano/1semestre/ac1/aula04/ex01-addicional.c @@ -0,0 +1,40 @@ +#include +#define SIZE 20 + +int main(void) +{ + static char str[SIZE+1]; + char *p; + + printf("Introduza uma string: "); + scanf("%s", str); + p = str; + + /// CONVERTER PARA MAIÚSCULAS + while (*p != 0x00) + { + if (*p >= 0x61 && *p <= 0x7A) + *p = *p + -0x20; + + p++; + } + /// + + printf("%s\n", str); + + p = str; + + /// CONVERTER PARA MINÚSCULAS + while (*p != 0x00) + { + if (*p >= 0x41 && *p <= 0x5A) + *p = *p + 0x20; + + p++; + } + /// + + printf("%s\n", str); + + return 0; +} diff --git a/2ano/1semestre/ac1/aula04/ex01-addicional.md b/2ano/1semestre/ac1/aula04/ex01-addicional.md new file mode 100644 index 0000000..ae9f3cd --- /dev/null +++ b/2ano/1semestre/ac1/aula04/ex01-addicional.md @@ -0,0 +1,17 @@ +# Alinea b) + +| p (\$t0) | \*p (\$t1) | | +|:----------:|:----------:|:--------------------| +| 0x10010000 | 0x41 | Valores iniciais | +| 0x10010001 | 0x63 | Fim da 1ª iteração | +| 0x10010002 | 0x31 | Fim da 2ª iteração | +| 0x10010003 | 0x2D | Fim da 3ª iteração | +| 0x10010004 | 0x70 | Fim da 4ª iteração | +| 0x10010005 | 0x72 | Fim da 5ª iteração | +| 0x10010006 | 0x41 | Fim da 6ª iteração | +| 0x10010007 | 0x74 | Fim da 7ª iteração | +| 0x10010008 | 0x69 | Fim da 8ª iteração | +| 0x10010009 | 0x63 | Fim da 9ª iteração | +| 0x10010010 | 0x61 | Fim da 10ª iteração | +| 0x10010011 | 0x53 | Fim da 11ª iteração | +| 0x10010012 | 0x00 | Fim da 12ª iteração | diff --git a/2ano/1semestre/ac1/aula04/ex01.asm b/2ano/1semestre/ac1/aula04/ex01.asm new file mode 100644 index 0000000..05763a1 --- /dev/null +++ b/2ano/1semestre/ac1/aula04/ex01.asm @@ -0,0 +1,39 @@ + .eqv SIZE,20 + + .data +str: .space 21 + + .text + .globl main + +# Mapa de registos +# num: $t0 +# i: $t1 +# str: $t2 +# str+i: $t3 +# str[i]: $t4 + +main: la $a0,str + li $a1,SIZE + li $v0,8 + syscall # read_string(str,SIZE) + li $t0,0 # num = 0 + li $t1,0 # i = 0 + +while: la $t2,str # $t2=&str[0] <=> $t2=str + addu $t3,$t2,$t1 # $t3=&str[i] <=> $t3=str+i + lb $t4,0($t3) # $t4=str[i] + beq $t4,'\0',endw # if (str[i]=='\0') goto endw + +if: blt $t4,'0',endif + bgt $t4,'9',endif + addi $t0,$t0,1 # num++ + +endif: addi $t1,$t1,1 # i++ + j while + +endw: move $a0,$t0 + li $v0,1 + syscall + + jr $ra diff --git a/2ano/1semestre/ac1/aula04/ex01.md b/2ano/1semestre/ac1/aula04/ex01.md new file mode 100644 index 0000000..55d3aab --- /dev/null +++ b/2ano/1semestre/ac1/aula04/ex01.md @@ -0,0 +1,13 @@ +# Alinea b) + +| Endereço de str (\$t2) | Endereço de str[i] (\$t3) | str[i] (\$t4) | i (\$t1) | num (\$t0) | | +|:-:|:-:|:-:|:-:|:-:|:-:| +| | | | 0 | 0 | Val. iniciais | +| 0x10010000 | 0x10010000 | 0x00000041 | 1 | 0 | Fim da 1ª iteração | +| 0x10010000 | 0x10010001 | 0x00000043 | 2 | 0 | Fim da 2ª iteração | +| 0x10010000 | 0x10010003 | 0x00000031 | 3 | 1 | Fim da 3ª iteração | +| 0x10010000 | 0x10010003 | 0x0000002d | 4 | 1 | Fim da 4ª iteração | +| 0x10010000 | 0x10010004 | 0x0000004c | 5 | 1 | Fim da 5ª iteração | +| 0x10010000 | 0x10010005 | 0x00000061 | 6 | 1 | Fim da 6ª iteração | +| 0x10010000 | 0x10010006 | 0x00000062 | 7 | 1 | Fim da 7ª iteração | +| 0x10010000 | 0x10010006 | 0x00000073 | 8 | 1 | Fim da 8ª iteração | diff --git a/2ano/1semestre/ac1/aula04/ex02.asm b/2ano/1semestre/ac1/aula04/ex02.asm new file mode 100644 index 0000000..9b05a3f --- /dev/null +++ b/2ano/1semestre/ac1/aula04/ex02.asm @@ -0,0 +1,38 @@ + .eqv SIZE,20 + + .data +str: .space 21 + + .text + .globl main + +# Mapa de registos +# num: $t0 +# p: $t1 +# *p: $t2 + +main: la $a0,str + li $a1,SIZE + li $v0,8 + syscall # read_string(str,SIZE) + + li $t0,0 # num = 0 + la $t1, str # p = str + + +while: lb $t2, 0($t1) # *p + beq $t2, '\0', endw # while (*p != '\0') { + +if: blt $t2, '0', endif # if (*p >= '0') + bgt $t2, '9', endif # if (*p <= '9') + addi $t0, $t0, 1 # num++; + +endif: addiu $t1, $t1, 1 # p++; + j while # } + + +endw: move $a0,$t0 + li $v0,1 + syscall + + jr $ra diff --git a/2ano/1semestre/ac1/aula04/ex02.md b/2ano/1semestre/ac1/aula04/ex02.md new file mode 100644 index 0000000..c32b6c6 --- /dev/null +++ b/2ano/1semestre/ac1/aula04/ex02.md @@ -0,0 +1,14 @@ +# Alinea b) + +| num (\$t0) | p (\$t1) | \*p (\$t2) | | +|:----------:|:----------:|:----------:|:-------------------| +| 0 | 0x10010000 | 0x41 | Val. iniciais | +| 0 | 0x10010001 | 0x43 | Fim da 1ª iteração | +| 0 | 0x10010002 | 0x31 | Fim da 2ª iteração | +| 1 | 0x10010003 | 0x2D | Fim da 3ª iteração | +| 1 | 0x10010004 | 0x4C | Fim da 4ª iteração | +| 1 | 0x10010005 | 0x41 | Fim da 5ª iteração | +| 1 | 0x10010006 | 0x42 | Fim da 6ª iteração | +| 1 | 0x10010007 | 0x73 | Fim da 7ª iteração | +| 1 | 0x10010008 | 0x00 | Fim da 8ª iteração | + diff --git a/2ano/1semestre/ac1/aula04/ex03-c.asm b/2ano/1semestre/ac1/aula04/ex03-c.asm new file mode 100644 index 0000000..cbf5d06 --- /dev/null +++ b/2ano/1semestre/ac1/aula04/ex03-c.asm @@ -0,0 +1,34 @@ + .data + .eqv SIZE, 4 + .eqv print_int10, 1 +array: .word 7692, 23, 5, 234 + + .text + .globl main + +# Mapa de registos +# $t0: i +# $t1: soma +# $t2: array +# $t3: array[i] + +main: li $t1, 0 # int soma = 0; + li $t0, 0 # int i = 0; + la $t2, array + +while: bge $t0, SIZE, endw # while (i < SIZE) { + + sll $t4, $t0, 2 + addu $t3, $t2, $t4 + lw $t3, 0($t3) + + add $t1, $t1, $t3 + + addi $t0, $t0, 1 + j while + +endw: li $v0, print_int10 + move $a0, $t1 + syscall + + jr $ra diff --git a/2ano/1semestre/ac1/aula04/ex03-c.c b/2ano/1semestre/ac1/aula04/ex03-c.c new file mode 100644 index 0000000..7a8560b --- /dev/null +++ b/2ano/1semestre/ac1/aula04/ex03-c.c @@ -0,0 +1,18 @@ +#include +#define SIZE 4 +int array[4] = {7692, 23, 5, 234}; + +int main(void) +{ + int soma = 0; + int i = 0; + + while (i < SIZE) { + soma += array[i]; + i++; + } + + printf("%d", soma); + + return 0; +} diff --git a/2ano/1semestre/ac1/aula04/ex03.asm b/2ano/1semestre/ac1/aula04/ex03.asm new file mode 100644 index 0000000..5efcb0e --- /dev/null +++ b/2ano/1semestre/ac1/aula04/ex03.asm @@ -0,0 +1,35 @@ + .data + .eqv SIZE, 4 + .eqv print_int10, 1 +array: .word 7692, 23, 5, 234 + + .text + .globl main + +# Mapa de registos +# $t0: p +# $t1: pultimo +# $t2: *p +# $t3: soma + +main: li $t3, 0 # int soma = 0; + + la $t0, array # p = array; + + li $t4, SIZE + addi $t4, $t4, -1 + sll $t4, $t4, 2 + la $t1, array # pultimo = array; + addu $t1, $t1, $t4 # pultimo += size - 1; + +while: bgt $t0, $t1, endw # while (p <= pultimo) { + lw $t2, 0($t0) # *p + add $t3, $t3, $t2 # soma += (*p); + addiu $t0, $t0, 4 # p++; + j while + +endw: li $v0, print_int10 + move $a0, $t3 + syscall # print_int10(soma); + + jr $ra diff --git a/2ano/1semestre/ac1/aula04/ex03.md b/2ano/1semestre/ac1/aula04/ex03.md new file mode 100644 index 0000000..2f50c7f --- /dev/null +++ b/2ano/1semestre/ac1/aula04/ex03.md @@ -0,0 +1,9 @@ +# Alinea b) + +| p (\$t0) | pultimo (\$t1) | \*p (\$t2) | soma (\$t3) | | +|:----------:|:--------------:|:----------:|:-----------:|:-------------------| +| 0x10010000 | 0x1001000C | 0x0000 | 0x0000 | Val. iniciais | +| 0x10010004 | 0x1001000C | 0x1E0C | 0x1E0C | Fim da 1ª iteração | +| 0x10010008 | 0x1001000C | 0x0017 | 0x1E23 | Fim da 2ª iteração | +| 0x1001000C | 0x1001000C | 0x0005 | 0x1E28 | Fim da 3ª iteração | +| 0x10010010 | 0x1001000C | 0x00EA | 0x1F12 | Fim da 4ª iteração |