From a996f5b7681a7d861d003fb5b6ff27ff4f5ea130 Mon Sep 17 00:00:00 2001 From: Strozzi <laps15@inf.ufpr.br> Date: Mon, 23 May 2016 21:57:11 -0300 Subject: [PATCH] Fix main to final version \(\!\?\) --- cMIPS/include/main.c | 59 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/cMIPS/include/main.c b/cMIPS/include/main.c index 99ada01..3ba007c 100644 --- a/cMIPS/include/main.c +++ b/cMIPS/include/main.c @@ -1,12 +1,24 @@ -#include<stdio.h> +#include "cMIPS.h" #include "vetorFib.h" #define MAXPOW 7 +typedef struct UARTdriver { +int rx_hd ; // reception queue head index +int rx_tl ; // reception queue tail index +char rx_q [16]; // reception queue +int tx_hd ; // transmission queue head index +int tx_tl ; // transmission queue tail index +char tx_q [16]; // transmission queue +int nrx ; // number of characters in rx_queue +int ntx ; // number of spaces in tx_queue +} UARTdriver ; +extern UARTdriver Ud ; + int Strlen(char *c) { int i= 0; - while(c[i++]); + while(c[i++]-10); return i-1; } @@ -51,21 +63,48 @@ int int2hex(char *c, int i) c[j++] = 'a'+ (val-10); p/=16; } - c[j] = 0; + c[j] = 10; return j-1; } int main() { - char n[16], f[16]; - int fib; - while (scanf("%s", n) && n[0]) { // trocar scanf por getc() + char n[16], f[16], c; + int fib, j, s; + while (1) { + j= 0; + while ((n[j++]= getFila()) != '\n'); + n[j] = '\n' + if (n[0] == 10) // critério de fim de transmissão + break; fib= hex2int(n); if (fib < BUF_SZ) { fib = buf[fib]; - int2hex(f, fib); - printf("%d(%s)\n", fib, f); // trocar printf por putc() - } else - printf("Valor fora dos limites!\n"); + s= int2hex(f, fib); //retorna strlen de f + for (j= 0; j< s; j++) + putc(f[j]); + } else { + to_stdout('v'); + to_stdout('a'); + to_stdout('l'); + to_stdout('o'); + to_stdout('r'); + to_stdout(' '); + to_stdout('m'); + to_stdout('u'); + to_stdout('i'); + to_stdout('t'); + to_stdout('o'); + to_stdout(' '); + to_stdout('g'); + to_stdout('r'); + to_stdout('a'); + to_stdout('n'); + to_stdout('d'); + to_stdout('e'); + to_stdout('\n'); + } } + // sleep?? + return 0; } -- GitLab