Week 6
Week 6
• NEG (negate)
This instruction takes the 2 's complement of a register
• Compare instructions
CP Rd,Rr, CPI Rd,k;
Shift instructions
• There are three shift instructions in the AVR
• LSL instruction
• LSR instruction
• ASR instruction
LSL instruction
Instruction multiplies the content of the register by 2 assuming
that after LSL the carry flag is not set.
LSR instruction
• LSR instruction divides the content of the register by 2 and the carry
flag contains the remainder of the division.
ASR instruction
• The ASR instruction can divide signed numbers by two.
SWAP instruction
BCD (binary coded decimal) number system
• Binary representation of 0 to 9 is called BCD.
• Unpacked BCD (8bit code)
• Packed BCD (4bit code)
For example, “0101 1001" is packed BCD for 59H
ASCII numbers
Packed BCD to ASCII conversion
• Example Real-time clock (RTC)
• To convert packed BCD to ASCII,
• 1st convert it to unpacked BCD.
• Then the unpacked BCD is tagged with 011 0000 (30H).
Chapter# 6
AVR ADVANCED ASSEMBLY LANGUAGE
PROGRAMMING
Constant values
• .EQU
• .EQU BETA= 40;
• Shift operators,
• Shift left and right a constant value
• LDI R16, 0b00000111<<1 ; R16 = Ob00001110
• M32DEF.INC
• names of the register bits are defined in the header files
M32DEF.INC (example 6-1)
HIGH( ) and LOW( ) functions
• LDI Rl6,LOW(0x4455) ; Rl6=0x55
• LDI Rl7,HIGH(0x4455) ; Rl7=0x44