Low-level programming Lab 4 – Logic operations Useful instructions

advertisement
Low-level programming
Lab 4 – Logic operations
Useful instructions:
IORLW const – performs inclusive OR bit operation between constant const and contents of W
register (result in W register)
ANDLW const – performs AND bit operation between constant const and contents of W register
(result in W register)
XORLW const – performs exclusive OR bit operation between constant const and contents of W
register (result in W register)
IORWF file_reg, d – performs inclusive OR bit operation between file_reg and contents of W
register (d – direction: W (0) – result in W register, F (1) result in file_reg);
ANDWF file_reg, d – performs AND bit operation between file_reg and contents of W register (d –
direction: W (0) – result in W register, F (1) result in file_reg);
XORWF file_reg, d – performs exclusive OR bit operation between file_reg and contents of W
register (d – direction: W (0) – result in W register, F (1) - result in file_reg);
COMF file_reg, d – performs logic complement (inversion) operation of contents of file_reg (d –
direction: W (0) – result in W register, F (1) - result in file_reg);
RLF file_reg, d – performs shift (rotate) left operation of contents of file_reg (d – direction: W (0)
– result in W register, F (1) - result in file_reg); rotation is performed via Carry bit (C) in STATUS
register.
RRF file_reg, d - performs shift (rotate) right operation of contents of file_reg (d – direction: W (0)
– result in W register, F (1) - result in file_reg); rotation is performed via Carry bit (C) in STATUS
register.
SWAPF file_reg, d – exchanges the upper and the lower nibbles (4-bit) of register file_reg (d –
direction: W (0) – result in W register, F (1) - result in file_reg);
Problem to solve:
Write a code which do following actions in sequence:
• place a value B'01010101' in v1 variable;
• place a value B'10101010' in v2 variable;
• get a value from port B;
• perform OR operation between this value and variable v1 and send it to port B;
• perform OR operation between this value and variable v2 and send it to port B;
• multiply by 4 this value and send it to port B;
• divide by 4 this value and send it to port B;
• swap the nibbles of inversion of this value and send it to port B.
(5 numbers must be sent to port B in sequence)
Check written program in MPLAB SIM (debugger) from MPLAB IDE. Send written code via email
to a.klimowicz@pb.edu.pl.
Download