SlideShare a Scribd company logo
Assembler Programming of Atmega328P
(Lecture-11)
R S Ananda Murthy
Associate Professor and Head
Department of Electrical & Electronics Engineering,
Sri Jayachamarajendra College of Engineering,
Mysore 570 006
R S Ananda Murthy Assembler Programming of Atmega328P
Storing Data in Flash Memory
Though flash memory is referred to as program memory,
we can also store fixed data in it using DB and DW
directives as shown above.
Since each word address in flash stores two bytes in
little-endian order, at any word address, the low-byte
address is twice the word address and the high-byte
address is low-byte address+1.
Determine the word and byte addresses in the example given
above.
R S Ananda Murthy Assembler Programming of Atmega328P
HIGH() and LOW() Functions
AVR assembler provides these two functions.
HIGH() returns the higher byte of a 16-bit value.
LOW() returns the lower byte of a 16-bit value.
These functions are typically used to initialize Z register to
point at data bytes stored in the flash memory before using
the LPM instruction.
For example:
LDI ZH,HIGH($100<<1);Initialize ZH.
LDI ZL,LOW($100<<1) ;Initialize ZL.
LPM
R S Ananda Murthy Assembler Programming of Atmega328P
Arithmetic and Logical Expressions in ALP
Arithmetic Operators Logical Operators
Symbol Operation Symbol Operations
+ Addition & Bitwise AND
− Subtraction | Bitwise OR
* Multiplication ^ Bitwise XOR
/ Division ~ Bitwise NOT
% Modulo << k Shifts left by k bits
>> k Shifts right by k bits
We can write arithmetic and logical operations in ALP using the
symbols given above.
R S Ananda Murthy Assembler Programming of Atmega328P
Examples of Arithmetic and Logical Expressions
R S Ananda Murthy Assembler Programming of Atmega328P
Device Definitions File
This file contains .EQU directives which define labels
assigned to various ports, port bits, registers and register
bits.
For Atmega328P device, this file is named as
m328pdef.inc
When we select a device for an assembly language project
in Atmel Studio, these definitions are available to the user
program through the device definitions file.
If we are not using Atmel Studio, then, we have to use
.INCLUDE directive to include the Device Definitions File in
the .asm file to use the standard labels.
R S Ananda Murthy Assembler Programming of Atmega328P
A Glimpse of Device Definitions File for Atmega328P
R S Ananda Murthy Assembler Programming of Atmega328P
Labels for Status Flags in m328Pdef.inc File
In m328Pdef.inc file, labels for status flags are defined as
shown above.
R S Ananda Murthy Assembler Programming of Atmega328P
Setting Specific Flags in SREG using Flag Labels
Labels for status flags can be used to set specific flags as
shown above.
R S Ananda Murthy Assembler Programming of Atmega328P
Labels Related to Memories in m328Pdef.inc File
We can use RAMEND to initialize Stack Pointer as shown later.
R S Ananda Murthy Assembler Programming of Atmega328P
Stack in Atmega328P
Stack is a portion of R/W memory which is used for storing
temporary data, for storing local variables and for storing
return addresses before executing subroutines or Interrupt
Service Routines.
In AVR MCUs, stack is, implemented as Last-In-First-Out
(LIFO), growing from higher memory to lower memory
locations.
PUSH Rr command will store the content of Rr in the stack
and then decrements the SP by 1.
POP Rd command will first increment the SP by 1 and
then, byte from the stack is copied to Rd.
R S Ananda Murthy Assembler Programming of Atmega328P
Stack Pointer in Atmega328P
In Atmega328P SP is a 16-bit register having two 8-bit
registers SPH and SPL in the I/O space of the R/W
memory in MCU as shown above.
In AVR MCUs having very small memory only SPL will be
present.
The Stack Pointer (SP) register always points to the top of
the stack.
R S Ananda Murthy Assembler Programming of Atmega328P
License
This work is licensed under a
Creative Commons Attribution 4.0 International License.
R S Ananda Murthy Assembler Programming of Atmega328P

More Related Content

What's hot

Microprogram Control
Microprogram Control Microprogram Control
Microprogram Control
Anuj Modi
 
Four types of motherboards
Four types of motherboardsFour types of motherboards
Four types of motherboards
siva muthu
 
