Shop OBEX P1 Docs P2 Docs Learn Events
Question about the use of 0 in prop assembly — Parallax Forums

Question about the use of 0 in prop assembly

Chris KraftChris Kraft Posts: 20
edited 2006-11-27 23:37 in Propeller 1
I am reading through the code in TV.spin and there are a couple of lines that I am not sure what they do. They all seem to use 0 as a location to copy things into.

Specifically (I don't have the line numbers handy):

: par          rdlong 0,t1

(there should not be a space between the : and par but the forums code keeps interpreting it as emoticons even inside the code block)

If I understand rdlong correctly it is taking main memory and, in this case, copying it into 0.

Further on I see the following two samples:

:wr           mov 0,t21


:ltab         mov 0,01



Does anyone know what this does? Why use 0 as a destination?

The only thing I can think of is that maybe 0 ends up representing the bottom of cog memory but that doesn't explain the use of mov 0,0 then.

If anyone has an explanation for what this is doing I would appreciate the help.

Thanks

--Chris

Post Edited (Chris Kraft) : 11/27/2006 2:28:49 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-11-27 15:10
    All of these instructions are modified at run-time. The destination field is set to some address earlier in the code. Look for the labels (:wr, :ltab, etc.) in the destination field of other instructions and you will see how this is used. The reason for this is that the instruction set doesn't provide for indexing, so self-modifying code has to be used to access arrays/tables.
  • Chris KraftChris Kraft Posts: 20
    edited 2006-11-27 15:33
    Ok. I think I got it. I saw the modification being done but it didn't register what was happening.

    So if I understand correctly:

    : par rdlong 0,t1

    establishes : par as being those commands, then a movd modify's the destination address, for example:

    movd : par, #_enable

    This causes the line to modify into the following:

    : par rdlong #_enable,t1

    Although its not really #_enable but the address that _enable is pointing too.

    --Chris
  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-27 23:25
    Chris,

    You've got it. Zero is being used here as a "don't-care" value. Some other assemblers provide an explicit symbol for distinguishing "I want this to be zero" from "I don't care what this is," often * or _, and that might be something for Parallax to consider.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-11-27 23:37
    I've always used 0-0 in these situations. It evaluates to 0, of course, but it's enough of a visual cue to flag it as a value that gets modified.

    -Phil
Sign In or Register to comment.