working with data arrays in PASM for P2
ti85
Posts: 44
in Propeller 2
If you have an array of data in the data section in PASM (such as)
Dat
temp long $C9,$C2,$09,$40,$07
And you want to read each data (value) one by one into a variable to perform some calculation…such as sum the five numbers together. How do you do that for the P2? It looks that the movs and movd instructions have been removed from the P2 architecture.
Comments
If you use PTRA or PTRB then you can do this
mov ptra,##temp
rdbyte xxx,ptra[n]
where n can be an offset IIRC -31 to +32 (might be -15 to +16 so you need to check). There’s also ptra++ option too.
Thank you for the quick reply, but I was thinking about an array (or pointer addressing) in COG ram not HUB ram. Sorry for the confusion
For indirect read from cog memory, you should use ALTS and ALTD to modify the source or destination address of the next instruction (see manual).
MOVS and MOVD are still avalable but have changed there names to SETS and SETD, I think. But you should not use them, the ALTx methode is faster and works also with hubexec.
Andy
There was already a thread about clarification of the ALTx instructions (https://forums.parallax.com/discussion/172803/p2-pasm-syntax-clarifications-altx).
Packed byte arrays in cogRAM can be dealt with using ALTGB prefixing of GETBYTE, and ALTSB prefixing of SETBYTE. Documented in the Register Indirection section of hardware doc.
thank you for the help! Are there any examples of the getbyte instruction being used in the programs that come with the propeller tool ide. I have better luck working through examples
The hardware doc has snippets that are helpful.
Here's one from my own debug code that prints hexadecimal out the serial port:
Excuse the messed formatting. The forum software needlessly auto replaced the tabs.
I converted a Spin program to PASM -- it uses a table. In this case, I'm extracting nibbles from a byte table, but working with other sizes just takes an instruction change.
pri main2(base, tix) | pinfield, offset, t, hipin, lopin ' runs forever!
org
mov pinfield, #7 ' create pin field for 8 pins
shl pinfield, #6
or pinfield, base
mov offset, #0 ' initialize offset
getct t ' initialize led timer
.loop altgn offset, #.lut ' point to low pin
getnib lopin ' read it
add lopin, base ' adjust for base pin
add offset, #1 ' bump to high pin for this led
altgn offset, #.lut ' point to high pin
getnib hipin ' read it
add hipin, base ' adjust for base pin
incmod offset, #111 ' increment with rollover
fltl pinfield ' clear last led
drvl lopin ' light current led
drvh hipin
addct1 t, tix ' update timer
waitct1 ' let it expire
jmp #.loop
.lut byte $01, $02, $03, $04, $05, $06, $07, $10
byte $12, $13, $14, $15, $16, $17, $20, $21
byte $23, $24, $25, $26, $27, $30, $31, $32
byte $34, $35, $36, $37, $40, $41, $42, $43
byte $45, $46, $47, $50, $51, $52, $53, $54
byte $56, $57, $60, $61, $62, $63, $64, $65
byte $67, $70, $71, $72, $73, $74, $75, $76
end