-
How to do this in ASM?
Can someone tell me how I could write assembly that does the same as the following line would in PBP:
array[index]=my_data.Byte0
assuming that the variables are already declared as follows:
array VAR BYTE[12]
index VAR BYTE
my_data VAR WORD
I was trying to work out an ASM equiv but came up empty.
*edit* Its for a 16F84A
-
-
Sorry... its for a 16F84A
-
Untested, off the top of my head. At least the F84 makes it easy, with only 1 bank of RAM
Code:
ASM
movlw low _array ; load FSR with address of the array
movwf FSR
rlf _index,W ; mult. index * 2 since array is WORDs
addwf FSR, F ; add result to FSR
movf INDF, W ; get the LowByte
movwf _my_data
incf FSR, F ; point to next byte
movf INDF, W ; get the HighByte
movwf _my_data + 1
ENDASM
<br>
-
i think thats the reverse of what i want, ie: my_data.Byte0=array[index]
but i think im getting the idea... a couple of questions tho..
i take it "low" infront of a veriable gives its memory address?
and how does this FSR thing work? ive never had to use it before.
Thanks
-
yup, you're right, it's backwards. That's what I get for trying to squeez in a reply when the boss isn't looking. :)
low is like LowByte or Byte0 in PBP, it just gives the lowest 8-bits of a value.
And, the FSR allows you to Read/Write the value of any RAM location by placing the address of the desired byte in the FSR register, and then reading/writing to/from the INDF register.
It's kind of like using PEEK and POKE in PBP.
It sounds like you might be able to take it from there, but if not let me know, and I'd make it work the other way around when I get off work.
<br>
-
Im needing to do this becuase im writing a pbp program that has interrupts that are required to be written in ASM.
If I declare a variable in pbp as a word, e.g. my_data VAR WORD, can I then use the variable _my_data in ASM as is?
for example, can i do rrf _my_data,1 and expect the whole word to be rotated?
-
The only other thing I dont get is how to get the base memory address of the array. Looking at your code here and the comment, i cant see how its doing what the comment said it does:
movlw low _array ; load FSR with address of the array
movwf FSR
Thanks for ur help
-
>> can i do rrf _my_data,1 and expect the whole word to be rotated?
No, it only works with 1 byte at a time. But, the rrf rotates through the CARRY flag, so a second rrf on the next byte will rotate the CARRY right into the next byte.
>> I dont get is how to get the base memory address of the array
At the ASM level, that's what variables are, pointers(address) to the actual memory location in RAM. So low _array gives you the lowbyte of the address of the variable array.
<br>
-
Kamikaze,
Ok, let's try this one more time. I think this is what you're after. And, since you're using it in an interrupt, it save/restores the FSR so it doesn't interfere with normal PBP operations.
Code:
fsave var byte
ASM
movf FSR, W ; save current FSR value
movwf _fsave
movlw low _array ; load FSR with address of the array
movwf FSR
movf _index,W ; get index value
addwf FSR, F ; add index to FSR
movf _my_data, W ; get my_data.Byte0
movwf INDF ; put it in the array
movf _fsave, W ; restore the original FSR
movwf FSR
ENDASM
-
Thanks for that Darrel... Looks like it will do what I want :)