Array implementation in Assembly
Iratenate
Posts: 7
I'm interested in implementing an array in assembler code. Is it possible?
I would think memory declaration would be something like:
arrayName res 8
for an array of 8 longs, but how would I reference a specific cell? How would I write to a specific cell?
I would think memory declaration would be something like:
arrayName res 8
for an array of 8 longs, but how would I reference a specific cell? How would I write to a specific cell?
Comments
This is an example given to me by Mike Green
So if I understand this correctly.....
The self modifying code treats the value stored at register :moveIt as any other variable.
movd sets the destination register to the new array 0th spot
movs sets the source register to the original array 0th spot
mov count, #5 sets up the loop
mov 0-0,0-0 executes the mov command on the data previously stored at :moveIt. The 0-0 place holder makes it so the data in the source and destination fields is not overwritten?
%1000000001 is added to to :moveIt, effectively incrementing both source and destination register locations.
repeat 5 times.
Makes sense, somewhat. I think I got it.
Thanks!
One more question. Where can I find out more info on the place holder and its uses?
> The 0-0 place holder makes it so the data in the source and destination fields is not overwritten?
No, that would not completly be correct.
:moveIt is just a label name for your assembler to know what space in ram you are referring to.
The assembler think you are creating a command that looks like: mov 0,0
But before your executed code comes to this position, you have already changed the value 0 and 0
to ram addresses that the labels RxBuffer and otherBuf represents (eg self modyifing code)
As pasm uses absolute values for ram location and not the difference from * (here) in a -512 to 512
and also a fix bitwith(32) for each and every instruction.
It makes it very ease to point to a new ram location by just increasing that part of the code line.
I'm not sure whether you understand what's been said or whether I understand what you said.
Each PASM instruction has a structure. There are some bits that tell the COG what instruction it is, there are some bits which tell what to do with flags and result, there are 9 bits which tell the COG the destination address and there are 9 bits for the source address or a nine bit immediate value (depending on another bit in the instruction) - all in all 32 bits.
movd simply replaces the destination address of the instruction that's found at the destination address of movd (:moveIt in this case)
#rxBuffer means that the address of rxBuffer (the COG-RAM address) is stored as destination address.
movs replaces the source address of the instruction that's found at the destination address of movs.
#otherBuf means that the address of otherBuf is stored as source address.
So, when mov 0-0, 0-0 is executed the first time it will find the address of rxBuffer as source and the address of otherBuf as destination, so it will copy the content of rxBuffer to otherBuf. Of course this overwrites whatever was at otherBuf before.
The instruction in that time is:
mov otherBuf, rxBuffer
%x000000001000000001
%xdddddddddsssssssss
x=bits 18-31
d=destination address
s=source address or immediate value
So, if you add %000000001000000001 you increment the source and the destination by 1
So, in the 2nd iteration the instruction at :moveIt is:
mov (otherBuf+1), (rxBuffer+1)
The placeholder is nothing else but a convention. It makes it easier to identify code which is meant to be self-modifying. You can write what you want, as its overwritten anyways by movd and movs.
Thanks.
Not exactly. The place holder is there for the human that reads the code. It just marks the part of the instructions that are modified so you can understand the source code better.
For the compiler it does not matter, you can set these placeholders to anything (valid), they get anyway overwritten by the code at runtime.
Andy