How to do... If X = 1 AND Y = 1 Then ... in ASM
Hi guys,
I sort of understand the CMP(s) function now and sort of understand the IF_C etc. functions and need to expand on them.· As the title shows...
·If X = 1 AND Y = 1 Then
is easy enough to understand in BASIC and perhaps even SPIN.· However, how would I go about this in ASM?
Chris
·
I sort of understand the CMP(s) function now and sort of understand the IF_C etc. functions and need to expand on them.· As the title shows...
·If X = 1 AND Y = 1 Then
is easy enough to understand in BASIC and perhaps even SPIN.· However, how would I go about this in ASM?
Chris
·

Comments
cmp X,#1 WZ IF_Z cmp Y,#1 WZ IF_Z jmp #okay ' X=1 and Y=1 IF_NZ jmp #fail ' X<>1 or Y<>1There are probably more optimal ways as well.
IF X = 1 THEN
IF Y = 1 THEN
In assembler this gives
cmp X, #1 WZ IF_Z cmp Y, #1 WZ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Airspace V - international hangar flying!
www.airspace-v.com/ggadgets for tools & toys
djnz X,#fail nr djnz Y,#fail nr succeed ...-Phil
again a nice solution from you. But for a newbie you should have mentioned, that your solution will change the values of X and/or Y.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
cmp X,#1 wz if_z cmp Y,#1 wz if_nz jmp #fail succeed ...you will see that the above requires 12 clocks to get to succeed or fail, while the djnz code takes 16 to get to succeed and 4 or 8 to get to fail. So the optimum choice will depend on the relative probabilities of the two cases.
-Phil
Fixed formatting.
Post Edited (Phil Pilgrim (PhiPi)) : 3/28/2009 9:06:30 PM GMT
I like your use of the djnz, however if you wanted something that followed more closely to ... If N=0 then ... or ... if N=1 then ... you could use the TJNZ or TJZ command.
tjnz X,#fail 'jump to address if not zero tjnz Y,#fail 'jump to address if not zero succeed ...·or..
tjz X,#fail 'jump to address if zero tjz Y,#fail 'jump to address if zero succeed ...▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Yup! But I think you meant, "If N<>0", rather than, "If N==1", right?
Actually, "If X==0 AND Y==0" is quicker with
or X,Y nr,wz if_nz jmp #fail succeed ...-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
-Phil
That's a lot of suggestions!· Thanks very much for all of them!
I will have to do some experimenting with the various examples so I can understand them but this should be enough to help me work out the structure for more complex decision making branching and such.
Chris