Shop OBEX P1 Docs P2 Docs Learn Events
Assembly code questioon. — Parallax Forums

Assembly code questioon.

mynet43mynet43 Posts: 644
edited 2009-03-24 14:28 in Propeller 1
I spent some time debugging assembly code.

I ran into a bug I hadn't seen before, that took me way too long to find.

If I use the following code:
        wrlong  cnt,_addr




It assembles fine, but doesn't store 'cnt' in _addr.

If I change it like this:
        mov     t2,cnt          
        wrlong  t2,_addr           




It now works fine.

Has anyone run across this before?

On p. 397 of the manual, it says that read-only registers can only be used in the 'source' field, which this is.

Am I missing something?

Thanks for the help.

Jim

Comments

  • mparkmpark Posts: 1,305
    edited 2009-03-24 03:29
    In "wrlong cnt,_addr", cnt is in the "destination" field (i.e., bits 17-9 of the instruction). "Source" and "destination" in this context do not necessarily refer to the direction of data movement.
  • mynet43mynet43 Posts: 644
    edited 2009-03-24 03:34
    Thanks! Great answer. You're absolutely right!

    Too bad the assembler doesn't catch it...
  • Paul BakerPaul Baker Posts: 6,351
    edited 2009-03-24 03:40
    How would it catch it? The assembler has no idea if an address or data is in any particular register.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-24 03:47
    Another reason to not prohibit it is that there are memory locations "underneath" the hardware read-only registers. If you use one of these locations in the destination field of an instruction, you are accessing the underlying memory location which can occasionally be used to store data or instructions.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-03-24 06:53
    Hi Mike,

    do you say that with

    mov cnt, # some value
    wrlong cnt, addr

    you really find 'some value' in HUB RAM? And this works with other special registers as well. Nice to know if that works because it can safe some longs in PASM.

    So, what about

    mov cnt, cnt
    wrlong cnt, addr

    then you don't have to waste an additional register.
  • mynet43mynet43 Posts: 644
    edited 2009-03-24 13:58
    Considering the time I spent trying to find the 'bug', it seems like there should be a better way.

    I'm surprised the assembler has no knowledge of the props special registers. It seems like it would be helpful if it did.

    Since it executed without an error, does anyone know which data was actually written to the output address?

    It seems like it would make more sense to provide another way to get at the "registers under the registers".

    All-in-all, I learned a lot from this little post.

    Thanks everyone,

    Jim
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-24 14:28
    The "shadow RAM" trick only works with read-only registers. One of the video drivers that Chip wrote uses this technique to squeeze out a couple of extra locations. There have been a couple of other uses of these locations for instructions since the hardware fetches instructions from RAM, not the hardware registers.
Sign In or Register to comment.