Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 791
user Avatar asked Jul 03 '26 21:07

user


1 Answers

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
like image 82
GJ. Avatar answered Jul 06 '26 12:07

GJ.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!