Chapter 4 Microprocessor CPU
Chapter 4 Microprocessor CPUChapter 4 Microprocessor CPU
Chapter 4 Microprocessor CPU
askme
 

What's hot (20)

L15 timers-counters-in-atmega328 p
L15 timers-counters-in-atmega328 pL15 timers-counters-in-atmega328 p
L15 timers-counters-in-atmega328 p
 
Processor types
Processor typesProcessor types
Processor types
 
Avr timers
Avr timersAvr timers
Avr timers
 
Microcontoller and Embedded System
Microcontoller and Embedded SystemMicrocontoller and Embedded System
Microcontoller and Embedded System
 
Microprogram Control
Microprogram Control Microprogram Control
Microprogram Control
 
Four types of motherboards
Four types of motherboardsFour types of motherboards
Four types of motherboards
 
Introduction to Avr Microcontrollers
Introduction to Avr MicrocontrollersIntroduction to Avr Microcontrollers
Introduction to Avr Microcontrollers
 
8085 Microprocessor
8085 Microprocessor8085 Microprocessor
8085 Microprocessor
 
Introduction to embedded system
Introduction to embedded systemIntroduction to embedded system
Introduction to embedded system
 
Embedded system.ppt
Embedded system.pptEmbedded system.ppt
Embedded system.ppt
 
Ppt on embedded system
Ppt on embedded systemPpt on embedded system
Ppt on embedded system
 
Chapter 4 Microprocessor CPU
Chapter 4 Microprocessor CPUChapter 4 Microprocessor CPU
Chapter 4 Microprocessor CPU
 
ATMEGA 328
ATMEGA 328ATMEGA 328
ATMEGA 328
 
microprocessor-and-microcontroller
microprocessor-and-microcontrollermicroprocessor-and-microcontroller
microprocessor-and-microcontroller
 
embedded system and AVR
embedded system and AVRembedded system and AVR
embedded system and AVR
 
Lect 2 ARM processor architecture
Lect 2 ARM processor architectureLect 2 ARM processor architecture
Lect 2 ARM processor architecture
 
8086-microprocessor
8086-microprocessor8086-microprocessor
8086-microprocessor
 
8051 timers
8051 timers8051 timers
8051 timers
 
Control unit
Control  unitControl  unit
Control unit
 
Semiconductor memories
Semiconductor memoriesSemiconductor memories
Semiconductor memories
 

Viewers also liked

Viewers also liked (20)

L7 starting-to-use-mcu
L7 starting-to-use-mcuL7 starting-to-use-mcu
L7 starting-to-use-mcu
 
L16 usart-atmega328 p
L16 usart-atmega328 pL16 usart-atmega328 p
L16 usart-atmega328 p
 
Arduino atmega328
Arduino atmega328Arduino atmega328
Arduino atmega328
 
L1 intro-to-mpu-mcu
L1 intro-to-mpu-mcuL1 intro-to-mpu-mcu
L1 intro-to-mpu-mcu
 
L5 data-parallel-computers
L5 data-parallel-computersL5 data-parallel-computers
L5 data-parallel-computers
 
L6 primary-memory
L6 primary-memoryL6 primary-memory
L6 primary-memory
 
Introduction to-Tex-and-LaTeX
Introduction to-Tex-and-LaTeXIntroduction to-Tex-and-LaTeX
Introduction to-Tex-and-LaTeX
 
Transformers
TransformersTransformers
Transformers
 
L4 speeding-up-execution
L4 speeding-up-executionL4 speeding-up-execution
L4 speeding-up-execution
 
L3 instruction-execution-steps
L3 instruction-execution-stepsL3 instruction-execution-steps
L3 instruction-execution-steps
 
Lecture-5 : Semiconductor Power Switching Devices-2
Lecture-5 : Semiconductor Power Switching Devices-2Lecture-5 : Semiconductor Power Switching Devices-2
Lecture-5 : Semiconductor Power Switching Devices-2
 
Lecture-3 : More Applications of Power Electronics
Lecture-3 : More Applications of Power ElectronicsLecture-3 : More Applications of Power Electronics
Lecture-3 : More Applications of Power Electronics
 
Lecture-7 : Semiconductor Power Switching Devices-4
Lecture-7 : Semiconductor Power Switching Devices-4Lecture-7 : Semiconductor Power Switching Devices-4
Lecture-7 : Semiconductor Power Switching Devices-4
 
