user
user

Reputation: 31

Assembly instruction to machine code

I'm trying to convert MOVFF 0x10, 0x15 to machine code. The Microcontroller is Microchip PIC 18F1220. The reference manual says:

MOVFF fs,fd

Encoding:
1st word: 1100 ffff ffff ffffs
2nd word: 1111 ffff ffff ffffd

The solution is:

1100 0000 0010 0000
1111 0000 0010 0101

But the solution I'm getting is

0x10 = 0001 0000
0x15 = 0001 0101
1100 0000 0001 0000
1111 0000 0001 0101

Can you please explain me how to get the right answer?

Thank you

Upvotes: 3

Views: 1744

Answers (1)

GJ.
GJ.

Reputation: 10937

Everything is OK.

movff is 2 words instruction (each word is 16 bits long).

movff instruction word starts with bits b'1100' and than follow 12 bits for source byte address in your case 0x10. After that instruction follow 'destination instruction word' which starts with b'1111' and than follow 12 bits for destination byte address in your case 0x15.

If you will jump (branch) to only 'destination instruction' then a nop should be performed.

On this way is possible to address 4096 bytes of RAM under PIC18 (what mean whole RAM).

EDIT: added simple test case output file for PIC18F1220:

---  C:\WORK\TEST\Test.asm  ----------------------------------------------
                                                  1:        org 0
                                                  2:     fs equ  0x10
                                                  3:     fd equ  0x15
   000    C010     MOVFF 0x10, 0x15               4:        movff   fs, fd
   002    F015     NOP
   004    C010     MOVFF 0x10, 0x15               5:        movff   0x10, 0x15
   006    F015     NOP

Upvotes: 2

Related Questions