Package: simulpic
Version: 2005-1-28-3
Instruction sublw (0x3C??) is interpreted in wrong way.
"sublw value" (code 0x3Cvalue) is interpreted as W = W - value.
But specification says and real 16F84 does: W = value - W.
Below is test file that demonstrates the bug.
This bug can be avoided when using subwf instead of sublw.
The value must be then stored in some memory.
----------- subbug.asm ----------
; example on BUG in sublw <literal> in simulpic
; sublw l: W = l - W, is interpreted as W = W - l
;
; Here in test simulpic executes 'Bad' (sets PORTB0 to 0; halt loop with nop)
; PIC16F84 executes 'Good' (sets PORTB0 to 1; halt loop without nop)
;
; You can avoid this bug by inicializing some file with l
; and using "subwf file,W" instead of "sublw l"
;
; ************************** HEADER *****************************
list p=16F84 ; list directive to define
processor
#include <p16f84.inc> ; processor specific variable definitions
; Code Protection : OFF
; Watchdog Timer : OFF
; Power Up Timer : ON
; Oscilator: High Speed crystal/resonator
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC ;
; ************************* PROGRAM ******************************
org 0x0000
; Initialization of ports
;setup PORTB 0 as test output
bsf STATUS, RP0 ; All inputs
movlw 0xFE
movwf TRISB
movlw 0xFF
movwf TRISA
bcf STATUS, RP0
; The test !
movlw 0x1 ; W = 1
sublw 0x3 ; W = 3 - W ;simulpic interprets as W = W - 3
addlw 0xfe ; W = W - 2
skpz ; if (W==0) skip;
goto Bad
Good
bcf PORTB,0 ;--- LO if result is 0xfc (bad)
goto $ ;halt
Bad
bsf PORTB,0 ;--- HI if result is 0x0 (good)
nop
goto $-1 ;another halt
end
----------- subbug.hex -----------
:020000040000FA
:100000008316FE308600FF30850083120130033CEA
:10001000FE3E031D0D2806100C28061400000E28B5
:02400E00F23F7F
:00000001FF
----------------------------------
--
Tomas 'ebi' Ebenlendr
http://get.to/ebik
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]