Lockedmovlw / movwf / movf /

Post
Guest
Super Member
2005/03/29 15:02:01
Hello.
I know c (so I know of pointers, for if this should be necessary..)
I have a little question:
(1) what are:
movlw ->literal to work register ; this one I know
movwf ->what is this "f" ? I don't understand this.
movf ->and this? what does this ?

(2) and; are there other mov's I should know of ??

Thanks in advance.
rglapion
Super Member
RE: movlw / movwf / movf / 2005/03/29 15:21:27
movwf - 'f' is a file register i.e. somewhere in ram. Check out the chapter called INSTRUCTION SET SUMMARY in each PIC datasheet. It explains all of the assembly language instructions.
Guest
Super Member
RE: movlw / movwf / movf / 2005/03/29 15:25:03
Thanks a lot.

are there pointers used in PIC assembly ??
rglapion
Super Member
RE: movlw / movwf / movf / 2005/03/29 15:37:54
In PIC18 you can use the TBLPTR to point to a Program Memory location. Download a datasheet!
Guest
Super Member
RE: movlw / movwf / movf / 2005/03/29 15:42:14
OK.Thanks. I'll do.
bob_barr
Super Member
RE: movlw / movwf / movf / 2005/03/29 15:58:25
are there pointers used in PIC assembly ??

Yes, it's described in the datasheet as 'indirect addressing' and uses the FSR register to point to the locations to be accessed.
Guest
Super Member
RE: movlw / movwf / movf / 2005/03/29 16:01:44
thanks. Now I start to get what this FSR register is.
(I understood very little of the book I've red because my englisch isn't good. Would have understood more of it if they directly used the word "pointer").
bob_barr
Super Member
RE: movlw / movwf / movf / 2005/03/29 16:11:44
Would have understood more of it if they directly used the word "pointer").

The term 'pointer' has another meaning in the C programming language. Microchip may have wanted to avoid creating confusion that might have been caused by using it in a different way when describing the chip's hardware.
Guest
Super Member
RE: movlw / movwf / movf / 2005/03/29 16:17:48
Well, in that case I'm not sure anymore I understand exactly what that FSR register is.
I know you'll probably refer me to the datasheet...
But could you give me a brief and simple explanation of FSR and INDF ??

...
400_up
Super Member
RE: movlw / movwf / movf / 2005/03/29 16:22:55
zztop,
The FSR is the "File Selection Register", INDF is not a physical register but it holds the data of the register selected by the FSR. So if the FSR has a value of 0x20 the INDF will hold the value of RAM address 0x20.
Guest
Super Member
RE: movlw / movwf / movf / 2005/03/29 16:28:25
so, in that case you can say that FSR is a pointer to the (non fysical) INDF register ? is this correct ?
If so, then "pointer" is the same in PIC-asm as in c/c++ ? Or not ?

Sorry that I ask so many questions in one time, but I like to understand what I'm doing as much as possible...

Thanks a lot.
400_up
Super Member
RE: movlw / movwf / movf / 2005/03/29 16:37:03
The FSR is the address and the INDF is the data.
Example

movlw byte
movwf FSR
movf INDF,W
movfw temp

This will put the value of byte (the word byte holds) into temp. It is not necessary that you know the address of byte. You could also use

movlw byte + 2

to access multiple byte values.
bob_barr
Super Member
RE: movlw / movwf / movf / 2005/03/29 16:40:04
If so, then "pointer" is the same in PIC-asm as in c/c++ ? Or not ?

It's similar but not exactly the same. Incrementing an integer pointer in C, for example, points it to the next integer (a two-byte increment). Incrementing the FSR register always increments it to the next byte address.
Guest
Super Member
RE: movlw / movwf / movf / 2005/03/29 16:51:31
The only thing I don't understand is why
"movwf FSR"
shoud mean that the address of byte is now in FSR and NOT the value