Lecture-2 : Applications of Power Electronics
Lecture-2 : Applications of Power ElectronicsLecture-2 : Applications of Power Electronics
Lecture-2 : Applications of Power Electronics
 
L14 kb-lcd-interfacing-with-atmega328 p
L14 kb-lcd-interfacing-with-atmega328 pL14 kb-lcd-interfacing-with-atmega328 p
L14 kb-lcd-interfacing-with-atmega328 p
 
Three phase-circuits
Three phase-circuitsThree phase-circuits
Three phase-circuits
 
Synchronous generators
Synchronous generatorsSynchronous generators
Synchronous generators
 
Lecture-4 : Semiconductor Power Switching Devices-1
Lecture-4 : Semiconductor Power Switching Devices-1Lecture-4 : Semiconductor Power Switching Devices-1
Lecture-4 : Semiconductor Power Switching Devices-1
 
Sowing and planting machines
Sowing and planting machinesSowing and planting machines
Sowing and planting machines
 
Lecture-1 : Introduction to Power Electronics
Lecture-1 : Introduction to Power ElectronicsLecture-1 : Introduction to Power Electronics
Lecture-1 : Introduction to Power Electronics
 

Similar to L11 assembly-language-programming-of-atmega328 p

Addressing modes (detailed data path)
Addressing modes (detailed data path)Addressing modes (detailed data path)
Addressing modes (detailed data path)
Mahesh Kumar Attri
 
Memory intrface and addrs modes
Memory intrface and addrs modesMemory intrface and addrs modes
Memory intrface and addrs modes
balbirvirdi
 

Similar to L11 assembly-language-programming-of-atmega328 p (20)

Addressing modes (detailed data path)
Addressing modes (detailed data path)Addressing modes (detailed data path)
Addressing modes (detailed data path)
 
Assembler Programming
Assembler ProgrammingAssembler Programming
Assembler Programming
 
Pdemodule 4
Pdemodule 4Pdemodule 4
Pdemodule 4
 
Assembly programming
Assembly programmingAssembly programming
Assembly programming
 
microprocessor
 microprocessor microprocessor
microprocessor
 
Microcontroller directives
Microcontroller directivesMicrocontroller directives
Microcontroller directives
 
pdfslide.net_morris-mano-ppt.ppt
pdfslide.net_morris-mano-ppt.pptpdfslide.net_morris-mano-ppt.ppt
pdfslide.net_morris-mano-ppt.ppt
 
Mpmc unit 1 notes
Mpmc unit 1 notesMpmc unit 1 notes
Mpmc unit 1 notes
 
Embedded system classes in mumbai
Embedded system classes in mumbaiEmbedded system classes in mumbai
Embedded system classes in mumbai
 
Computer architecture 3
Computer architecture 3Computer architecture 3
Computer architecture 3
 
מצגת פרויקט
מצגת פרויקטמצגת פרויקט
מצגת פרויקט
 
8086 Assembly Language and Serial Monitor Operation of 8086 Trainer Kit
8086 Assembly Language and Serial Monitor Operation of 8086 Trainer Kit8086 Assembly Language and Serial Monitor Operation of 8086 Trainer Kit
8086 Assembly Language and Serial Monitor Operation of 8086 Trainer Kit
 
c++
c++ c++
c++
 
lect 5
lect 5lect 5
lect 5
 
EE8551 MPMC
EE8551  MPMCEE8551  MPMC
EE8551 MPMC
 
Memory intrface and addrs modes
Memory intrface and addrs modesMemory intrface and addrs modes
Memory intrface and addrs modes
 
assignment 1-MC.pdf
assignment 1-MC.pdfassignment 1-MC.pdf
assignment 1-MC.pdf
 
nasm_final
nasm_finalnasm_final
nasm_final
 
Introducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptxIntroducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptx
 
Assembly Language for as level computer science
Assembly Language for as level computer scienceAssembly Language for as level computer science
Assembly Language for as level computer science
 

Recently uploaded

Hall booking system project report .pdf
Hall booking system project report  .pdfHall booking system project report  .pdf
Hall booking system project report .pdf
Kamal Acharya
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
Kamal Acharya
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 

Recently uploaded (20)

Hall booking system project report .pdf
Hall booking system project report  .pdfHall booking system project report  .pdf
Hall booking system project report .pdf
 
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf
 
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
 
