0% found this document useful (0 votes)
52 views33 pages

Week 6

The document discusses various topics related to microprocessor systems and interfacing, including: 1. An assignment to write an assembly program for an Atmega328P microcontroller to control LEDs using various ports and registers. 2. Logic and comparison instructions like AND, OR, XOR, COM, NEG, and CP. 3. Shift instructions including LSL, LSR, and ASR. 4. Addressing modes for accessing data like single-register, register, direct, register indirect, flash direct, and flash indirect.

Uploaded by

aroosa naheed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views33 pages

Week 6

The document discusses various topics related to microprocessor systems and interfacing, including: 1. An assignment to write an assembly program for an Atmega328P microcontroller to control LEDs using various ports and registers. 2. Logic and comparison instructions like AND, OR, XOR, COM, NEG, and CP. 3. Shift instructions including LSL, LSR, and ASR. 4. Addressing modes for accessing data like single-register, register, direct, register indirect, flash direct, and flash indirect.

Uploaded by

aroosa naheed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

EEE-342 Microprocessor

System and Interfacing 4(3,1)


Lecture 10,11……
Lecture
Assignment-1 last question
• Write the assembly program for Atmega328P to control the LEDs connected to
PORT-C. The DDRC register must equal to your Reg# and single control switch is
connected at PD3.
• Identify the total number of LED used.
• Draw program flow chart.
• Write pseudocode
• Write the assembly program.
Logic and Compare Instruction
• And
• Or
• Ex-or
• Com
• Neg
• Cp
AND
Ex-or
COM(complement)
• COM(complement)

• 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

• RAMEND is defined equal to the address of


the last location of the memory.
Lecture
ADDRESSING MODES
Various ways of accessing data are called addressing modes.
1. Single-Register (Immediate)
2. Register
3. Direct
4. Register indirect
5. Flash Direct
6. Flash Indirect
Single-Register (Immediate)
• Single-register (immediate) addressing mode
Register
• Two-register addressing mode
Direct
• Accessing entire data memory directly is called Direct addressing
mode
Register indirect
• In the AYR, three registers are used for this purpose: X, Y, and Z. These
are 16-bit registers allowing access to the entire 65,536 bytes of data
memory space in the AVR.
• For example, "LDI XL,0x31" is the same as "LDI R26,0x31“
LD Instruction
• The 16-bit registers X, Y, and Z are widely used as pointers. We can
use them with the LD instruction to read the value of a location
pointed to by these registers.
Auto-increment and auto-decrement options
for pointer
Register indirect with displacement
• LDD Rd, Z+q ; load from Z+q into Rd

• LDD R20, Z+5 ;load from Z+5 into R20


Flash Direct
• Writing data to program memory.
• Use .DB and .DW directives
. DB (define byte)
Flash Indirect
• This is an addressing mode widely used to access data elements
located in the program space of the AVR using pointers.
• Two Modes
• program memory constant addressing and
• program memory addressing with post-increment.
Copying a bit
Manipulating the bits of I/0 registers

You might also like