Skip to content

Commit

Permalink
AC files, AED2 monitoria Files
Browse files Browse the repository at this point in the history
  • Loading branch information
NBO2001 committed Jan 14, 2024
1 parent 230bdf2 commit 5cb5bd8
Show file tree
Hide file tree
Showing 80 changed files with 2,206,342 additions and 0 deletions.
213 changes: 213 additions & 0 deletions AC/Natanael_Bezerra/vida_menos_menos.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
.data
matrixA: .word32 2,1,0,5,3,4,1,6,5,6,3,8,7,8,5, 10
matrixB: .word32 0,3,5,21,1,2,8,13,2,1,13,8,3,0,-21,5
matrixR: .word32 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0
ordem: .byte 4

; Espaco para o print da matriz, um pouquinho grande, pois pode ter valores muito grandes
matrix: .space 128

params_format: .space 8
params_sys5: .space 8

; O codigo demora um pouquinho para terminar. haha

.code
LB $s0, ordem($zero) ; ordem da matrix
ADDI $t1, $zero, 0x4
MULT $s0, $t1
MFLO $t1

MULT $s0, $s0
MFLO $s0

; Inicializaccao das variaveis
ADDI $s2, $zero, 0x4
MULT $s0, $s2 ; Tamanho total da matriz
MFLO $s1 ; tam==s1
ADD $s2, $zero, $zero ; so para dizer q (column_control==s2) recebe zero
ADD $s3, $zero, $t1 ; loop_control==s3
ADD $s4, $zero, $zero ; so para dizer q (i_start==s4) recebe zero
ADD $s5, $zero, $zero ; so para dizer q (b_control==s5) recebe zero
ADD $s6, $zero, $zero ; so para dizer q (a_control==s6) recebe zero

; multiplicao das matrizes, tres loops, percorrendo as colunas ordem vezes

tercWhileStart:
SLT $a0, $s2, $t1 ; column_control < ordem
BEQZ $a0, tercWhileEnd ; while

secondWhileStart:
SLT $a0, $s6, $s1 ; a_control < tam
BEQZ $a0, secondWhileEnd ; while

ADD $t0, $zero, $s4 ; i = i_start

fistWhileStart:
SLT $a0, $t0, $s3 ; i < loop_control
BEQZ $a0, firstWhileEnd ; while

LH $a1, matrixA($s6) ; matrixA[a_control]
LH $a2, matrixB($s5) ; matrixB[b_control]
MULT $a1, $a2
MFLO $a1
LH $a2, matrixR($t0)
ADD $a2, $a2, $a1
SW $a2, matrixR($t0)

ADDI $s6, $s6, 0x4 ; a_control += 4
ADDI $t0, $t0, 0x4 ; i += 4

B fistWhileStart

firstWhileEnd:
ADDI $s5, $s5, 0x4; b_control += 1
B secondWhileStart

secondWhileEnd:
ADD $s3, $s3, $t1 ; loop_control += ordem


ADD $s4, $s4, $t1 ; i_start += ordem

ADD $s6, $zero, $zero ; a_control = 0
ADDI $s2, $s2, 0x4 ; column_control += 4
B tercWhileStart
tercWhileEnd: B print_f

final_code: SYSCALL 0


; Convert os caracteres para asciiz e mostra o resultado
print_f: XOR $s5,$s5,$s5
ADD $s0, $zero, $zero ; i = 0
ADDI $s2, $zero, 0x4
LB $s4, ordem($zero) ; ordem da matrix
MULT $s4,$s4
MFLO $t5


start_loop_1: SLT $t0, $s0, $s4 ; i < ordem
BEQZ $t0, finalLoop
ADD $s3, $zero, $s0

start_loop_2: SLT $t0, $s3, $t5 ; i < ordem
BEQZ $t0, final_loop_2

MULT $s3, $s2
MFLO $t0


LH $s1, matrixR($t0)
JAL conv_for_ascii
JAL func_add_wd
JAL verify_is_full

XOR $v0, $v0,$v0
XOR $v1, $v1,$v1
ADDI $v0, $zero, 0x20
ADDI $v1, $zero, 0x8
JAL func_add_wd
JAL verify_is_full


ADD $s3, $s3, $s4
B start_loop_2
final_loop_2:
ADDI $s0, $s0, 0x1

XOR $v0, $v0,$v0
XOR $v1, $v1,$v1
ADDI $v0, $zero, 0xa
ADDI $v1, $zero, 0x8
JAL func_add_wd
JAL verify_is_full

B start_loop_1

finalLoop: JAL func_add_wd
JAL move_restante

daddi $a3, $zero, matrix
sw $a3, params_sys5($zero)
daddi $t6, $zero, params_sys5
syscall 5

B final_code




move_restante: SD $s6, matrix($s5)
XOR $s6,$s6,$s6
XOR $s7,$s7,$s7
JALR $ra


; guarda em $s5 o index do vetor de caracteres
verify_is_full: SLTI $t0, $s7, 0x40
BNEZ $t0, end_the_func
SD $s6, matrix($s5)
ADDI $s5, $s5, 0x8
DADD $s6,$zero,$v0 ; --Remove
DADD $s7,$zero,$v1 ; --Remove
end_the_func: JALR $ra

; A funcao usa o registrador $s7 para manter o tamanho da palavra e $s6 para a palavra
; E pega o valor de $v0 e $v1
func_add_wd: ADDI $t0, $zero, 0x40 ; maximo de uma palavra
DSUB $t1, $t0, $s7
ADDI $t1, $t1, 0x1
SLT $t2, $v1, $t1
BEQZ $t2, nao_tem_spaco
DSLLV $v0, $v0, $s7
DADD $s6, $s6, $v0
DADD $s7, $s7, $v1
XOR $v0,$v0,$v0
XOR $v1,$v1,$v1
JALR $ra

