UWI大二电计专业学生关于PIC16F877指令集符号的技术问询
Hey there! As someone who’s spent a lot of time tinkering with the PIC16F877 (especially in assembly), I totally get why those highlighted MSB (Most Significant Bit) and LSB (Least Significant Bit) symbols in the instruction set feel confusing at first. Let’s break this down clearly, tied directly to the three main instruction formats the PIC16F877 uses:
1. MSB (Bit 13/15, depending on instruction length)
The MSB acts as a core identifier for instruction type and length:
- 12-bit instructions (e.g.,
MOVLW,CLRW,RETFIE): The top two bits (bit13 and bit12) are fixed as11, so the MSB (bit13) tells the microcontroller "this is a short, immediate/control-focused instruction" rather than a longer register operation. - 14-bit instructions (most core ops like
MOVWF,ADDWF,BTFSC): The MSB (bit13) is part of the instruction’s opcode. For example, a0in bit13 signals a register-to-register operation, while specific1values map to dedicated control instructions. - 16-bit instructions (e.g., extended
CALL,GOTO): The MSB (bit15) marks this as an extended instruction, letting the PIC access its full 8KB program memory (since 14-bit instructions can only reach the first 4KB).
2. LSB (Bit 0)
The LSB is almost always a functional control bit or part of a data/address field:
- Register operation instructions (e.g.,
ADDWF,ANDWF,IORWF): This bit decides where the operation’s result is stored. A0sends the result back to the target file register (F), while a1routes it to the W register (the PIC’s accumulator). For example:ADDWF STATUS, 0→ Result stored in the STATUS registerADDWF STATUS, 1→ Result stored in the W register
- Bit-test instructions (e.g.,
BTFSC,BTFSS): The LSB is the lowest bit of the 4-bit "bit select" field, which specifies exactly which bit in the target file register you’re testing. - Immediate value instructions (e.g.,
MOVLW): The LSB is just the least significant bit of the 8-bit immediate value you’re loading into the W register.
Quick Example to Tie It All Together
Take the assembly instruction MOVWF 0x25 (move the W register’s value to file register 0x25):
- Its 14-bit machine code is
000001001010000 - MSB (bit13) is
0→ tells the PIC this is a 14-bit register operation - LSB (bit0) is
0→ part of the 11-bit file register address (0x25 = 00100101, filling bits10-0 of the instruction word)
Grasping these bits isn’t just textbook stuff—if you ever need to debug assembly code at the machine level, or optimize tight loops by hand-coding machine instructions, knowing what MSB/LSB do will save you a ton of head-scratching.
内容的提问来源于stack exchange,提问作者Aadi

