Shop OBEX P1 Docs P2 Docs Learn Events
Code Confusion.... — Parallax Forums

Code Confusion....

Kenneth KramerKenneth Kramer Posts: 11
edited 2004-11-08 11:23 in General Discussion
Hi everybody,

Consider the following code:
·mov a,#10
·mov b,a··; b := a
:loop
·sub a,b··; if 0 set z := 1
·jz :loop·; if z == 0 then jump :loop
·nop··; if z == 1 then <nop>

however, this code executes as:
·mov a,#10
·mov b,a··; b := a
:loop
·sub a,b··; if 0 set z·:= 1
·jz :loop·; if z == 1 then jump :loop
·nop··; if z == 0 then <nop>

when using the SXSim simulator.

Now, if a macro like:
ifz·macro·1
·sb STATUS.2
·jmp \1
endm

substitutes the <jz> compound statement such that:
·mov a,#10
·mov b,a
:loop
·sub a,b··; if 0 set z = 1
·ifz :loop·; if z == 0 then jump :loop
·nop··; if z == 1 then <nop>

which lead me to the conclusion that <jz> has the <snz> instruction implemented as <snb STATUS.2>. If that's the case (and it seems so) then the <jz> statement wiil never jump to the address in mind.

If this·bug (which I believe it is) has been fixed in later version(s), please forgive me - I couldn't resist·thinking about·the problem burger.gif .

Thanks,
Kenneth

Post Edited By Moderator (Jon Williams) : 11/8/2004 2:34:44 PM GMT

Comments

  • BeanBean Posts: 8,129
    edited 2004-11-07 01:16
    I don't follow your comments.
    In the first example you have

    jz :loop ; if z==0 then jump :loop

    The comment does NOT describe the action "jz" means jump if the zero flag is SET not if the zero flag is zero

    Maybe that is the confusion.

    Bean.
  • Kenneth KramerKenneth Kramer Posts: 11
    edited 2004-11-08 11:23
    It was a mistake. I've done some assembler programming in the 8086 processor family over the years and I have always thought of the zero flag as being Z (zero) = 0 or NZ (non-zero) = 1. My apology to Mr. Daubach for mistakenly thinking of my problem as a bug in the SXSim simulator. Thanks for the input, Bean. It helped me a lot.


    cheers,
    Kenneth
Sign In or Register to comment.