Shop OBEX P1 Docs P2 Docs Learn Events
Moving Bytes — Parallax Forums

Moving Bytes

JDOhioJDOhio Posts: 72
edited 2006-08-11 04:25 in General Discussion
I have a few places in code where I move bytes around like this:

FOR Index=0 to 6
    There(Index)=Here(Index)
NEXT




Since I have a few places, I would rather have a subroutine to call such as

MoveBytes Here,There, 6

I'm not familiar with a couple things.

1) How might I pass the address of a memory location to a subroutine?
2) Once I am in the subroutine, how might I read one location and place it in another?
3) Did I make this too hard?

This was my attempt:

temp1=4
ASM
MOV __PARAM1,#Here & $FF
MOV __PARAM2,#Here >> 8
MOV __PARAM3,#There & $FF
MOV __PARAM4,#There >> 8
MOV FSR,#__PARAMCNT
MOV IND,#4
MOV FSR,#$10 
CALL @__MoveBytes
ENDASM

MoveBytes:
temp2=__PARAM1
temp3=__PARAM2
tempA=__PARAM3
tempB=__PARAM4
FOR ACount=0 to temp1
    READ temp2+temp3,temp4
    ASM
        MOV FSR,#tempA+tempB
        MOV IND,temp4
        INC tempB
    ENDASM
NEXT

RETURN




I'd much rather prefer something like

MOV W,#Here                ;                      There(Index)=Here(Index)
ADD W,Index                     
MOV FSR,W                     
MOV __PARAM2,IND              
MOV FSR,#$10                  
MOV W,#There          
ADD W,Index                     
MOV FSR,W                     
MOV IND,__PARAM2




But I'm not sure how to set up the address indirection.

Joe

Comments

  • BeanBean Posts: 8,129
    edited 2006-08-11 02:03
    This will do it...

    DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ 4_000_000
     
    here  VAR Byte (7)
    there VAR Byte (7)
     
     
    CopyBytes SUB 3
     
     
    PROGRAM Start NOSTARTUP
     
     
    Start:
      PUT here, "ABCDEFG"
      CopyBytes here, there, 7
    END
    
     
     
    CopyBytes:
      ASM
    :Again:
        MOV W,__PARAM1
        MOV FSR,W
        MOV W,IND
        MOV __PARAM4,W
        MOV W,__PARAM2
        MOV FSR,W
        MOV W,__PARAM4
        MOV IND,W
        INC __PARAM1
        INC __PARAM2
        DJNZ __PARAM3, :Again
      ENDASM
      RETURN
    

    In SX/B array names are just constants into the virtual __RAM array.

    So you can do "tempbyte = __RAM(here)"

    or you can assign the variable name to a byte variable and use that as an index into __RAM

    tempByte = here
    __RAM(tempByte) = "A" ' Same as here(0) = "A"
    INC tempByte
    __RAM(tempByte) = "B" ' Same as here(1) = "B"
    

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh


    Post Edited (Bean (Hitt Consulting)) : 8/11/2006 2:09:13 AM GMT
  • John CoutureJohn Couture Posts: 370
    edited 2006-08-11 04:25
    Ooo! Ooo! Bean, make sure that makes it into the SX/B manual .... maybe a section on "advanced coding techniques". Very kool!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
Sign In or Register to comment.