2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdfDanfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES  INTRODUCTION UNIT-IENERGY STORAGE DEVICES  INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Scaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltageScaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltage
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Toll tax management system project report..pdf
Toll tax management system project report..pdfToll tax management system project report..pdf
Toll tax management system project report..pdf
 

L11 assembly-language-programming-of-atmega328 p

  • 1. Assembler Programming of Atmega328P (Lecture-11) R S Ananda Murthy Associate Professor and Head Department of Electrical & Electronics Engineering, Sri Jayachamarajendra College of Engineering, Mysore 570 006 R S Ananda Murthy Assembler Programming of Atmega328P
  • 2. Storing Data in Flash Memory Though flash memory is referred to as program memory, we can also store fixed data in it using DB and DW directives as shown above. Since each word address in flash stores two bytes in little-endian order, at any word address, the low-byte address is twice the word address and the high-byte address is low-byte address+1. Determine the word and byte addresses in the example given above. R S Ananda Murthy Assembler Programming of Atmega328P
  • 3. HIGH() and LOW() Functions AVR assembler provides these two functions. HIGH() returns the higher byte of a 16-bit value. LOW() returns the lower byte of a 16-bit value. These functions are typically used to initialize Z register to point at data bytes stored in the flash memory before using the LPM instruction. For example: LDI ZH,HIGH($100<<1);Initialize ZH. LDI ZL,LOW($100<<1) ;Initialize ZL. LPM R S Ananda Murthy Assembler Programming of Atmega328P
  • 4. Arithmetic and Logical Expressions in ALP Arithmetic Operators Logical Operators Symbol Operation Symbol Operations + Addition & Bitwise AND − Subtraction | Bitwise OR * Multiplication ^ Bitwise XOR / Division ~ Bitwise NOT % Modulo << k Shifts left by k bits >> k Shifts right by k bits We can write arithmetic and logical operations in ALP using the symbols given above. R S Ananda Murthy Assembler Programming of Atmega328P
  • 5. Examples of Arithmetic and Logical Expressions R S Ananda Murthy Assembler Programming of Atmega328P
  • 6. Device Definitions File This file contains .EQU directives which define labels assigned to various ports, port bits, registers and register bits. For Atmega328P device, this file is named as m328pdef.inc When we select a device for an assembly language project in Atmel Studio, these definitions are available to the user program through the device definitions file. If we are not using Atmel Studio, then, we have to use .INCLUDE directive to include the Device Definitions File in the .asm file to use the standard labels. R S Ananda Murthy Assembler Programming of Atmega328P
  • 7. A Glimpse of Device Definitions File for Atmega328P R S Ananda Murthy Assembler Programming of Atmega328P
  • 8. Labels for Status Flags in m328Pdef.inc File In m328Pdef.inc file, labels for status flags are defined as shown above. R S Ananda Murthy Assembler Programming of Atmega328P
  • 9. Setting Specific Flags in SREG using Flag Labels Labels for status flags can be used to set specific flags as shown above. R S Ananda Murthy Assembler Programming of Atmega328P
  • 10. Labels Related to Memories in m328Pdef.inc File We can use RAMEND to initialize Stack Pointer as shown later. R S Ananda Murthy Assembler Programming of Atmega328P
  • 11. Stack in Atmega328P Stack is a portion of R/W memory which is used for storing temporary data, for storing local variables and for storing return addresses before executing subroutines or Interrupt Service Routines. In AVR MCUs, stack is, implemented as Last-In-First-Out (LIFO), growing from higher memory to lower memory locations. PUSH Rr command will store the content of Rr in the stack and then decrements the SP by 1. POP Rd command will first increment the SP by 1 and then, byte from the stack is copied to Rd. R S Ananda Murthy Assembler Programming of Atmega328P
  • 12. Stack Pointer in Atmega328P In Atmega328P SP is a 16-bit register having two 8-bit registers SPH and SPL in the I/O space of the R/W memory in MCU as shown above. In AVR MCUs having very small memory only SPL will be present. The Stack Pointer (SP) register always points to the top of the stack. R S Ananda Murthy Assembler Programming of Atmega328P
  • 13. License This work is licensed under a Creative Commons Attribution 4.0 International License. R S Ananda Murthy Assembler Programming of Atmega328P