Moving Bytes
I have a few places in code where I move bytes around like this:
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:
I'd much rather prefer something like
But I'm not sure how to set up the address indirection.
Joe
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
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 RETURNIn 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
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 J. Couture
San Diego Miramar College