Está en la página 1de 4

THE AVR INSTRUCTION SET

4.1 PROGRAM AND DATA ADDRESSING MODES The various AVR instructions can be categorized in about 10 different addressing modes. Each instruction has an opcode that indicates to the control logic of the processor what to do. The other part of the instruction is the operand, on which the opcode operates. 4.1.1 REGISTER DIRECT (SINGLE REGISTER) The Register Direct instructions can operate on any of the 32 registers of the register file. It reads the contents of a register, operates on the contents of the register, and then stores the result of the operation back into the same register. Figure 4.1 illustrates the source and destination for these types of instructions. The format of the instruction is: Mnemonic Destination Register. Examples of these instructions are as follows. Rd is any register from the register file and is the destination (as well as the source) register for the operation. COM Rd: 1s complement (invert all the bits) of the register Rd is stored back in register Rd. INC Rd: Increments the contents of Rd by one. DEC Rd: Decrements the contents of Rd by one. TST Rd: Test for zero or negative contents of the Rd register. CLR Rd: Loads $00 into the Rd register. SER Rd: Loads $FF into the Rd register. LSL Rd: Shifts the contents of register Rd one place to left. A 0 is shifted in bit position 0, and the contents of bit7 are copied to the Carry flag. LSR Rd: Shifts the contents of register Rd one place to Right. A 0 is shifted in bit position 7, and the contents of bit0 are copied to the Carry flag. ROL Rd: Rotate Rd register contents left through the carry. Carry flag goes to bit0, and bit7 goes into the carry. ROR Rd: Rotate Rd register contents right through the carry. Carry flag goes to bit7, and bit0 goes into the carry. ASR Rd: Arithmetic Shift right the contents of the Rd, keeping the bit7 at the same place. This achieves a signed divide by two for each shift. Swap Rd: Swap nibbles of the register Rd.

4.1.2 REGISTER DIRECT (TWO REGISTERS): In these types of instructions, two registers are involved. The two registers are named as the source register, Rs, and the destination register, Rd. The instruction reads the two registers and operates on their contents and stores the result back in the destination register. Figure 4.2 illustrates the source and destination for these types of instructions. Example instructions are: ADD Rd, Rs; SUB Rd, Rs; AND Rd, Rs; MOV Rd, Rs; OR Rd, Rs;

4.1.3 I/O DIRECT: These instructions are used to access the I/O space. The I/O registers can only be accessed using these instructions: In Rd, PORTADDRESS; Out PORTADDRESS, Rs. Rd, Rs can be any of the 32 registers from the register file, and the I/O registers can be any register from the entire range of $00 to $3F (a total of 64 I/O registers). Figure 4.3 illustrates how such instructions operate.

4.1.4 DATA DIRECT: These are two word instructions. One of the words is the address of the data memory space. So a maximum of 64 Kbyte data memory can be accessed using these types of instructions. The examples of these instructions are: LDS RD, K; K is a 16-bit address. STS K, Rs; Figure 4.4 illustrates how direct data instructions operate.

4.1.5 DATA INDIRECT: These are similar to the data direct type of instructions, except that these instructions are one word each, and a pointer register (X, Y, or Z) is used that has the base address of the data memory. To the base address in the pointer register, an offset can be added, as well as some increment/decrement operations on the pointer contents. Examples of these instructions are: LD Rd, X; X is the pointer register (register pair R26, R27); LD Rd, X_; Rd is the destination register and it is loaded with the contents of the data memory pointed to by the X register, and after the memory is accessed, the X register is incremented. ST X, Rs; ST X_, Rs; ST-Y, Rs; and so on. Figure 4.5 illustrates how one variant of indirect data instructions operate.

4.1.6 INDIRECT PROGRAM ADDRESSING: In these types of instructions, the Z register is used to point to the program memory. Up to 64 Kbytes of program memory can be accessed with the 16-bit Z register. Examples of these types of instructions are: IJMP and ICALL. Figure 4.6 illustrates how indirect program addressing instructions operate.

4.1.7 RELATIVE PROGRAM ADDRESSING: These instructions are of the type RJMP and RCALL, where an offset of _/_2K to the program counter is used. Figure 4.7 illustrates how relative program addressing instructions operate.

También podría gustarte