msp4th: bugfix do-loop, gcc optimizes too much
authorDan White <dan@whiteaudio.com>
Thu, 16 May 2013 06:49:46 +0000 (01:49 -0500)
committerDan White <dan@whiteaudio.com>
Thu, 16 May 2013 06:49:46 +0000 (01:49 -0500)
msp4th/bootrom.rcf
msp4th/cosim.py
msp4th/main.c
msp4th/msp4th.c
msp4th/test4th.c

index 92cdcb32fdc8d4ded1543fe50e0154d87fb33c35..4fcbaf0d6e131b053dd246af4be561939ce770fb 100644 (file)
 0100000010110010
 0011000101101110
 0100010001011010
+0100001110000010
+0100000001100010
 0100001111000010
 0100001110100100
 0100001111000010
-0100010000100100
-0100001111000010
 0100001100100100
 0100000000111111
 0100010001000100
 0100111101001011
 1001001110000010
 0100000000001100
-0010010000010100
+0010010000011100
 1001001001111111
 0010000000001111
 1001001000011001
 0100000000000010
 0101001110110010
 0100000000001010
-0011110000101000
+0011110000100110
 0100101101001111
 0001001010010010
 0100000000000010
 1001000001111011
 0000000000001101
+0010000000001000
+0100000001111111
+0000000000001010
+0001001010010010
+0100000000000010
+0011110000001100
+1001000001111111
+0000000000001101
 0010010000001001
 1001000001111011
 0000000000001010
 0101001100111111
 1001111110000010
 0100000000001010
-0011100000001011
-1001001110000010
-0100000000001100
-0010010000000110
-0100000001111111
-0000000000001010
-0001001010010010
-0100000000000010
+0011100000000001
 0100001100001010
-0011110000000010
-0100001000011010
-0100000000001100
 0100001000011111
 0100000000001010
 0100001000011110
 0100001111001111
 0000000000000000
 1001001100001010
-0010001110111111
+0010001111000001
 0100101010000010
 0100000000001010
 0100000100111001
 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
 0100001111001111
 0000000000000000
 0001001010110000
-0011001011001000
+0011001011000100
 1001111101001010
 0010110000000011
 1001001000011011
 0011110011001110
 0100101000001111
 0001001010110000
-0011001110110100
+0011001110101010
 0100111100001001
 1001001100001111
 0010010000000011
 0011110111111110
 0100101000001111
 0001001010110000
-0011001110110100
+0011001110101010
 0100111100001011
 1001100100001111
 0010010000000011
 0100000000011110
 0100101000001111
 0001001010110000
-0011001110110100
+0011001110101010
 1001101100001111
 0010010000000011
 0001001010110000
-0011001110010100
+0011001110001010
 0100001100011111
 0001001010110000
-0011001110010100
+0011001110001010
 0100000100111001
 0100000100111010
 0100000100111011
 0001001000001011
 0001001000001010
 0001001010110000
-0011001110001000
+0011001101111110
 1001000000111111
 0100111000100000
 0011100000000101
 0011110000000001
 0100001100011011
 0001001010110000
-0011001110010100
+0011001110001010
 0100101100001111
 0001001010110000
-0011001110010100
+0011001110001010
 0100000100111010
 0100000100111011
 0100000100110000
 1001001100011111
 0010010000000100
 0001001010110000
-0011001110001000
+0011001101111110
 1001001100001111
 0010000000000010
 0100101110000010
 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
 0100111010000010
 0100000000011100
 0001001010110000
-0011001110010100
+0011001110001010
 0100000100110000
 0100001100001101
 0011110000000111
 0100001000011111
 0100000000000110
 0001001010110000
-0011001110110100
+0011001110101010
 0101111100001111
 0101001000011111
 0100000000100000
 1000011010100110
 0000000000000010
 0001001010110000
-0011001110001000
+0011001101111110
 0100000000110000
 0011110000011110
 1100001000110010
 0100000000110000
 0011110000011110
 0001001010110000
-0011001110001000
+0011001101111110
 0001001010110000
 0011011010100100
 0100000000110000
 0100000000110000
 0011110000011110
 0001001010110000
-0011001110001000
+0011001101111110
 0100011000001110
 1001111110000110
 0000000000000000
 0011010000010000
 0011110000001011
 0001001010110000
-0011001110001000
+0011001101111110
 0100011000001110
 1001011000101111
 0011010000001010
 0011110000000101
 0001001010110000
-0011001110001000
+0011001101111110
 0100011000001110
 1001011000101111
 0010000000000100
 0100000000110000
 0011110000011110
 0001001010110000
-0011001110001000
+0011001101111110
 0001001010110000
 0011011100110000
 0011110001110010
 0001001010110000
-0011001100011110
+0011001100010100
 0100000000110000
 0011110000011110
 0001001010110000
 0101001000011011
 0100000000001000
 0001001010110000
