Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

INSTRUCTION SET in PIC 16f877a

Status
Not open for further replies.

PA3040

Advanced Member level 3
Joined
Aug 1, 2011
Messages
883
Helped
43
Reputation
88
Reaction score
43
Trophy points
1,308
Activity points
6,929
Dear All,

Reference MCU is 16f877a
Please see picture

In this picture the locations A and B and C has relation ship. am I right?

I mean

ADDWF ia 6 bit OPCODE
00 0111 is the machine code after decode by MCU

Therefore
ADDWF = 00 0111

as per code list in INSTRUCTION SET in PIC 16f877a data sheet, I think it not needs six bit, I think can manage by four bits
am I right

CODE.GIF
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
15,153
Helped
4,944
Reputation
9,909
Reaction score
4,755
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
128,697
The 16F877A has 35 instructions in it's set so it needs 6 bits to be able to cover their numerical range. (35 in binary is 100011 although zero would also be a valid code). With only four bits there would only be enough to define 16 instructions.

If you look at the instruction set you will notice there is a pattern to the bits and that Microchip did a good job of optimizing the instructions. Some codes are not used on the 877A but bear in mind that other PICs have features which use the missing codes. It helps to keep the different devices as 'code compatible' as possible.

However, I wouldn't worry about the binary make up of the instructions as you rarely if ever need to use them. The assembler or compiler will automatically work out what the bits should be and embed them in a .hex file for you to program into the chip.

Brian.
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating

PA3040

Advanced Member level 3
Joined
Aug 1, 2011
Messages
883
Helped
43
Reputation
88
Reaction score
43
Trophy points
1,308
Activity points
6,929
The 16F877A has 35 instructions in it's set so it needs 6 bits to be able to cover their numerical range. (35 in binary is 100011 although zero would also be a valid code). With only four bits there would only be enough to define 16 instructions.

If you look at the instruction set you will notice there is a pattern to the bits and that Microchip did a good job of optimizing the instructions. Some codes are not used on the 877A but bear in mind that other PICs have features which use the missing codes. It helps to keep the different devices as 'code compatible' as possible.

However, I wouldn't worry about the binary make up of the instructions as you rarely if ever need to use them. The assembler or compiler will automatically work out what the bits should be and embed them in a .hex file for you to program into the chip.

Brian.

Thanks brian,
I got the point
please see picture

Different OPCODE and same machine codes

what about this
please guide

inc.GIF
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
15,153
Helped
4,944
Reputation
9,909
Reaction score
4,755
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
128,697
The opcode is not always 6 bits wide, in some cases it is 7 or 8 bits wide. It all depends on the instruction, for example CLRW implicitly clears the W register so there is no need to include a bit number or register number in the instruction. Microchip cleverly designed the instruction set so it made best use of the number of bits need for each instruction. When bits and addresses have to included they used shorter opcodes so they would all still fit in 14 bits.

When you see the first 6 bits are the same, you will notice the 7th or 8th bits are always fixed at 0 or 1.

Brian.
 

yuvko

Member level 4
Joined
Sep 5, 2007
Messages
74
Helped
19
Reputation
38
Reaction score
17
Trophy points
1,288
Activity points
1,596
bit 7, defines the target of the operation - W register or other register F, therefore CLRF and CLRW will only differ by that bit. in the same logic mov W reg to itself is equal to nop.
 

PA3040

Advanced Member level 3
Joined
Aug 1, 2011
Messages
883
Helped
43
Reputation
88
Reaction score
43
Trophy points
1,308
Activity points
6,929
The opcode is not always 6 bits wide, in some cases it is 7 or 8 bits wide. .

Brian.

Thanks Brian,

Please see picture
General Format for Instructions. Byte-oriented OPCODE's are always six bit

Please explain

byte.GIF
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
15,153
Helped
4,944
Reputation
9,909
Reaction score
4,755
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
128,697
I think you are reading too much into the description of the bit fields. In real life the only time you ever need to use these is when writing your own assember system.

The table in the data sheet is "General" format, if you look closely some of the byte oriented instructions the following bit is specifed to be fixed as 0 or 1 which makes it a 7-bit opcode. You will also see that some of the byte oriented opcodes have the same first 6 bits as opcodes in other categories. For example 'movwf', 'clrwdt', 'sleep' and 'return' all start with 000000 but other bits in the opcode are different from each other.

It might be helpful for you to create your own table of opcodes, based on the numeric value rather that opcode type, you will see that each opcode really does have it's own unique bit pattern, whether it is 6, 7 or 8 bits wide. If it didn't the PIC wouldn't know which instruction it ws to execute.

Brian.
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top