conditional jumps in assembly
Here is another one that I have been banging my head against for a few hours and am getting nowhere.
I have a counter that I am decrementing and would like to jump to another place if it doesn't roll over or hit zero. Either one would be OK. Conditional jumping just doesn't seem to work for me. I have tried all of these. In each case, the stuff that should be jumped over most of the time is run every time:
I have tried variations on pretty much every instruction in each of those.
I CAN get things to work if I do this:
If I change it to this, it no longer works:
I must be missing something simple about conditional jumps but can't figure out what. Any help would be appreciated.
I have a counter that I am decrementing and would like to jump to another place if it doesn't roll over or hit zero. Either one would be OK. Conditional jumping just doesn't seem to work for me. I have tried all of these. In each case, the stuff that should be jumped over most of the time is run every time:
djnz myLong,#jumpPlace
mov myLong,#255
' other code goes here
jumpPlace
sub myLong,#1 wz
if_nz jmp #jumpPlace
mov myLong,#255
' other code goes here
jumpPlace
sub myLong,#1
cmp myLong,#0 wz
if_z jmp #jumpPlace
mov myLong,#255
' other code goes here
jumpPlace
I have tried variations on pretty much every instruction in each of those.
I CAN get things to work if I do this:
sub myLong,#1 wc
if_c mov myLong,#255
'other code goes here and it will work BUT I have to put 'if_c' before each instruction so that it doesn't run them
If I change it to this, it no longer works:
sub myLong,#1 wz
if_z mov myLong,#255
'other code goes here
I must be missing something simple about conditional jumps but can't figure out what. Any help would be appreciated.
Comments
-Phil
cmpsub myLong,#1 wc,wz if_nc_or_z jmp #jumpPlace
cmpsub will set the C flag if it subtracted 1 (so "not C" if it was already 0)
cmpsub will set the Z flag if it just went from 1 to 0
Does that work for you? I'm not sure exactly what you're trying to do, sorry.
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
Your examples should work OK. Can you show a complete source that fails? There must be something in the other parts of your loop that is changing mylong, or excuting other code that makes it look like it's not skipping the "other code goes here" part.
Dave
-Jack
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit some of my articles at Propeller Wiki:
MATH on the propeller propeller.wikispaces.com/MATH
pPropQL: propeller.wikispaces.com/pPropQL
pPropQL020: propeller.wikispaces.com/pPropQL020
OMU for the pPropQL/020 propeller.wikispaces.com/OMU
pPropellerSim - A propeller simulator for ASM development sourceforge.net/projects/ppropellersim
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
Yes, but it's the hours spent chasing the stupid things that allows you to learn so many neat other things..
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Life may be "too short", but it's the longest thing we ever do.
Now there is even a Mac OS X ready version... it looks (well, so-so, it is java :-() and behaves as every other app out there. (There is little magic involved in the process...)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit some of my articles at Propeller Wiki:
MATH on the propeller propeller.wikispaces.com/MATH
pPropQL: propeller.wikispaces.com/pPropQL
pPropQL020: propeller.wikispaces.com/pPropQL020
OMU for the pPropQL/020 propeller.wikispaces.com/OMU
pPropellerSim - A propeller simulator for ASM development sourceforge.net/projects/ppropellersim
Graham
<gasp>
Sellout!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Life may be "too short", but it's the longest thing we ever do.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit some of my articles at Propeller Wiki:
MATH on the propeller propeller.wikispaces.com/MATH
pPropQL: propeller.wikispaces.com/pPropQL
pPropQL020: propeller.wikispaces.com/pPropQL020
OMU for the pPropQL/020 propeller.wikispaces.com/OMU
pPropellerSim - A propeller simulator for ASM development sourceforge.net/projects/ppropellersim