[AC2] Aula02

- Missing additional exercises

Signed-off-by: TiagoRG <tiago.rgarcia@ua.pt>
This commit is contained in:
Tiago Garcia 2024-03-01 10:30:45 +00:00
parent 83dd876d16
commit 82297aa802
Signed by: TiagoRG
GPG Key ID: DFCD48E3F420DB42
7 changed files with 223 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,13 @@
#include <detpic32.h>
int main() {
int counter = 0;
while (1) {
putChar('\r');
printInt(counter, 10 | 4 << 16);
resetCoreTimer();
while (readCoreTimer() < 200000);
counter++;
}
return 0;
}

View File

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

View File

@ -0,0 +1,16 @@
#include <detpic32.h>
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;
}

View File

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

View File

@ -0,0 +1,38 @@
#include <detpic32.h>
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;
}

View File

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