Xytaglyph
Xytaglyph

Reputation: 1

PIC Programming: Moving Literal to File?

I am currently studying the PIC and we have used commands such as MOVLW (Move literal to Write regiser), MOVWF (Move write register to specified file location), etc. but I am curious as to why there is not a command that allows you to MOVLF, or move a literal directly to a file register? This would skip the step of using the write register, and take only 1 instruction cycle rather than 2.

Thanks for the help

Upvotes: 0

Views: 1190

Answers (4)

Joseph Julicher
Joseph Julicher

Reputation: 121

The technical reason why there is no movlf instruction on the 8-bit PICmcu's is due to the instruction width. There are 14-bits in the instruction word. These bits must be allocated to an opcode and a payload. The opcode width for the PIC16 is not a fixed amount of bits. Some instructions like CALL and GOTO have 3-bit opcodes to allow a 2KB reach without help. Other instructions like ALL of the literal instructions need an 8-bit payload (for the literals) so they only have 6 bits remaining... but wait, the file instructions need 7 bits (on a PIC16) to address the file registers so we must steal one bit of the literal opcodes to create a file address segment. We must also steal one bit of the literal opcodes to create ALL THE OTHER opcodes.....In any case, the instruction map fills up fast so you have to decide between instructions. In the case of your proposed instruction... movlf, this will require 7 bits of File address and 8-bits of literal address plus however many opcode bits are needed to find a spot in the ISA. Just the payload is 15 bits. The PIC18 solves this by making some 2-cycle instructions. These look like one instruction but will take 2 words in the program memory and require 2 CPU cycles to execute. An example is MOVFF. The PIC16 designers decided that since it took 2 words and 2 cycles, there was no loss in making the 2 instructions explicit. This is actually an advantage because 2 cycle instructions on the PIC18 add 1 cycle of uncertainty to the interrupt latency.

Upvotes: 0

GJ.
GJ.

Reputation: 10937

There are two 8 bit PIC families and instruction sets, PIC16 and PIC18 (and even PIC12)!

Remember this is RISC (reduced instruction code set).

The single PIC16 instruction is 14 bit wide and at PIC18 is 16 bit wide! So as you can see you can not put 8 bit address and 8 bit literal in to one intruction. However PIC16 have clrf instruction which put 0 to file register and PIC18 have also setfinstruction which put 255 to file register. You have also movlb instruction which put 5 or 4 bit literal to BSR file register to reduce your code at selecting 256 byte memory bank.

There are also two another single instruction which can help to you, bsf and bcf (at PIC18 also btg) but they can only set/clear single bit in file register (or also toggle single bit at PIC18).

Upvotes: 1

Mike
Mike

Reputation: 4288

In the PIC core one operand has always to be the w-Register. But you can help yourself with a macro:

MOVLF   macro   LITERAL, Register
        MOVLW   LITERAL
        MOVWF   Register
        endm

But know of course you need two cycles for this 'command'.

Upvotes: 0

Peter Cordes
Peter Cordes

Reputation: 365267

It's not unusual for rare operations to only exist with a register source/dest, not also an immediate.

For example, x86 move to segment register only has a register/memory source, but it's very often used with mov ax, @data (mov r16, imm16) / mov ds, ax (once at the start of small programs or boot sectors).

Having a separate opcode for a different form would use up limited coding space, reducing the number of different instructions you could use. Or it would make the decoders more complex.

It's annoying when your use-case needs a lot of something that the ISA designers decided wasn't important enough to do with a single instruction. :/

Upvotes: 0

Related Questions