Shop OBEX P1 Docs P2 Docs Learn Events
conditional jumps in assembly — Parallax Forums

conditional jumps in assembly

Jack BuffingtonJack Buffington Posts: 115
edited 2010-02-09 15:28 in Propeller 1
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:

        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 Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-02-08 22:33
    Your first two examples should work fine. Your third one has an error: the if_z should be if_nz. But your first is the best choice. I think we'll need to see the entire program to determine why it doesn't work the way you want it to. Obviously, there's something else going on here. For example, did you remember to put all your reses at the very end of your assembly program?

    -Phil
  • lonesocklonesock Posts: 917
    edited 2010-02-08 22:39
    There is at least one more option:
    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.
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-02-08 23:51
    Jack,

    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 BuffingtonJack Buffington Posts: 115
    edited 2010-02-09 00:08
    I finally figured it out. I had thought that it was something to do with not understanding how propeller assembly language works but it turns out that I was simply initializing myLong to zero when I reserved it as a long so that it wouldn't be an alias. I wasn't setting it to a number above zero anywhere in my code so it decremented to 4,294,967,296. Eventually my program would have run fine once it decremented all the way through a long... Sorry to have wasted peoples' time on this one. I'll post my code to the object exchange once I have it nice and polished. I'm working on a PWM routine that is more efficient than the one in the object exchange right now.

    -Jack
  • AleAle Posts: 2,363
    edited 2010-02-09 09:02
    ** Advertisement ** I find the use of a (my) simulator for small pieces of code quite a nice and useful. (see sig) hop.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-02-09 09:08
    Ale: There are many times I wish I learnt to use your simulator. It's always the simple stupid things that you get caught on.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
  • BradCBradC Posts: 2,601
    edited 2010-02-09 09:31
    Cluso99 said...
    It's always the simple stupid things that you get caught on.

    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.
  • AleAle Posts: 2,363
    edited 2010-02-09 10:20
    You both are right... but sometimes you do not have extra time to dig :-(.

    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 StablerGraham Stabler Posts: 2,510
    edited 2010-02-09 10:40
    Everyone knows the procedure is to bang your head against the wall for a few hours and THEN download a simulator or read the instructions depending on if we are talking programming of IKEA furniture.

    Graham
  • BradCBradC Posts: 2,601
    edited 2010-02-09 14:55
    Graham Stabler said...
    read the instructions

    <gasp>
    Sellout!!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Life may be "too short", but it's the longest thing we ever do.
  • AleAle Posts: 2,363
    edited 2010-02-09 15:28
    Actually reading the instructions help a lot, sometimes. I got quite a bit of complaints from people who did not read the included docs in pPropellerSim!. I wonder why did I write them. Brad you did not write any instructive for BST (AFAIK) but discussed all of it in the appropriate thread... smart, very smart.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
Sign In or Register to comment.