From 79485544bca2d7565702ab290cea8486b081035b Mon Sep 17 00:00:00 2001 From: TiagoRG Date: Tue, 5 Mar 2024 22:41:15 +0000 Subject: [PATCH] [AC2] Aula02 Finished Signed-off-by: TiagoRG --- 2ano/2semestre/ac2/aula02/addicional-1.s | 23 ++++++++++++++++++ 2ano/2semestre/ac2/aula02/part2.s | 31 ++++++++++++++++++++---- 2 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 2ano/2semestre/ac2/aula02/addicional-1.s diff --git a/2ano/2semestre/ac2/aula02/addicional-1.s b/2ano/2semestre/ac2/aula02/addicional-1.s new file mode 100644 index 0000000..82e24f2 --- /dev/null +++ b/2ano/2semestre/ac2/aula02/addicional-1.s @@ -0,0 +1,23 @@ + .equ READ_CORE_TIMER, 11 + .equ RESET_CORE_TIMER, 12 + + .data + .text + +timedone: + li $t0, 0 +timedone_if: + blez $a1, timedone_else + li $v0, RESET_CORE_TIMER + syscall + j timedone_return +timedone_else: + li $v0, READ_CORE_TIMER + syscall + move $t1, $v0 + mul $t2, $a0, 20000 + ble $t1, $t2, timedone_return + div $t0, $t1, 20000 +timedown_return: + move $v0, $t0 + jr $ra diff --git a/2ano/2semestre/ac2/aula02/part2.s b/2ano/2semestre/ac2/aula02/part2.s index 65c2516..f91bcde 100644 --- a/2ano/2semestre/ac2/aula02/part2.s +++ b/2ano/2semestre/ac2/aula02/part2.s @@ -1,3 +1,4 @@ + .equ INKEY, 1 .equ READ_CORE_TIMER, 11 .equ RESET_CORE_TIMER, 12 .equ PUT_CHAR, 3 @@ -11,10 +12,12 @@ # cnt1: $s0 # cnt5: $s1 # cnt10: $s2 +# factor: $s3 main: li $s0, 0 li $s1, 0 li $s2, 0 + li $s3, 100 while: li $a0, '\r' li $v0, PUT_CHAR @@ -49,21 +52,39 @@ while: li $a0, '\r' li $v0, PRINT_INT syscall + li $v0, INKEY + syscall + move $t0, $v0 + beq $t0, 'A', increase_speed + beq $t0, 'N', decrease_speed + beq $t0, 'S', suspend + j continue + +increase_speed: + div $s3, $s3, 2 + j continue +decrease_speed: + li $s3, 100 + j continue +suspend: + li $v0, INKEY + syscall + beq $v0, 'R', continue + j suspend +continue: addu $sp, $sp, -4 sw $ra, 0($sp) - li $a0, 100 + move $a0, $s3 jal delay - remi $t0, $s0, 10 + rem $t0, $s2, 10 bnez $t0, ignore1 addi $s0, $s0, 1 - li $s3, 0 ignore1: - remi $t0, $s1, 2 + rem $t0, $s2, 2 bnez $t0, ignore5 addi $s1, $s1, 1 - li $s4, 0 ignore5: addi $s2, $s2, 1