From 26a2fa71385f90e1c549eb7159829ed68eb97450 Mon Sep 17 00:00:00 2001 From: Dan White Date: Thu, 16 May 2013 01:49:46 -0500 Subject: [PATCH] msp4th: bugfix do-loop, gcc optimizes too much --- msp4th/bootrom.rcf | 178 ++++++++++++++++++++++----------------------- msp4th/cosim.py | 10 --- msp4th/main.c | 5 +- msp4th/msp4th.c | 23 +++--- msp4th/test4th.c | 34 ++++++--- 5 files changed, 127 insertions(+), 123 deletions(-) diff --git a/msp4th/bootrom.rcf b/msp4th/bootrom.rcf index 92cdcb3..4fcbaf0 100644 --- a/msp4th/bootrom.rcf +++ b/msp4th/bootrom.rcf @@ -148,11 +148,11 @@ 0100000010110010 0011000101101110 0100010001011010 +0100001110000010 +0100000001100010 0100001111000010 0100001110100100 0100001111000010 -0100010000100100 -0100001111000010 0100001100100100 0100000000111111 0100010001000100 @@ -288,7 +288,7 @@ 0100111101001011 1001001110000010 0100000000001100 -0010010000010100 +0010010000011100 1001001001111111 0010000000001111 1001001000011001 @@ -305,12 +305,20 @@ 0100000000000010 0101001110110010 0100000000001010 -0011110000101000 +0011110000100110 0100101101001111 0001001010010010 0100000000000010 1001000001111011 0000000000001101 +0010000000001000 +0100000001111111 +0000000000001010 +0001001010010010 +0100000000000010 +0011110000001100 +1001000001111111 +0000000000001101 0010010000001001 1001000001111011 0000000000001010 @@ -320,18 +328,8 @@ 0101001100111111 1001111110000010 0100000000001010 -0011100000001011 -1001001110000010 -0100000000001100 -0010010000000110 -0100000001111111 -0000000000001010 -0001001010010010 -0100000000000010 +0011100000000001 0100001100001010 -0011110000000010 -0100001000011010 -0100000000001100 0100001000011111 0100000000001010 0100001000011110 @@ -347,7 +345,7 @@ 0100001111001111 0000000000000000 1001001100001010 -0010001110111111 +0010001111000001 0100101010000010 0100000000001010 0100000100111001 @@ -378,35 +376,32 @@ 0100000000001010 0100000100110000 0001001000001011 -0001001010110000 -0011001011001000 0100000001111011 0000000000100000 -0011110000000010 0001001010110000 -0011001011001000 +0011001011000100 1001111101001011 0010111111111100 0100000100111011 0100000100110000 0001001010110000 -0011001011001000 +0011001011000100 1001000001111111 0000000000101001 0010001111111011 0001001010110000 -0011001011110110 +0011001011110010 0100000100110000 0001001000001011 0001001000001010 0011110000000101 0001001010110000 -0011001100001110 +0011001100000100 0011110000000100 0001001010110000 0011001000001110 0001001010110000 -0011001011110110 +0011001011110010 1001000001111111 0000000000101000 0010011111110110 @@ -428,7 +423,7 @@ 0100001111001111 0000000000000000 0001001010110000 -0011001011001000 +0011001011000100 1001111101001010 0010110000000011 1001001000011011 @@ -525,7 +520,7 @@ 0011110011001110 0100101000001111 0001001010110000 -0011001110110100 +0011001110101010 0100111100001001 1001001100001111 0010010000000011 @@ -536,7 +531,7 @@ 0011110111111110 0100101000001111 0001001010110000 -0011001110110100 +0011001110101010 0100111100001011 1001100100001111 0010010000000011 @@ -547,14 +542,14 @@ 0100000000011110 0100101000001111 0001001010110000 -0011001110110100 +0011001110101010 1001101100001111 0010010000000011 0001001010110000 -0011001110010100 +0011001110001010 0100001100011111 0001001010110000 -0011001110010100 +0011001110001010 0100000100111001 0100000100111010 0100000100111011 @@ -562,7 +557,7 @@ 0001001000001011 0001001000001010 0001001010110000 -0011001110001000 +0011001101111110 1001000000111111 0100111000100000 0011100000000101 @@ -714,10 +709,10 @@ 0011110000000001 0100001100011011 0001001010110000 -0011001110010100 +0011001110001010 0100101100001111 0001001010110000 -0011001110010100 +0011001110001010 0100000100111010 0100000100111011 0100000100110000 @@ -743,7 +738,7 @@ 1001001100011111 0010010000000100 0001001010110000 -0011001110001000 +0011001101111110 1001001100001111 0010000000000010 0100101110000010 @@ -757,19 +752,24 @@ 0101110000101101 0100110110001100 0000000000000000 -1001001100001111 -0011100000000101 +1001001100011111 +0011100000000100 1001011100011101 0000000000000100 -0011010000000111 +0011010000001001 +0011110000000101 1001001100001111 -0010000000000011 -1001110110001110 +0010010000000110 +1001110110000111 0000000000000100 -0011010000000010 +0011010000000011 0100111010100010 0100000000011100 0100000100110000 +0100111000000111 +0101000000110111 +0000000000000110 +0100000100110000 0100011000001110 0101111100001111 0101011000001111 @@ -802,7 +802,7 @@ 0100111010000010 0100000000011100 0001001010110000 -0011001110010100 +0011001110001010 0100000100110000 0100001100001101 0011110000000111 @@ -840,7 +840,7 @@ 0100001000011111 0100000000000110 0001001010110000 -0011001110110100 +0011001110101010 0101111100001111 0101001000011111 0100000000100000 @@ -1045,7 +1045,7 @@ 1000011010100110 0000000000000010 0001001010110000 -0011001110001000 +0011001101111110 0100000000110000 0011110000011110 1100001000110010 @@ -1076,7 +1076,7 @@ 0100000000110000 0011110000011110 0001001010110000 -0011001110001000 +0011001101111110 0001001010110000 0011011010100100 0100000000110000 @@ -1093,20 +1093,20 @@ 0100000000110000 0011110000011110 0001001010110000 -0011001110001000 +0011001101111110 0100011000001110 1001111110000110 0000000000000000 0011010000010000 0011110000001011 0001001010110000 -0011001110001000 +0011001101111110 0100011000001110 1001011000101111 0011010000001010 0011110000000101 0001001010110000 -0011001110001000 +0011001101111110 0100011000001110 1001011000101111 0010000000000100 @@ -1119,12 +1119,12 @@ 0100000000110000 0011110000011110 0001001010110000 -0011001110001000 +0011001101111110 0001001010110000 0011011100110000 0011110001110010 0001001010110000 -0011001100011110 +0011001100010100 0100000000110000 0011110000011110 0001001010110000 @@ -1150,7 +1150,7 @@ 0101001000011011 0100000000001000 0001001010110000 -0011001110001000 +0011001101111110 0100111110001011 0000000000000000 0101001100011010 @@ -1167,10 +1167,10 @@ 0100000000110000 0011110000011110 0001001010110000 -0011001110001000 +0011001101111110 0100111100001011 0001001010110000 -0011001110001000 +0011001101111110 0100101100001110 0101111000001110 0101001000011110 @@ -1189,7 +1189,7 @@ 0100000000110000 0011110000011110 0001001010110000 -0011001101101110 +0011001101100100 0100000000110000 0011110000011110 0100001100001111 @@ -1198,10 +1198,10 @@ 0100000000011100 0011110001111001 0001001010110000 -0011001110011100 +0011001110010010 0100111100001011 0001001010110000 -0011001110001000 +0011001101111110 1001001100001111 0010010000000010 0100000000110000 @@ -1230,11 +1230,11 @@ 0001000000001110 0100111000001111 0001001010110000 -0011001110010100 +0011001110001010 0100000000110000 0011110000011110 0001001010110000 -0011001110001000 +0011001101111110 0001001010110000 0011011101001110 0100000001111111 @@ -1244,14 +1244,14 @@ 0100000000110000 0011110000011110 0001001010110000 -0011010011110100 +0011010011101010 0100000000110000 0011110000011110 0100001100001111 0011111111101100 0100001100011111 0001001010110000 -0011010110100110 +0011010110011100 0100000000110000 0011110000011110 0001001010110000 @@ -1259,7 +1259,7 @@ 0100000000110000 0011110000011110 0001001010110000 -0011010000001100 +0011010000000010 0100000000110000 0011110000011110 0001001010110000 @@ -1279,11 +1279,11 @@ 0100001000011011 0100000000000010 0001001010110000 -0011001110001000 +0011001101111110 0001001010001011 0011110100001011 0001001010110000 -0011001110011100 +0011001110010010 0100111110000010 0100000000011100 0011110100000110 @@ -1294,10 +1294,10 @@ 0000000000000000 0011110100000000 0001001010110000 -0011001110001000 +0011001101111110 0100111100001011 0001001010110000 -0011001110001000 +0011001101111110 0100101100001110 1111000000111110 1111111111111110 @@ -1306,27 +1306,27 @@ 0100000000100010 0011111110110100 0001001010110000 -0011001110001000 +0011001101111110 0100111100001010 0001001010110000 -0011001110001000 +0011001101111110 0100001000011011 0100000000011100 0001001010110000 -0011001110100010 +0011001110011000 0100101000001111 0001001010110000 -0011001110100010 +0011001110011000 0100101100001111 0001001010110000 -0011001110100010 +0011001110011000 0011110011100100 0100001100011111 0011110000000010 0001001010110000 -0011001110001000 +0011001101111110 0001001010110000 -0011010111100000 +0011010111010110 0011110011011101 0100011100011111 0000000000000010 @@ -1351,7 +1351,7 @@ 0011111011001111 1100001000110010 0001001010110000 -0011001110001000 +0011001101111110 0100111110000010 0000000100110010 0100011010010010 @@ -1376,7 +1376,7 @@ 0011111110001010 0100110000001011 0001001010110000 -0011001110001000 +0011001101111110 0100101110000110 0000000000000000 0011110010101001 @@ -1450,27 +1450,27 @@ 0000000000000011 0000000000000000 0001001010110000 -0011001110101010 +0011001110100000 0011110001100001 0001000010000110 0011110001011111 0001001010110000 -0011001110001000 +0011001101111110 0100111100001011 0001001010110000 -0011001110001000 +0011001101111110 0100101100001110 0101111000001110 0101111110001110 0000000000000000 0011110001010101 0001001010110000 -0011001110001000 +0011001101111110 0001001010110000 0011011000001000 0011110001010000 0001001010110000 -0011001110001000 +0011001101111110 0101111100001111 0101011000001111 0100111100101111 @@ -1479,21 +1479,21 @@ 0000000000000010 0100011000101111 0001001010110000 -0011001110010100 +0011001110001010 0100011010100110 0000000000000100 0100101110000110 0000000000000010 0011110001000000 0001001010110000 -0011001110001000 +0011001101111110 0100011000001110 1001111110000110 0000000000000000 0011010000111010 0011110000000101 0001001010110000 -0011001110001000 +0011001101111110 0100011000001110 1001011000101111 0011010000110100 @@ -1531,7 +1531,7 @@ 0000000000000000 0011110000010011 0001001010110000 -0011001110001000 +0011001101111110 0100111110000010 0100000000001100 0011110000001110 @@ -1540,15 +1540,15 @@ 0100001111001111 0000000000000000 0001001010110000 -0011001110001000 +0011001101111110 0001001010110000 0011000110100000 0011110000000101 0001001010110000 -0011010001100010 +0011010001011000 0011110000000010 0001001010110000 -0011010011011010 +0011010011010000 0100000100111000 0100000100111001 0100000100111010 @@ -1556,7 +1556,7 @@ 0100000100110000 0001001000001011 0001001010110000 -0011001110001000 +0011001101111110 0100111100001011 1001000000111111 0100111000100000 @@ -1572,7 +1572,7 @@ 0100001000011111 0100000000011100 0001001010110000 -0011001110100010 +0011001110011000 0101101100001011 0101000000111011 1110111111101000 @@ -1580,7 +1580,7 @@ 0100001000011111 0100000000011100 0001001010110000 -0011001110100010 +0011001110011000 0101101100001011 0101001000011011 0100000000100000 @@ -1623,7 +1623,7 @@ 0011011101100100 0011110000001000 0001001010110000 -0011001110100010 +0011001110011000 0100101100001111 0101111100001111 0101001000011111 diff --git a/msp4th/cosim.py b/msp4th/cosim.py index 1a327f6..e8c4192 100644 --- a/msp4th/cosim.py +++ b/msp4th/cosim.py @@ -70,19 +70,9 @@ try: s += '\r' for n in (pc, atoi): - #for n in (pc, ): send(n, s) - if s.startswith('bye'): - #things don't match after this - break prompt(n) - if 0: - print - print 's :', s.rstrip() - print 'pc :', pc.before - print 'atoi:', atoi.before - print_side(atoi.before, pc.before) diff --git a/msp4th/main.c b/msp4th/main.c index f8eb53f..e14e849 100644 --- a/msp4th/main.c +++ b/msp4th/main.c @@ -136,9 +136,12 @@ static __inline__ void setup_default_msp4th(void) default_config.getchar = &uart_getchar; default_config.puts = &uart_puts; + // stack top is zero + mathStackArray[MATH_STACK_SIZE - 1] = 0; + // terminate the strings lineBufferArray[0] = 0; - wordBufferArray[0] = 0; + //wordBufferArray[0] = 0; cmdListArray[0] =0; diff --git a/msp4th/msp4th.c b/msp4th/msp4th.c index b7ebda7..681ec1a 100644 --- a/msp4th/msp4th.c +++ b/msp4th/msp4th.c @@ -59,7 +59,7 @@ int16_t cmdListIdx; // next open space for user word strings /* The following allow re-configuring the location/size of all configurable * arrays. Then the stack sizes and user program space sizes can be - * (re-)specified by changing the table and calling init_msp4th() again. See + * (re-)specified by changing the table and calling msp4th_init() again. See * test430.c for a configuration example. * * THE ONLY BOUNDARY CHECKS ARE: @@ -398,7 +398,7 @@ void msp4th_init(struct msp4th_config *c) * table locations. * * Changing the values in the msp4th_* locations and calling - * init_msp4th() again restarts the interpreter with the new layout; + * msp4th_init() again restarts the interpreter with the new layout; */ mathStackPtr = c->mathStackStart; addrStackPtr = c->addrStackStart; @@ -525,10 +525,9 @@ uint8_t nextPrintableChar(void) { uint8_t c; - c = getKeyB(); - while (c <= ' ') { + do { c = getKeyB(); - } + } while (c <= ' '); return (c); } @@ -538,10 +537,9 @@ uint8_t skipStackComment(void) { uint8_t c; - c = getKeyB(); - while (c != ')') { + do { c = getKeyB(); - } + } while (c != ')'); c = nextPrintableChar(); @@ -894,17 +892,14 @@ void loopFunc(int16_t n) #define k ANOS // count #define m ASTACK(2) // limit - ANOS += n; // inc/dec the count + k += n; // inc/dec the count - if ( ! ( ((n >= 0) && (k >= m)) - || ((n <= 0) && (k <= m)))) { + if (((n > 0) && (k < m)) || ((n < 0) && (k > m))) { // loop progCounter = j; } else { // done, cleanup - popAddrStack(); - popAddrStack(); - popAddrStack(); + addrStackPtr += 3; } #undef j #undef k diff --git a/msp4th/test4th.c b/msp4th/test4th.c index 509d175..cfe7ff8 100644 --- a/msp4th/test4th.c +++ b/msp4th/test4th.c @@ -6,12 +6,25 @@ +/* + * msp4th settings + */ #define MATH_STACK_SIZE 32 #define ADDR_STACK_SIZE 64 -#define CMD_LIST_SIZE 128 -#define PROG_SPACE 256 -#define USR_OPCODE_SIZE 32 + +//total length of all user programs in opcodes +#define USER_PROG_SIZE 256 + +//max number of user-defined words +#define USER_OPCODE_MAPPING_SIZE 32 + +//total string length of all word names (+ 1x each) +#define USER_CMD_LIST_SIZE 128 + +//maximum input line length #define LINE_BUFFER_SIZE 128 + +//maximum word character width #define WORD_BUFFER_SIZE 32 @@ -21,11 +34,11 @@ */ int16_t mathStackArray[MATH_STACK_SIZE]; int16_t addrStackArray[ADDR_STACK_SIZE]; -int16_t progArray[USR_OPCODE_SIZE]; -int16_t progOpcodesArray[USR_OPCODE_SIZE]; -uint8_t cmdListArray[CMD_LIST_SIZE]; -uint8_t lineBufferArray[CMD_LIST_SIZE]; -uint8_t wordBufferArray[CMD_LIST_SIZE]; +int16_t progArray[USER_PROG_SIZE]; +int16_t progOpcodesArray[USER_OPCODE_MAPPING_SIZE]; +uint8_t cmdListArray[USER_CMD_LIST_SIZE]; +uint8_t lineBufferArray[LINE_BUFFER_SIZE]; +uint8_t wordBufferArray[WORD_BUFFER_SIZE]; struct msp4th_config config; @@ -66,9 +79,12 @@ void config_msp4th(void) config.getchar = &my_getchar; config.puts = &my_puts; + // stack top is zero + mathStackArray[MATH_STACK_SIZE - 1] = 0; + // terminate the strings lineBufferArray[0] = 0; - wordBufferArray[0] = 0; + //wordBufferArray[0] = 0; cmdListArray[0] = 0; -- 2.25.1