Shop OBEX P1 Docs P2 Docs Learn Events
Propeller Tool ASM CON byte breakdown Request (or maybe there is a trick I don' — Parallax Forums

Propeller Tool ASM CON byte breakdown Request (or maybe there is a trick I don'

Timothy D. SwieterTimothy D. Swieter Posts: 1,613
edited 2010-03-03 17:10 in Propeller 1
While working on some driver code I came across something that could be valuable in the ASM compiling. In the CON section I have many, many, many definitions. For example _S0_MR = $0400. Now, I can't use this definition in ASM because obviously it exceeds $1FF. (For those that aren't familiar with ASM the second register has to be 9 bits or less). So because _S0_MR is larger than $1FF I can't do the following.

mov reg, #_S0_MR




But I would like to be able to do soemthing without breaking all the definitions down since the definitions are what are described in the data sheet. I was thinking I would try the following, but it doesn't compile. Maybe something like this already exist, but if it doesn't maybe it could get added in the compiler?

mov reg, #_S0_MR.byte[noparse][[/noparse]0]
shl   reg, #8
or    reg, #_S0_MR.byte


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
www.tdswieter.com

Comments

  • heaterheater Posts: 3,370
    edited 2010-03-03 11:16
    How about:

    CON
    
    big_constant = 1234
    
    PUB start
    
    DAT
                      MOV   somewhere, big_constant_dat
    
    somewhere            LONG 0
    big_constant_dat  LONG big_constant
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2010-03-03 11:19
    heater - won't your method take away from the 496 longs of the cog? I'd hate to have to redefine all the CONs as DATs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
    www.tdswieter.com
  • heaterheater Posts: 3,370
    edited 2010-03-03 11:30
    Yes, and so does yours with the SHL and OR instructions.

    Except the way I have shown only uses one instruction for each reference to the constant in your PASM.

    I'm not sure there is any way to load a long constant without consuming the LONG for it.

    By the way .byte[noparse][[/noparse] 0 ] and .byte[noparse][[/noparse] 1 ] etc aren't really necessary as you can always use SHIFTS and ANDs when loading a constant:

    MOV low_byte, big_constant & $FF
    MOV high_byte, (big_constant >> 8) & $FF

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.

    Post Edited (heater) : 3/3/2010 11:35:40 AM GMT
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2010-03-03 11:35
    Ah-Ha!!! Thanks heater for engaging in the discussion with me. Your last statement is what I didn't realize. I can do the following for the moment and then contemplate the savings/expense of doing redefines in the DAT section.

                  mov       reg,    ((_S0_MR >> 8) & $FF)
                  shl       reg,    #8
                  or        reg,    (_S0_MR & $FF)
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
    www.tdswieter.com
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-03-03 12:41
    heater's method is what I use. It uses 1 less cog long than your method Timothy, and it is actually more readable.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
  • heaterheater Posts: 3,370
    edited 2010-03-03 13:04
    On can always just define constants as DAT items and forget about having them in a CON section at all.

    This has two advantages:
    1) Large constants in DAT are available for use in both Spin and PASM automatically.
    2) Makes the program smaller when using large constants.

    The following code goes from 17 program LONGs to 11 if I change the start method to use the "b" constant in DAT rather than the "a" constant definition.

    CON
    
    a = $12345678
    
    VAR
    long num1
    long num2
    long num3
    long num4
    long num5
    long num6
    long num7
    long num8
    long num9
    
    PUB start
      num1 := a
      num2 := a
      num3 := a
      num4 := a
      num5 := a
      num6 := a
      num7 := a
      num8 := a
      num9 := a
    
    DAT
    b long $12345678 
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2010-03-03 13:26
    I am glad I asked, it always pays to ask because I learn something in the process.

    Heater, with your last example, what is it about the way that SPIN handles a CON vs a DAT that causes 6 less longs?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
    www.tdswieter.com
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2010-03-03 13:29
    Maybe I answered my own question. From studying the Hex output it looks like with the CON that it uses the value over and over. With the DAT is references the value once. I also see with the DAT it appears to store the number backwards.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
    www.tdswieter.com
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2010-03-03 13:35
    One disadvantage to having CON in the dat section is that any calling code outside of the file can't use the Object#con construct because it can't get the value out of DAT.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
    www.tdswieter.com
  • BeanBean Posts: 8,129
    edited 2010-03-03 14:06
    You can use

    mov reg,#_SO_MR & $1FF 
    movd reg,#_SO_MR >> 9
    


    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.

    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf


    Post Edited (Bean) : 3/3/2010 2:11:07 PM GMT
  • heaterheater Posts: 3,370
    edited 2010-03-03 14:14
    "I also see with the DAT it appears to store the number backwards."

    The Prop. is the only architecture + language system I've seen that is both big endian and little endian at the same time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • VIRANDVIRAND Posts: 656
    edited 2010-03-03 16:13
    heater said...
    "I also see with the DAT it appears to store the number backwards."

    The Prop. is the only architecture + language system I've seen that is both big endian and little endian at the same time.
    interesting... might explain a lot of peculiar results trying to pass dsp-like data between spin and pasm.

    I also assume that CON was not assigned any memory but merely put labels on constants used during
    compile time, but obviously if a label is used more than once it would be part of each instruction
    that used the same labeled constant.

    DAT still seems hard to accurately find and point to when used as data storage, with labels there not
    easily evaluated consistently, and @ tending to always miss them by 16 or some random number. Has
    it ever been conveniently solved to determine the address of a label in DAT? I seem to invent a lot of
    wheels every time I need to access DAT space, and I just thought of searching HUBRAM for strings at
    the beginning of DAT such as "DAT0", but that makes a long, which you say the endianness is not
    consistent, so longs like $F000000F and $FF0000FF would might work as palindromes but may not be
    unique and rare enough to use, like $F5A00A5F or $B0DA_AB0D. (Which a small loop would search
    for and when found, result in a reliable pointer to a DAT block in both spin and pasm). What method
    is simpler than such contrivances and also consistent?
    edit: endianness in longs can be so variational that this new strange way might require them to be
    more like $FF0000FF and $00FFFF00 until they are exactly specified, with those two non-unique
    examples possibly being the only generally valid ones until it is known how they are stored in
    every possible case. When, if ever, does a long or a string appear backwards or mixed up in DAT
    if it is used or changed by both spin and pasm? I only noticed this problem with the internal font
    before, and assumed that only the video generator was shifting the less obvious way.

    Post Edited (VIRAND) : 3/3/2010 4:34:20 PM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-03-03 17:10
    I use this if I want the constant accessible to the outside and/or visible near the top of my code:

    CON
    
      MY_BIG = 1234567
    
    PUB start
    
    ...
    
    DAT
    
    ...
            mov     reg,_my_big
    
    ...
    
    _my_big long    MY_BIG
    
    
    


    It takes no more room than the movs/movd tango and is quicker to execute and more readable. (I typically write constant labels using all caps to distinguish them from variables.)

    For plain numeric constants that don't need a descriptive name, I use something like this:

            mov     reg,_0x0012_34cd
            mov     reg2,_512
    
    ...
    
    _0x0012_34cd long $0012_34cd
    _512         long 512
    
    
    



    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 3/3/2010 5:18:43 PM GMT
Sign In or Register to comment.