Code Confusion....
Kenneth Kramer
Posts: 11
Hi everybody,
Consider the following code:
however, this code executes as:
when using the SXSim simulator.
Now, if a macro like:
substitutes the <jz> compound statement such that:
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 .
Thanks,
Kenneth
Post Edited By Moderator (Jon Williams) : 11/8/2004 2:34:44 PM GMT
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>
·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>
·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
·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>
·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 .
Thanks,
Kenneth
Post Edited By Moderator (Jon Williams) : 11/8/2004 2:34:44 PM GMT
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.
cheers,
Kenneth