sxsim bug, Z cleared after mov w,variable
Peter Verkaik
Posts: 3,956
Hi,
Appended test program has 2 variables, Ktimer and kCount initialized to 1 (at label initRegs)
The mainloop is
main
··;other tasks here
··bank·kernel
··dec·kCount···· ;decrements kCount from 1 to 0, so Z set
··mov·w,kTimer ;in sxsim Z·gets cleared after·executing this instruction
··snz· ; and thus kCount does not get reloaded
··mov·kCount,w
··jmp·main
I am using sxsim 2.08.06
regards peter
Appended test program has 2 variables, Ktimer and kCount initialized to 1 (at label initRegs)
The mainloop is
main
··;other tasks here
··bank·kernel
··dec·kCount···· ;decrements kCount from 1 to 0, so Z set
··mov·w,kTimer ;in sxsim Z·gets cleared after·executing this instruction
··snz· ; and thus kCount does not get reloaded
··mov·kCount,w
··jmp·main
I am using sxsim 2.08.06
regards peter
SRC
5K
Comments
interchange
··dec·kCount···· ;decrements kCount from 1 to 0, so Z set
··mov·w,kTimer ;in sxsim Z·gets cleared after·executing this instruction
so main becomes
main
··;other tasks here
··bank·kernel· ;at this point Z=1
··mov·w,kTimer ;in sxsim Z·gets cleared after·executing this instruction
··dec·kCount···· ;decrements kCount from 1 to 0, so Z set
··snz· ;·now·kCount gets reloaded
··mov·kCount,w
··jmp·main
regards peter
according to the SX datasheets, a mov w, fr instruction affects the Z flag, i.e. when fr contains 0, the Z flag is set, else it is cleared. I have verified this with the SX-Key in debug mode, and I have also double-checked SXSim to make sure that it handles this the same way. So I don't think this is a bug in SXSim.
BTW, vice-versa, the mov fr, w instruction does NOT affect the Z flag.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
You are right. I should have checked the datasheet.
Funny, the mov w,#literal and mov w,m and mov w,<>fr that I use most to reload,
do not affect the Z flag. So I assumed mov w,fr wouldn't either.
regards peter
I have no clue why the SX designers decided to let the mov w, fr instruction affect the Z flag, where other mov instructions don't (except those that increment, decrement, etc. a value "on the fly"). Well, we'll have to live with it .
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
When Parallax created new mnemonics for the PIC (which they then transferred to the SX), they made PIC/SX assembly language much easier to read, on the one hand, but obscured the underlying instruction set a little, on the other. What seems like a glaring asymmetry with the Parallax mnemonics, makes a lot more sense when the underlying instruction set is taken into account.
-Phil
Update: Incidentally, the way to move a register to W without setting any flags is:
Post Edited (Phil Pilgrim (PhiPi)) : 2/25/2007 5:59:25 PM GMT
thank you for your explanation - this makes the difference between "mov w, fr" and "mov fr, w" clear, and - yes - under this light, it makes sense that "mov w, fr" affects the Z flag, where "mov fr, w" does not.
Using the "double swap" method is a nice trick (except that it takes two instructions, or maybe three).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G