(because:
"movlw byte" copies the value of byte to the workregister, and
"movwf FSR" copies the content of the workregister (which is the value of byte) to FSR ...
so, according to this, it's the value , and not the address of byte which should be in FSR ?!)

thanks.
bob_barr
Super Member
RE: movlw / movwf / movf / 2005/03/29 16:58:56
The only thing I don't understand is why
"movwf FSR"
shoud mean that the address of byte is now in FSR and NOT the value

That's because FSR holds the address that will be used for the indirect addressing.

(because:
"movlw byte" copies the value of byte to the workregister, and
"movwf FSR" copies the content of the workregister (which is the value of byte) to FSR ...
so, according to this, it's the value , and not the address of byte which should be in FSR ?!)

If I had written that example, I would have used 'movlw addr' to indicate that an address was being put into the FSR register. The FSR register always holds an address; reading or writing INDF accesses that address.
Guest
Super Member
RE: movlw / movwf / movf / 2005/03/29 17:01:31
OK.
I think I got it completely now (at least, I hope).

Thanks a lot for your help and your patience (you allso, 400_up ).

Grtz.
400_up
Super Member
RE: movlw / movwf / movf / 2005/03/29 17:01:39
I'm sorry, I wasn't clear.

movlw byte ;moves the address of byte into the W register

movlw means "move a literal into W" in this case the literal is the address of byte. Any literal value between 0 and 255 could be used instead of byte. The assembler will use the address of byte as the literal when used in this way.

Then

movwf FSR ;make the FSR 'point' to the address of byte
movf INDF,W ;move the contents of the pointed to file (byte) into W
movwf temp ;move the contents of W into temp

Any help at all?
Guest
Super Member
RE: movlw / movwf / movf / 2005/03/29 17:08:17
so, is this correct:
(1)
movlw byte ->here the ADDRESS of "byte" is stored in the workregister
movwf FSR
movf INDF,W
movfw temp
(2)
movlw byte ->here the VALUE of "byte" is stored in the workregister
movwf ANOTHERREGISTER

so, you can say that (1) is just a special case , an exception where the assembler decides to copy an address because FSR allways needs an address ?!
< Message edited by zztop -- Mar. 29, 2005 5:08:45 PM >
bob_barr
Super Member
RE: movlw / movwf / movf / 2005/03/29 17:44:51
Let's go with an example (it's simplified but functional):

VAR equ 0x20

movlw 1 ; moves the literal value of 1 to w
movwf VAR ; stores the 1 into location VAR (this is direct addressing)

; somewhere else in the program

movf VAR, w ; get the value from location VAR into w (also direct addressing)


; new topic

movlw VAR ; moves the address of VAR to w
movwf FSR ; put it in FSR for indirect addressing

movlw 1 ; the literal value 1 again
movwf INDF ; stores it at the address pointed to by FSR (indirect addressing)

; sometime later (note: this assumes that FSR is still the same)

movf INDF, w ; get the value from the address pointed to by FSR (also indirect addressing)


'movlw' always moves a literal value into w, regardless of whether that value is just an ordinary number or the address of a variable.
< Message edited by bob_barr -- Mar. 29, 2005 4:45:43 PM >
Guest
Super Member
RE: movlw / movwf / movf / 2005/03/29 17:55:05
OK.
so the movwf is allways the same.

Really appreciated that you didn't loose your patience with my stupid (I see now...) questions.


Thanks a lot.
bob_barr
Super Member
RE: movlw / movwf / movf / 2005/03/29 18:22:08
Really appreciated that you didn't loose your patience with my stupid (I see now...) questions.

No problem, don't be so hard on yourself. This stuff takes some time to 'get your head around'.

One suggestion: Learn to use the MPLAB simulator. It will let you test code before you program it into a real chip. The simulator lets you single-step through your program's execution and watch the registers and RAM change as you do. There are a couple of introductory web seminars on the simulator available in the archives.
Guest
Super Member
RE: movlw / movwf / movf / 2005/03/31 11:27:04
OK.
I'll follow that advice.
magio
Super Member
RE: movlw / movwf / movf / 2005/03/31 13:27:02
ORIGINAL: zztop
Really appreciated that you didn't loose your patience with my stupid (I see now...) questions.

Stupid questions no... newbie questions that's all grin

learn something is the goal of being part of a forum. If you have something that was at first difficult and then seems to be easy is because you learned, not because you're questions were stupid.

Smile
Guest
Super Member
RE: movlw / movwf / movf / 2005/03/31 15:42:22
Why not just ditch ASM since you know C?
You can always look at the dissassembly for grins.
I'll climb up a tree to avoid using ASM.
Guest
Super Member
RE: movlw / movwf / movf / 2005/03/31 15:59:25
It's for my studies and I had 90% of the code, I just had to add+adapt...
so it should mean a HUGE effort converting all the asm to c...