From b4baeb6624cead59b0698902b179d9541d13ad70 Mon Sep 17 00:00:00 2001 From: Roberto Hexsel <roberto@inf.ufpr.br> Date: Thu, 12 Nov 2015 10:37:29 -0200 Subject: [PATCH] now reads from stdin, cMIPS.{h,c} --- cMIPS/include/cMIPS.h | 4 ++-- cMIPS/include/cMIPS.s | 2 +- cMIPS/include/cMIPSio.c | 30 +++++++++++------------------- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/cMIPS/include/cMIPS.h b/cMIPS/include/cMIPS.h index f6791e2..9a881a5 100644 --- a/cMIPS/include/cMIPS.h +++ b/cMIPS/include/cMIPS.h @@ -1,6 +1,6 @@ #define x_INST_BASE_ADDR 0x00000000 -#define x_DATA_BASE_ADDR 0x00020000 +#define x_DATA_BASE_ADDR 0x00010000 #define x_IO_BASE_ADDR 0x0F000000 #define x_IO_MEM_SZ 0x00002000 #define x_IO_ADDR_RANGE 0x00000020 @@ -24,7 +24,7 @@ extern void exit(int); extern void print(int); extern void to_stdout(char c); -extern int from_stdin(char *); +extern int from_stdin(void); extern void writeInt(int); extern void writeClose(void); diff --git a/cMIPS/include/cMIPS.s b/cMIPS/include/cMIPS.s index 21de4c6..fd744cd 100644 --- a/cMIPS/include/cMIPS.s +++ b/cMIPS/include/cMIPS.s @@ -3,7 +3,7 @@ .set x_INST_BASE_ADDR,0x00000000 .set x_INST_MEM_SZ,0x00004000 - .set x_DATA_BASE_ADDR,0x00020000 + .set x_DATA_BASE_ADDR,0x00010000 .set x_DATA_MEM_SZ,0x00008000 .set x_IO_BASE_ADDR,0x0F000000 diff --git a/cMIPS/include/cMIPSio.c b/cMIPS/include/cMIPSio.c index c1f74aa..8c8103e 100644 --- a/cMIPS/include/cMIPSio.c +++ b/cMIPS/include/cMIPSio.c @@ -16,11 +16,12 @@ //======================================================================= // simulator's STD_INPUT and STD_OUTPUT //======================================================================= -// write an integer (hex) to VHDL simulator's standard output -void print(int n) { - int *IO = (int *)IO_PRINT_ADDR; - - *IO = n; +// read a character from VHDL simulator's standard input +int from_stdin(void) { + int *IO = (void *)IO_STDIN_ADDR; + + // gets line line only after receiving a '\n' (line-feed, 0x0a) + return( *IO ); } // write a character to VHDL simulator's standard output @@ -31,21 +32,12 @@ void to_stdout(char c) { *IO = (unsigned char)c; } -// read a character from VHDL simulator's standard input -// return value = 1 if EnoOfFile, 0 otherwise -// character read is stored at address provided in argument -int from_stdin(char *c) { - int *IO = (int *)IO_STDIN_ADDR; - int status, value; - - value = *IO; - status = *(IO + 1); +// write an integer (hex) to VHDL simulator's standard output +void print(int n) { + int *IO = (int *)IO_PRINT_ADDR; - if (status == 0) { - *c = (unsigned char)value; - } - return status; -}; //-------------------------------------------------------------------- + *IO = n; +} //======================================================================= -- GitLab