From 408bca6c2247bd806debfd0626cc32969dbc9d63 Mon Sep 17 00:00:00 2001 From: Dan White Date: Sun, 1 Feb 2015 14:07:54 -0600 Subject: [PATCH] fix dirMemory access, the array index must be unsigned --- msp4th/Makefile | 2 +- msp4th/msp4th.c | 6 +++--- msp4th/tests.4th | 7 +++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/msp4th/Makefile b/msp4th/Makefile index 2ec2a13..40c63a1 100644 --- a/msp4th/Makefile +++ b/msp4th/Makefile @@ -70,7 +70,7 @@ OBJECTS = $(SOURCES:.c=.o) ASSEMBLYS = $(SOURCES:.c=.lst) #all: $(TARGET).elf $(TARGET).hex $(TARGET).txt -all: $(TARGET).elf $(TARGET).hex $(TARGET).xout $(ASSEMBLYS) +all: $(TARGET).elf $(TARGET).hex $(TARGET).xout $(ASSEMBLYS) _pc4th #we .include this, so it doesn't make it to the auto-generated dependencies main.o: flashboot.s diff --git a/msp4th/msp4th.c b/msp4th/msp4th.c index 4bb3f31..22d4e6f 100644 --- a/msp4th/msp4th.c +++ b/msp4th/msp4th.c @@ -1247,14 +1247,14 @@ void execVM(int16_t opcode) case 41: // @ ( addr -- val ) \ read directly from memory address i = TOS >> 1; - TOS = dirMemory[i]; + TOS = dirMemory[(uint16_t)i]; break; case 42: // ! ( val addr -- ) \ write directly to memory address words only! i = popMathStack(); // address to write to i = i >> 1; j = popMathStack(); // value to write - dirMemory[i] = j; + dirMemory[(uint16_t)i] = j; break; case 43: // h@ ( -- prog ) \ get end of program code space @@ -1408,7 +1408,7 @@ GCC_DIAG_ON(int-to-pointer-cast); case 66: // +! ( n addr -- ) \ *addr += n i = popMathStack(); j = popMathStack(); - dirMemory[i] += j; + dirMemory[(uint16_t)i] += j; break; case 67: // roll ( n -- ) \ nth stack removed and placed on top diff --git a/msp4th/tests.4th b/msp4th/tests.4th index b1f84b9..f3e4ac2 100644 --- a/msp4th/tests.4th +++ b/msp4th/tests.4th @@ -206,10 +206,9 @@ test-pwrd bar \ case 41: // @ ( addr -- val ) \ read directly from memory address \ case 42: // ! ( val addr -- ) \ write directly to memory address words only! -\ NOTE: Not working on PC version, fake dirMemory array needs debugging. -\ 42 0xff00 ! -\ 0xff00 @ -\ 42 cmp +42 0xff00 ! +0xff00 @ +42 cmp \ case 43: // h@ ( -- progIdx ) \ get end of program code space \ no test -- 2.25.1