[AC2] Aula03 Refactor

Signed-off-by: TiagoRG <tiago.rgarcia@ua.pt>
This commit is contained in:
Tiago Garcia 2024-03-01 22:31:31 +00:00
parent 013aa534ec
commit 74408b634d
Signed by: TiagoRG
GPG Key ID: DFCD48E3F420DB42
7 changed files with 59 additions and 91 deletions

View File

@ -12,8 +12,8 @@
.equ PORTE, 0x6110 .equ PORTE, 0x6110
.equ LATE, 0x6120 .equ LATE, 0x6120
.equ READ_CORE_TIMER, 11 .equ READ_CORE_TIMER, 11
.equ RESET_CORE_TIMER, 12 .equ RESET_CORE_TIMER, 12
.data .data
.text .text

View File

@ -12,8 +12,8 @@
.equ PORTE, 0x6110 .equ PORTE, 0x6110
.equ LATE, 0x6120 .equ LATE, 0x6120
.equ READ_CORE_TIMER, 11 .equ READ_CORE_TIMER, 11
.equ RESET_CORE_TIMER, 12 .equ RESET_CORE_TIMER, 12
.data .data
.text .text

View File

@ -12,8 +12,8 @@
.equ PORTE, 0x6110 .equ PORTE, 0x6110
.equ LATE, 0x6120 .equ LATE, 0x6120
.equ READ_CORE_TIMER, 11 .equ READ_CORE_TIMER, 11
.equ RESET_CORE_TIMER, 12 .equ RESET_CORE_TIMER, 12
.data .data
.text .text

View File

@ -12,8 +12,8 @@
.equ PORTE, 0x6110 .equ PORTE, 0x6110
.equ LATE, 0x6120 .equ LATE, 0x6120
.equ READ_CORE_TIMER, 11 .equ READ_CORE_TIMER, 11
.equ RESET_CORE_TIMER, 12 .equ RESET_CORE_TIMER, 12
.data .data
.text .text

View File

@ -1,19 +1,9 @@
.equ ADDR_BASE, 0xBF88 .equ ADDR_BASE, 0xBF88
.equ TRISB, 0x6040
.equ PORTB, 0x6050
.equ LATB, 0x6060
.equ TRISC, 0x6080
.equ PORTC, 0x6090
.equ LATC, 0x60A0
.equ TRISD, 0x60C0
.equ PORTD, 0x60D0
.equ LATD, 0x60E0
.equ TRISE, 0x6100 .equ TRISE, 0x6100
.equ PORTE, 0x6110
.equ LATE, 0x6120 .equ LATE, 0x6120
.equ READ_CORE_TIMER, 11 .equ READ_CORE_TIMER, 11
.equ RESET_CORE_TIMER, 12 .equ RESET_CORE_TIMER, 12
.data .data
.text .text
@ -33,11 +23,11 @@ main:
li $t0, 0x0001 # Iniciar contagem li $t0, 0x0001 # Iniciar contagem
loop: loop:
lw $t2, LATE($t7) lw $t1, LATE($t7)
andi $t2, $t2, 0xFFE1 # 1111 1111 1110 0001 (reset bits 4-1) andi $t1, $t1, 0xFFE1 # 1111 1111 1110 0001 (reset bits 4-1)
sll $t3, $t0, 1 # shift do contador para os bits 4-1 sll $t2, $t0, 1 # shift do contador para os bits 4-1
or $t2, $t2, $t3 # merge contador com valor do LATE or $t1, $t1, $t2 # merge contador com valor do LATE
sw $t2, LATE($t7) # atualiza valor do LATE sw $t1, LATE($t7) # atualiza valor do LATE
li $v0, RESET_CORE_TIMER li $v0, RESET_CORE_TIMER
syscall syscall
@ -45,16 +35,15 @@ loop:
delay: delay:
li $v0, READ_CORE_TIMER li $v0, READ_CORE_TIMER
syscall syscall
move $t6, $v0 move $t2, $v0
blt $t6, 13333333, delay blt $t2, 13333333, delay
lw $t4, LATE($t7) # ler valor dos leds andi $t1, $t1, 0x0010 # isolar bit 4
andi $t4, $t4, 0x0010 # isolar bit 4 srl $t1, $t1, 4 # colocar bit na posição menos significativa para o contador
srl $t4, $t4, 4 # colocar bit na posição menos significativa para o contador xori $t1, $t1, 0x0001 # negar bit
xori $t4, $t4, 0x0001 # negar bit
sll $t0, $t0, 1 # shift left do contador sll $t0, $t0, 1 # shift left do contador
or $t0, $t0, $t4 # colocar bit lido no contador or $t0, $t0, $t1 # colocar bit lido no contador
j loop j loop

