Shop OBEX P1 Docs P2 Docs Learn Events
Assembly Question - Time Difference — Parallax Forums

Assembly Question - Time Difference

mynet43mynet43 Posts: 644
edited 2010-10-26 14:24 in Propeller 1
Can someone tell me the proper way to subtract two numbers in assembly to get a time difference?

I'm trying to get a time difference using cnt.

If I use:

mov dt,cnt
sub dt,old_t

Then I may get a negative number, if cnt has wrapped around it's 32 bits.

I know I can set the carry to tell if dt is less than old_t, but I'm not sure what to do if it is.

My time differences will always be less than 1 second.

So what is the correct way to always get a positive time difference.

Thank you for your help.

Jim

Comments

  • whickerwhicker Posts: 749
    edited 2010-10-25 15:34
    Please refer to the "Code Execution Time" section of the Propeller Q&A:
    http://www.parallax.com/portals/0/propellerqna/


    your answer is pretty much down in the middle.
  • Heater.Heater. Posts: 21,230
    edited 2010-10-25 16:21
    mynet43,

    Consider this:

    Old time is some very big unsigned number, for example in Hex:

    $FFFFFFF0

    And your new time is some small unsigned number, after CNT has rolled over:

    $00000005

    What is the elapsed time?

    new - old = $00000005 - $FFFFFFF0 = $00000015

    If you don't believe it try it on your calculator in hex mode and keeping only the lower 8 hex digits.

    Magically, despite the wrap around of CNT, that is the correct answer.

    As SUB in PASM is unsigned it to will give the correct result.

    Up until the time difference is greater than $FFFFFFFF. About 40 seconds for an 80MHz Prop.
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-10-25 18:02
    I just looked at the example in Q&A. Wow, I hadn't thought about using the neg to set the initial time as a negative. Saves and instruction! And I am always on the alert for tricks to shave time/instructions off code.
  • mynet43mynet43 Posts: 644
    edited 2010-10-25 19:32
    Wow,

    Thanks so much for all the great feedback!

    It all makes sense now.

    I think I've got it!

    Jim
  • Heater.Heater. Posts: 21,230
    edited 2010-10-25 23:01
    I can't read any of the code snippets of the code execution time section of that link: http://www.parallax.com/portals/0/propellerqna/
    All the characters are displaying wrongly. Looking around I find a lot of the text is gibberish too.

    Is this just me and my IceWeasle browser on Debian or what?
  • SapiehaSapieha Posts: 2,964
    edited 2010-10-25 23:08
    Hi Heater.


    I not have any problems.

    On Win XP with Firefox

    Heater. wrote: »
    I can't read any of the code snippets of the code execution time section of that link: http://www.parallax.com/portals/0/propellerqna/
    All the characters are displaying wrongly. Looking around I find a lot of the text is gibberish too.

    Is this just me and my IceWeasle browser on Debian or what?
  • Heater.Heater. Posts: 21,230
    edited 2010-10-25 23:23
    Looks like this here, much of the text has the same problem.
    563 x 210 - 5K
  • mynet43mynet43 Posts: 644
    edited 2010-10-26 05:47
    Heater,

    I think it's your browser or possibly not having the font installed.

    I have no problem reading it with XP/Firefox.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-10-26 08:33
    I looked in the CSS file for the site, and it requires the Parallax font (parallax.ttf) to be installed. Are you noticing gibberish outside of code snippets?

    -Phil
  • Heater.Heater. Posts: 21,230
    edited 2010-10-26 12:21
    Most of the text seems fine but there is the occasional mess up as attached.

    Surely a web page should not depend on having the Parallax font installed.
    228 x 117 - 2K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-10-26 13:08
    Heater,

    It's not your browser. I looked at the site with Opera under Ubuntu and got the same gibberish you did. With Opera under OS/X, the site hangs completely until I hit stop (X). Then the left menu is mostly absent. This did not happen on Ubuntu, though. There's definitely something wacky about that site.

    -Phil
  • train nuttrain nut Posts: 70
    edited 2010-10-26 14:24
    heater

    I have no problem running iep8 on xp.

    train nut
Sign In or Register to comment.