PDA

View Full Version : Setting and clearing flags



Pliers
11-18-2010, 03:57 PM
In an assembly instruction, if a flag gets set, will it get cleared by the next WZ instruction if that instruction does not set the flag?

dMajo
11-18-2010, 04:53 PM
NO, the next instruction do not clear it

Each instruction that have a wz effect specified will modify the z flag. Its state will remain unchanged untill the next instruction with the wz effect specified.

That mean that you can have several if_z lines that will all react to the last line that had the wz effect specification thus affecting it

Pliers
11-18-2010, 04:58 PM
In the sample given.

Will the next wz effect specified, clear Z if that is the case?

ericball
11-18-2010, 05:02 PM
This may be a better way to accomplish what you want.


mov dira, InputPins
:loop waitpne MediaPresentMask, MediaPresentMask ' wait for pin to go to low
and SlackSensor1Mask,ina wz
if_nz mov outa , #LED18 ' turn on LED18 if pin high
and SlackSensor2Mask,ina wz
if_nz mov outa , #LED20 ' turn on LED20 if pin high
jmp #:loop

ericball
11-18-2010, 05:04 PM
Will the next wz effect specified, clear Z if that is the case?
The next wz will update the Z flag as per the instruction results. However, it is possible to "chain" flags by prefixing the wz instruction with if_z or if_nz as appropriate and construct AND/OR logic.

Pliers
11-18-2010, 05:08 PM
Thanks for your help.

ericball, Ill checkout your code. THANK YOU VERY MUCH.

Mine was not working :)

Pliers
11-18-2010, 05:38 PM
Still not working.
I hold button 1 in, and then press button 2 or 3.



pub main
cognew (@start,0)

dat
start org 0
mov dira, DirOfThePins
:loop waitpeq Sensor1, Sensor1 ' wait for pin1 to go to high
and Sensor2,ina wz
if_nz mov outa , LED18 ' turn on LED18 if pin2 high
and Sensor3,ina wz
if_nz mov outa , LED20 ' turn on LED20 if pin3 high
jmp #:loop
LED18 long %100_0000_0000_0000_0000
LED20 long %10_000_0000_0000_0000_0000
Sensor1 long %10 ' Pin 1, button input goes high
Sensor2 long %100 ' Pin 2, button input goes high
Sensor3 long %1000 ' Pin 3, button input goes high
DirOfThePins long %1_1111_0000_0000_0000_0000 ' Pins 20..16 as outputs , LEDS

Pliers
11-18-2010, 06:42 PM
It maybe something is also on the INA, making my AND statements bad.
Therefore not setting the Z flag.
OK. I got some ideas. I'll be back.

ericball
11-18-2010, 06:59 PM
It maybe something is also on the INA, making my AND statements bad. Therefore not setting the Z flag.
Whoops, you want the TEST instruction, not the AND instruction otherwise you're overwriting Sensor2/3 with the AND result.

You're also not resetting OUTA. Hmm...



start org 0
mov dira, DirOfThePins
:loop waitpeq Sensor1, Sensor1 ' wait for pin1 to go to high
test Sensor2,ina wz
muxnz outa, LED18 ' turn on LED18 if pin2 high
test Sensor3,ina wz
muxnz outa, LED20 ' turn on LED20 if pin3 high
jmp #:loop
DirOfThePins long %1_1111_0000_0000_0000_0000 ' Pins 20..16 as outputs , LEDS
LED18 long %0_0100_0000_0000_0000_0000
LED20 long %1_0000_0000_0000_0000_0000
Sensor1 long %0_0000_0000_0000_0000_0010 ' Pin 1, button input goes high
Sensor2 long %0_0000_0000_0000_0000_0100 ' Pin 2, button input goes high
Sensor3 long %0_0000_0000_0000_0000_1000 ' Pin 3, button input goes high