nao_tem_spaco: DSUB $t3, $v1, $t1
DADD $t4, $zero, $v0
DSLLV $t4, $v0, $s7
DADD $s6, $s6, $t4
DADD $v1, $zero, $t3
ADDI $v1, $v1, 1
ADDI $t1, $t1, -1
DSRLV $v0, $v0, $t1
DADD $s7, $zero, $t0
JALR $ra




; convert o que estar em $s1 para codigo asciiz
conv_for_ascii: ADDI $t0, $zero, 0xa
DADDI $v1, $zero, 0x0
DADD $v0, $zero, $zero
ADDI $t1, $zero, 0x1
ADDI $t2, $zero, 0x1f
DSLLV $t1,$t1, $t2
AND $a1, $s1,$t1
ADDI $t7, $zero, 0x0 ; numero positivo

BEQZ $a1, eh_positivo
ADDI $a1, $zero, -1
MULT $s1, $a1
MFLO $s1
ADDI $t7, $zero, 0x1 ; numero negativo

eh_positivo: DSLL $v0, $v0, 0x8
DADDI $v1, $v1, 0x8
DIV $s1, $t0
MFHI $a2
DADDI $a2, $a2, 0x30
DADD $v0, $v0, $a2
MFLO $s1
BNEZ $s1, eh_positivo
BEQZ $t7, final_func
DSLL $v0, $v0, 0x8
DADDI $v1, $v1, 0x8
DADDI $v0, $v0, 0x2d

final_func: JALR $ra
1 change: 1 addition & 0 deletions AC/arduino/TP4 - Natanael_Bezerra_de_Oliveira
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://www.tinkercad.com/things/jC7WbOeXouO?sharecode=5rqIEvADxqmo7RrdhNBts6Q0fT14v_kUorh94Yx4Wwc
145 changes: 145 additions & 0 deletions AC/arduino/refcto.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#define PIN_A 13
#define PIN_WHITE 12
#define PIN_BLACK 8
#define PINO_BOTAO_BLACK 2
#define PINO_BOTAO_WHITE 3


volatile bool blackBtnUpper = false;
volatile bool whiteBtnUpper = false;
volatile bool fistClick = true;
volatile bool started = false;
volatile bool timeBurst = false;
volatile unsigned long int timeWhite = 180000;
volatile unsigned long int timeBlack = 180000;
volatile unsigned long int baseLine = 0;
volatile unsigned long int nextPrint = 0;
volatile unsigned long int timemReference = 0;



void setup() {
Serial.begin(9600);
pinMode(PIN_WHITE, OUTPUT);
pinMode(PIN_BLACK, OUTPUT);
pinMode(PINO_BOTAO_BLACK, INPUT_PULLUP);
pinMode(PINO_BOTAO_WHITE, INPUT_PULLUP);

digitalWrite(PIN_WHITE, LOW);
digitalWrite(PIN_BLACK, LOW);

attachInterrupt(digitalPinToInterrupt(PINO_BOTAO_BLACK), btnWhitePlayer, FALLING);
attachInterrupt(digitalPinToInterrupt(PINO_BOTAO_WHITE), btnBlackPlayer, RISING);
}

void loop() {

// Se o tempo estiver estourado não faz nada.
if(timeBurst){
return;
}

if (started && millis() >= nextPrint) {
printTimeOfThePlayer();
nextPrint += 1000;
}

// Se o negocio dos tiver levantado, significa que o branco está jogando
if (blackBtnUpper) {

// Se ainda não tiver começado, comece
if (!started) {
started = true;
nextPrint = baseLine;
}

// Reduz 1 segundo
if(millis() >= timemReference ){
timemReference += 1000;
timeWhite -= 1000;
}

if(timeWhite <= 0){
Serial.println("O tempo das Brancas acabou. As Pretas ganharam!");
timeBurst = true;
digitalWrite(PIN_WHITE, LOW);
digitalWrite(PIN_BLACK, LOW);
}else{
digitalWrite(PIN_WHITE, HIGH);
digitalWrite(PIN_BLACK, LOW);
}


}

if (started && whiteBtnUpper) {

if(millis() >= timemReference ){
timemReference += 1000;
timeBlack -= 1000;
}

if(timeBlack <= 0){
Serial.println("O tempo das Pretas acabou. As Brancas ganharam!");
timeBurst = true;
digitalWrite(PIN_WHITE, LOW);
digitalWrite(PIN_BLACK, LOW);
}else{
digitalWrite(PIN_WHITE, LOW);
digitalWrite(PIN_BLACK, HIGH);
}


}


}

void printTime(unsigned long int time) {
unsigned long seconds = time / 1000;
unsigned long minutes = seconds / 60;
seconds %= 60;

if (minutes < 10) {
Serial.print("0");
}
Serial.print(minutes);
Serial.print(":");
if (seconds < 10) {
Serial.print("0");
}
Serial.print(seconds);
}

void printTimeOfThePlayer() {
Serial.print("Brancas ");
printTime(timeWhite);
Serial.print(" VS ");
printTime(timeBlack);
Serial.println(" Pretas");
}

void btnWhitePlayer() {
if(!fistClick && !blackBtnUpper && whiteBtnUpper){
timeBlack += 3000;
}
fistClick = false;
baseLine = millis();
timemReference = baseLine;
blackBtnUpper = true;
whiteBtnUpper = false;
}

void btnBlackPlayer() {

baseLine = millis();
timemReference = baseLine;

if(blackBtnUpper && !whiteBtnUpper){
timeWhite += 3000;
}


blackBtnUpper = false;
whiteBtnUpper = true;
}
Loading

0 comments on commit 5cb5bd8

Please sign in to comment.