-0011001110001000
+0011001101111110
 0100111110001011
 0000000000000000
 0101001100011010
 0100000000110000
 0011110000011110
 0001001010110000
-0011001110001000
+0011001101111110
 0100111100001011
 0001001010110000
-0011001110001000
+0011001101111110
 0100101100001110
 0101111000001110
 0101001000011110
 0100000000110000
 0011110000011110
 0001001010110000
-0011001101101110
+0011001101100100
 0100000000110000
 0011110000011110
 0100001100001111
 0100000000011100
 0011110001111001
 0001001010110000
-0011001110011100
+0011001110010010
 0100111100001011
 0001001010110000
-0011001110001000
+0011001101111110
 1001001100001111
 0010010000000010
 0100000000110000
 0001000000001110
 0100111000001111
 0001001010110000
-0011001110010100
+0011001110001010
 0100000000110000
 0011110000011110
 0001001010110000
-0011001110001000
+0011001101111110
 0001001010110000
 0011011101001110
 0100000001111111
 0100000000110000
 0011110000011110
 0001001010110000
-0011010011110100
+0011010011101010
 0100000000110000
 0011110000011110
 0100001100001111
 0011111111101100
 0100001100011111
 0001001010110000
-0011010110100110
+0011010110011100
 0100000000110000
 0011110000011110
 0001001010110000
 0100000000110000
 0011110000011110
 0001001010110000
-0011010000001100
+0011010000000010
 0100000000110000
 0011110000011110
 0001001010110000
 0100001000011011
 0100000000000010
 0001001010110000
-0011001110001000
+0011001101111110
 0001001010001011
 0011110100001011
 0001001010110000
-0011001110011100
+0011001110010010
 0100111110000010
 0100000000011100
 0011110100000110
 0000000000000000
 0011110100000000
 0001001010110000
-0011001110001000
+0011001101111110
 0100111100001011
 0001001010110000
-0011001110001000
+0011001101111110
 0100101100001110
 1111000000111110
 1111111111111110
 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
 0011111011001111
 1100001000110010
 0001001010110000
-0011001110001000
+0011001101111110
 0100111110000010
 0000000100110010
 0100011010010010
 0011111110001010
 0100110000001011
 0001001010110000
-0011001110001000
+0011001101111110
 0100101110000110
 0000000000000000
 0011110010101001
 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
 0000000000000010
 0100011000101111
 0001001010110000
-0011001110010100
+0011001110001010
 0100011010100110
 0000000000000100
 0100101110000110
 0000000000000010
 0011110001000000
 0001001010110000
-0011001110001000
+0011001101111110
 0100011000001110
 1001111110000110
 0000000000000000
 0011010000111010
 0011110000000101
 0001001010110000
-0011001110001000
+0011001101111110
 0100011000001110
 1001011000101111
 0011010000110100
 0000000000000000
 0011110000010011
 0001001010110000
-0011001110001000
+0011001101111110
 0100111110000010
 0100000000001100
 0011110000001110
 0100001111001111
 0000000000000000
 0001001010110000
-0011001110001000
+0011001101111110
 0001001010110000
 0011000110100000
 0011110000000101
 0001001010110000
-0011010001100010
+0011010001011000
 0011110000000010
 0001001010110000
-0011010011011010
+0011010011010000
 0100000100111000
 0100000100111001
 0100000100111010
 0100000100110000
 0001001000001011
 0001001010110000
-0011001110001000
+0011001101111110
 0100111100001011
 1001000000111111
 0100111000100000
 0100001000011111
 0100000000011100
 0001001010110000
-0011001110100010
+0011001110011000
 0101101100001011
 0101000000111011
 1110111111101000
 0100001000011111
 0100000000011100
 0001001010110000
-0011001110100010
+0011001110011000
 0101101100001011
 0101001000011011
 0100000000100000
 0011011101100100
 0011110000001000
 0001001010110000
-0011001110100010
+0011001110011000
 0100101100001111
 0101111100001111
 0101001000011111
index 1a327f6c1916f504b2495018985151b0d5f539b8..e8c419205f3042aed9bfef4125973fc16f87545f 100644 (file)
@@ -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)
 
 
index f8eb53f4cbd84a1b51ad6de88ab9d081e63807e7..e14e849c3667538dac1ac5e44c18dbd913fe8b01 100644 (file)
@@ -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;
 
 
index b7ebda72db7de20b7519ee5352368c055993da20..681ec1a0b73a68b1aef42e12636a06b394a40e96 100644 (file)
@@ -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
index 509d175fdd6c77bb7b034383be510d4485bdd672..cfe7ff88cdb9c6717bee3805ff4aa11f05a910db 100644 (file)
@@ -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<space> 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
 
 
  */
 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;