[Flashforth-devel] PIC18F - Problems with code above $8000
Brought to you by:
oh2aun
|
From: Pablo M. <ea...@ho...> - 2018-03-19 20:50:33
|
Hello Mikael,
I am writing a relatively big (o lousy coded) program, and have found that words created above $8000 sometimes result in a processor reset when compiled into new words.
Here is a simple example:
hex flash here u. 895a ok<$,flash>
ram ok<$,ram>
: test1 1 1 + ; ok<$,ram>
test1 ok<$,ram>2
: test2 test1 ; ok<$,ram>2
test2
FlashForth 5 PIC18F26K20 07.10.2017 --> [test2 has produced a reset]
After a lot of head scratching, I have found that CALL and GOTO instructions have an incorrect destination address when the target is above $8000:
' test1 ok<$,ram>8962
hex see test2
897a efb1 f0c4 goto test1
The destination addresss should be 44b1 (= 8962 / 2), but the compiled address is c4b1. This results in a jump outside the program.
The problem is that the destination address is calculated with the 2/ code (TWOSLASH routine). But 2/ is designed to work with signed numbers. It does so by shifting 1 bit right but maintaining the sign bit.
8962 2/ ok<$,ram>c4b1 <--- This is the used (incorrect) address
8962 1 rshift ok<$,ram>c4b1 44b1 <--- This is the correct address
The simplest solution would be to change 2/ to work with unsigned numbers. But I see that the current implementation of 2/ is correct according to the ANS94 standard, so it doesn't seem right to change it.
Perhaps the best solution is to create a new subrutine "u2/"
UTWOSLASH:
bcf STATUS, C, A
rrcf Sminus, F, A
rrcf Splus, F, A
return
and use it instead of TWOSLASH in "br?" and "br3".
73, Pablo - EA4FUK
|