diff --git a/2ano/2semestre/ac2/aula02/AC2-P-Aula02.pdf b/2ano/2semestre/ac2/aula02/AC2-P-Aula02.pdf new file mode 100644 index 0000000..67fab1e Binary files /dev/null and b/2ano/2semestre/ac2/aula02/AC2-P-Aula02.pdf differ diff --git a/2ano/2semestre/ac2/aula02/part1-ex1.c b/2ano/2semestre/ac2/aula02/part1-ex1.c new file mode 100644 index 0000000..527b553 --- /dev/null +++ b/2ano/2semestre/ac2/aula02/part1-ex1.c @@ -0,0 +1,13 @@ +#include + +int main() { + int counter = 0; + while (1) { + putChar('\r'); + printInt(counter, 10 | 4 << 16); + resetCoreTimer(); + while (readCoreTimer() < 200000); + counter++; + } + return 0; +} diff --git a/2ano/2semestre/ac2/aula02/part1-ex1.s b/2ano/2semestre/ac2/aula02/part1-ex1.s new file mode 100644 index 0000000..15c3902 --- /dev/null +++ b/2ano/2semestre/ac2/aula02/part1-ex1.s @@ -0,0 +1,37 @@ + .equ READ_CORE_TIMER, 11 + .equ RESET_CORE_TIMER, 12 + .equ PUT_CHAR, 3 + .equ PRINT_INT, 6 + + .data + .text + .globl main + +main: li $t0, 0 + +while: li $a0, '\r' + li $v0, PUT_CHAR + syscall + + move $a0, $t0 + li $a1, 4 + sll $a1, $a1, 16 + ori $a1, $a1, 10 + li $v0, PRINT_INT + syscall + + li $v0, RESET_CORE_TIMER + syscall + +delay: li $v0, READ_CORE_TIMER + syscall + move $t1, $v0 + + # 20,000,000 cycles = 1 second = 1 Hz + # 4,000,000 cycles = 0.2 second = 5 Hz + # 2,000,000 cycles = 0.1 second = 10 Hz + blt $t1, 20000000, delay + + addi $t0, $t0, 1 + j while + diff --git a/2ano/2semestre/ac2/aula02/part1-ex2.c b/2ano/2semestre/ac2/aula02/part1-ex2.c new file mode 100644 index 0000000..d601326 --- /dev/null +++ b/2ano/2semestre/ac2/aula02/part1-ex2.c @@ -0,0 +1,16 @@ +#include + +void delay(unsigned int ms) { + resetCoreTimer(); + while(readCoreTimer() < ms * 20000); +} + +int main() { + int counter = 0; + while (1) { + putChar('\r'); + printInt(counter++, 10 | 4 << 16); + delay(1000); + } + return 0; +} diff --git a/2ano/2semestre/ac2/aula02/part1-ex2.s b/2ano/2semestre/ac2/aula02/part1-ex2.s new file mode 100644 index 0000000..cea5209 --- /dev/null +++ b/2ano/2semestre/ac2/aula02/part1-ex2.s @@ -0,0 +1,39 @@ + .equ READ_CORE_TIMER, 11 + .equ RESET_CORE_TIMER, 12 + .equ PUT_CHAR, 3 + .equ PRINT_INT, 6 + + .data + .text + .globl main + +main: li $s0, 0 + +while: li $a0, '\r' + li $v0, PUT_CHAR + syscall + + move $a0, $s0 + li $a1, 4 + sll $a1, $a1, 16 + ori $a1, $a1, 10 + li $v0, PRINT_INT + syscall + + addu $sp, $sp, -4 + sw $ra, 0($sp) + li $a0, 1000 + jal delay + + addi $s0, $s0, 1 + j while + +delay: li $v0, RESET_CORE_TIMER + syscall + +count: li $v0, READ_CORE_TIMER + syscall + mul $t0, $a0, 20000 + blt $v0, $t0, count + + jr $ra diff --git a/2ano/2semestre/ac2/aula02/part2.c b/2ano/2semestre/ac2/aula02/part2.c new file mode 100644 index 0000000..78dc9e5 --- /dev/null +++ b/2ano/2semestre/ac2/aula02/part2.c @@ -0,0 +1,38 @@ +#include + +void delay(unsigned int ms) { + resetCoreTimer(); + while(readCoreTimer() < ms * 20000); +} + +int main() { + int cnt1 = 0, cnt5 = 0, cnt10 = 0; + unsigned int ms = 100; + while (1) { + putChar('\r'); + printInt(cnt1, 10 | 4 << 16); + putChar('\t'); + printInt(cnt5, 10 | 4 << 16); + putChar('\t'); + printInt(cnt10, 10 | 4 << 16); + + char key = inkey(); + switch(key) { + case 'S': + while(inkey() != 'R'); + break; + case 'A': + ms /= 2; + break; + case 'N': + ms = 100; + break; + } + + delay(ms); + if (cnt10 % 10 == 0) cnt1++; + if (cnt10 % 2 == 0) cnt5++; + cnt10++; + } + return 0; +} diff --git a/2ano/2semestre/ac2/aula02/part2.s b/2ano/2semestre/ac2/aula02/part2.s new file mode 100644 index 0000000..65c2516 --- /dev/null +++ b/2ano/2semestre/ac2/aula02/part2.s @@ -0,0 +1,80 @@ + .equ READ_CORE_TIMER, 11 + .equ RESET_CORE_TIMER, 12 + .equ PUT_CHAR, 3 + .equ PRINT_INT, 6 + + .data + .text + .globl main + +# Mapa de registos +# cnt1: $s0 +# cnt5: $s1 +# cnt10: $s2 + +main: li $s0, 0 + li $s1, 0 + li $s2, 0 + +while: li $a0, '\r' + li $v0, PUT_CHAR + syscall + + move $a0, $s0 + li $a1, 4 + sll $a1, $a1, 16 + ori $a1, $a1, 10 + li $v0, PRINT_INT + syscall + + li $a0, '\t' + li $v0, PUT_CHAR + syscall + + move $a0, $s1 + li $a1, 4 + sll $a1, $a1, 16 + ori $a1, $a1, 10 + li $v0, PRINT_INT + syscall + + li $a0, '\t' + li $v0, PUT_CHAR + syscall + + move $a0, $s2 + li $a1, 4 + sll $a1, $a1, 16 + ori $a1, $a1, 10 + li $v0, PRINT_INT + syscall + + addu $sp, $sp, -4 + sw $ra, 0($sp) + li $a0, 100 + jal delay + + remi $t0, $s0, 10 + bnez $t0, ignore1 + addi $s0, $s0, 1 + li $s3, 0 + +ignore1: + remi $t0, $s1, 2 + bnez $t0, ignore5 + addi $s1, $s1, 1 + li $s4, 0 + +ignore5: + addi $s2, $s2, 1 + j while + +delay: li $v0, RESET_CORE_TIMER + syscall + +count: li $v0, READ_CORE_TIMER + syscall + mul $t0, $a0, 20000 + blt $v0, $t0, count + + jr $ra