Shop OBEX P1 Docs P2 Docs Learn Events
Setting and clearing flags — Parallax Forums

Setting and clearing flags

PliersPliers Posts: 280
edited 2010-11-18 11:59 in Propeller 1
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?

Comments

  • dMajodMajo Posts: 855
    edited 2010-11-18 09:53
    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
  • PliersPliers Posts: 280
    edited 2010-11-18 09:58
    In the sample given.

    Will the next wz effect specified, clear Z if that is the case?
  • ericballericball Posts: 774
    edited 2010-11-18 10:02
    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
    
  • ericballericball Posts: 774
    edited 2010-11-18 10:04
    Pliers wrote: »
    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.
  • PliersPliers Posts: 280
    edited 2010-11-18 10:08
    Thanks for your help.

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

    Mine was not working :)
  • PliersPliers Posts: 280
    edited 2010-11-18 10:38
    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
    
    
  • PliersPliers Posts: 280
    edited 2010-11-18 11:42
    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.
  • ericballericball Posts: 774
    edited 2010-11-18 11:59
    Pliers wrote: »
    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 
    
Sign In or Register to comment.