Micro Session3 Done
Micro Session3 Done
Clara Zaiter
[email protected]
• FSR0, which is a 16-bit register (FSR0 = FSR0H:FSR0L), is hence employed to store the 12-bit
address of a register.
To load a pointer with a certain address, the load fsr (lfsr) instruction is used
Data Move instructions
Operations on WREG and Register f
Example
Operations on WREG and Literal K
Truth tables
Status Register
This register reflects the status of the ALU after an arithmetic or a logical operation
is executed.
➢Logic operations are responsible for OR, XOR, AND, 1’s complement, etc.
Status Register bits
➢Zero bit Z
▪ This flag is set if the 8-bit result of an arithmetic or logic operation is zero; otherwise, it is
cleared.
➢Carry bit C
▪ This flag is set by the ALU when the result of an addition operation (i.e. addwf or addlw) is greater than 255;
if not, the C bit is cleared.
▪ In the context of subtract operations (subwf and sublw), this flag is also called BORROW (active low).
▪ The carry bit is also affected by rotate-through-carry instructions (rrcf and rlcf). When an 8-bit register is
rotated the carry bit is fed into one end of the register and the bit that is shifted out at the opposite end goes
into the carry.
Status Register bits
➢Negate bit N
▪ This flag is set to point out that the result of the instruction is negative (most significant bit of
the result is set); otherwise, it is cleared.
➢Overflow bit OV
▪ This flag is set when the addition of two 8-bit binary numbers of the same sign generates a result of the
opposite sign; otherwise, OV is cleared.
Effect of arithmetic/logic instructions on the STATUS register
Example 1:
movlw 0xFE
addwf RegA, W
=> Loads 0xFE into WREG, adds WREG to RegA, and stores the result in WREG.
movlw 0x0F
andwf RegA, F
=> Loads 0x0F into WREG, performs a bitwise AND with RegA, and stores the result
in RegA.
comf RegA, F
=> Complements all bits in RegA (bitwise NOT) and stores the result back in RegA.
movlw 6
sublw 5
=> Loads 0x06 into WREG and subtracts WREG from 5, with the result stored in
WREG.
decf RegA, F
incf RegA, W
bcf STATUS, C
rlcf RegA, W
Clears the Carry bit, then rotates RegA to the left, with the result stored in
WREG.
bcf STATUS, C
rlncf RegA, F
Clears the Carry bit, then rotates RegA to the left without carry, with the result
stored back in RegA.
movlw 0x0F
xorwf RegA, W
Loads 0x0F into WREG, performs a bitwise XOR with RegA, and stores the result
in WREG.
movlw 0x55
iorwf RegA, W
Loads 0x55 into WREG, performs a bitwise OR with RegA, and stores the result in
WREG.
setf RegA
movff RegA, RegB
negf RegA
Sets all bits of RegA (making it 0xFF), moves RegA to RegB, then negates RegA (2’s
complement).
movlw B'11000011’
setf RegA
comf RegA, F
Loads binary 11000011 into WREG, sets all bits in RegA to 1 and complements RegA.