View File

@ -1,19 +1,9 @@
.equ ADDR_BASE, 0xBF88 .equ ADDR_BASE, 0xBF88
.equ TRISB, 0x6040
.equ PORTB, 0x6050
.equ LATB, 0x6060
.equ TRISC, 0x6080
.equ PORTC, 0x6090
.equ LATC, 0x60A0
.equ TRISD, 0x60C0
.equ PORTD, 0x60D0
.equ LATD, 0x60E0
.equ TRISE, 0x6100 .equ TRISE, 0x6100
.equ PORTE, 0x6110
.equ LATE, 0x6120 .equ LATE, 0x6120
.equ READ_CORE_TIMER, 11 .equ READ_CORE_TIMER, 11
.equ RESET_CORE_TIMER, 12 .equ RESET_CORE_TIMER, 12
.data .data
.text .text
@ -33,11 +23,11 @@ main:
li $t0, 0x0010 # Iniciar contagem li $t0, 0x0010 # Iniciar contagem
loop: loop:
lw $t2, LATE($t7) lw $t1, LATE($t7)
andi $t2, $t2, 0xFFE1 # 1111 1111 1110 0001 (reset bits 4-1) andi $t1, $t1, 0xFFE1 # 1111 1111 1110 0001 (reset bits 4-1)
sll $t3, $t0, 1 # shift do contador para os bits 4-1 sll $t2, $t0, 1 # shift do contador para os bits 4-1
or $t2, $t2, $t3 # merge contador com valor do LATE or $t1, $t1, $t2 # merge contador com valor do LATE
sw $t2, LATE($t7) # atualiza valor do LATE sw $t1, LATE($t7) # atualiza valor do LATE
li $v0, RESET_CORE_TIMER li $v0, RESET_CORE_TIMER
syscall syscall
@ -45,16 +35,15 @@ loop:
delay: delay:
li $v0, READ_CORE_TIMER li $v0, READ_CORE_TIMER
syscall syscall
move $t6, $v0 move $t2, $v0
blt $t6, 13333333, delay blt $t2, 13333333, delay
lw $t4, LATE($t7) andi $t1, $t1, 0x0002 # isolar bit 1
andi $t4, $t4, 0x0002 sll $t1, $t1, 2 # colocar bit na posição mais significativa para o contador
sll $t4, $t4, 2 xori $t1, $t1, 0x0008 # negar bit
xori $t4, $t4, 0x0008 srl $t0, $t0, 1 # shift right do contador
srl $t0, $t0, 1 or $t0, $t0, $t1 # colocar bit lido no contador
or $t0, $t0, $t4
j loop j loop

View File

