Download DB038 - Van Ooijen Technische Informatica
Transcript
DB038 : A PIC experiments board version 2.00 placement of code and data in the PIC address ranges. The presence of a linker script in the list of project files selects relocatable mode, the absence selects absolute mode. 3.2 Data load and store There MOVLW instruction loads the W register with a literal. The MOVWF instruction saves the W register to a memory location. These instructions do not affect the flags. The MOVFW instruction that loads the W register from a memory location is technically an arithmetic instruction: it affects the zero flag, and its destination can be either the W registers or (!) the memory location. The CLRW instructions clears the W register, the CLRF instruction clears a memory location. Both set the zero flag. Operation W := n [ a ] := W W := [ a ] W := 0 [ a ] := 0 Opcode MOVLW n MOVWF a MOVF a, W MOVFW a CLRW CLRF a Notes affects Z sets Z sets Z Note that the assembler accepts “MOVFW a” as synonym for “MOVF a,W”. 3.3 Arithmetic and logic instructions The monadic (one-operand) instructions operate on the content of a memory location specified in the instruction. The result can be stored either in the memory location or in W. These instructions include increment, decrement, rotate left, rotate right, swap nibbles, and (!) move. Operation Increment Decrement Rotate right Rotate left Swap nibbles Move Opcode for W := f( [ a ] ) INCF a, W DECF a, W RRF a, W RLF a, W SWAPF a, W MOVF a, W notes [ a ] = f( [ a ] ) INCF a, F DECF a, F RRF a, F RLF a, F SWAPF a, F MOVF a, F affects Z affects Z involves C involves C affects no flags affects Z Note the rather peculiar instruction “MOVF a, F”. This instruction copies the content of a memory location to … that same memory location. Its only useable effect is that it sets or clears the Z flag depending on whether the content is zero or not. The dyadic (two-operand) arithmetic instructions have two forms. The first form is like the monadic instructions. It operates on a memory location specified in the instruction, uses the W register as second operand, and can store the result either in the memory location or in W. The second form operates on an 8bit constant, uses the W register as second operand, and stores the result in the W register. The arithmetic operations that can be done in both forms are add, subtract, and, or and xor. Note that W is the second operand, not the first. This makes a difference for subtraction only, but has confused many people. Add and subtract affect all three flags. Rotate involves the carry bit. The others affect only the zero flag, except swap nibbles which affects no flag at all. For subtracting the carry flag is set when no carry occurs and cleared when a carry occurs, so it is often referred to as the carry - /borrow flag: carry refers to the carry for addition, /borrow refers to the negated (the / is used to indicate negation) borrow for subtraction. (c) Van Ooijen Technische Informatica - Wouter van Ooijen page 36 of 74