@ -1,19 +1,11 @@
.equ ADDR_BASE, 0xBF88 .equ ADDR_BASE, 0xBF88
.equ TRISB, 0x6040 .equ TRISB, 0x6040
.equ PORTB, 0x6050 .equ PORTB, 0x6050
.equ LATB, 0x6060
.equ TRISC, 0x6080
.equ PORTC, 0x6090
.equ LATC, 0x60A0
.equ TRISD, 0x60C0
.equ PORTD, 0x60D0
.equ LATD, 0x60E0
.equ TRISE, 0x6100 .equ TRISE, 0x6100
.equ PORTE, 0x6110
.equ LATE, 0x6120 .equ LATE, 0x6120
.equ READ_CORE_TIMER, 11 .equ READ_CORE_TIMER, 11
.equ RESET_CORE_TIMER, 12 .equ RESET_CORE_TIMER, 12
.data .data
.text .text
@ -30,18 +22,18 @@ main:
andi $t0, $t0, 0xFFE1 # 1111 1111 1110 0001 (isola bits 4-1) andi $t0, $t0, 0xFFE1 # 1111 1111 1110 0001 (isola bits 4-1)
sw $t0, TRISE($t7) # Configura RE4-RE1 como output sw $t0, TRISE($t7) # Configura RE4-RE1 como output
lw $t1, TRISB($t7) lw $t0, TRISB($t7)
ori $t1, $t1, 0x0004 # 0000 0000 0000 0010 (isola bit 1) ori $t0, $t0, 0x0004 # 0000 0000 0000 0010 (isola bit 1)
sw $t1, TRISB($t7) # Configura RB1 como input sw $t0, TRISB($t7) # Configura RB1 como input
li $t0, 0x0010 # Iniciar contagem li $t0, 0x0010 # Iniciar contagem
loop: loop:
lw $t2, LATE($t7) lw $t1, LATE($t7)
andi $t2, $t2, 0xFFE1 # 1111 1111 1110 0001 (reset bits 4-1) andi $t1, $t1, 0xFFE1 # 1111 1111 1110 0001 (reset bits 4-1)
sll $t3, $t0, 1 # shift do contador para os bits 4-1 sll $t2, $t0, 1 # shift do contador para os bits 4-1
or $t2, $t2, $t3 # merge contador com valor do LATE or $t1, $t1, $t2 # merge contador com valor do LATE
sw $t2, LATE($t7) # atualiza valor do LATE sw $t1, LATE($t7) # atualiza valor do LATE
li $v0, RESET_CORE_TIMER li $v0, RESET_CORE_TIMER
syscall syscall
@ -49,32 +41,30 @@ loop:
delay: delay:
li $v0, READ_CORE_TIMER li $v0, READ_CORE_TIMER
syscall syscall
move $t6, $v0 move $t2, $v0
blt $t6, 13333333, delay blt $t2, 13333333, delay
switch_check: switch_check:
lw $t6, PORTB($t7) lw $t2, PORTB($t7)
andi $t6, $t6, 0x0004 # 0000 0000 0000 0100 (isola bit 3) andi $t2, $t2, 0x0004 # 0000 0000 0000 0100 (isola bit 3)
lw $t4, LATE($t7) beqz $t2, move_right # switch3 = 0: move_right, switch3 = 1: move_left
beqz $t6, move_right
move_left: move_left:
andi $t4, $t4, 0x0010 andi $t1, $t1, 0x0010 # isolar bit 4
srl $t4, $t4, 4 srl $t1, $t1, 4 # colocar bit na posição menos significativa para o contador
xori $t4, $t4, 0x0001 xori $t1, $t1, 0x0001 # negar bit
sll $t0, $t0, 1 sll $t0, $t0, 1 # shift left do contador
or $t0, $t0, $t4
j switch_end j switch_end
move_right: move_right:
andi $t4, $t4, 0x0002 andi $t1, $t1, 0x0002 # isolar bit 1
sll $t4, $t4, 2 sll $t1, $t1, 2 # colocar bit na posição mais significativa para o contador
xori $t4, $t4, 0x0008 xori $t1, $t1, 0x0008 # negar bit
srl $t0, $t0, 1 srl $t0, $t0, 1 # shift right do contador
or $t0, $t0, $t4
switch_end: switch_end:
or $t0, $t0, $t1 # colocar bit lido no contador
j loop j loop