Atmel AVR Assembler

download Atmel AVR Assembler

of 77

  • date post

    14-Oct-2015
  • Category

    Documents

  • view

    32
  • download

    2

Embed Size (px)

Transcript of Atmel AVR Assembler

  • BeginnersIntroductiontotheAssemblyLanguageof

    ATMELAVRMicroprocessors

    by

    GerhardSchmidt

    http://www.avrasmtutorial.net

    April2009

    History:

    Added chapter on code structures in April 2009

    Additional corrections and updates as of January 2008

    Corrected version as of July 2006

    Original version of December 2003

  • Avr-Asm-Tutorial 1 http://www.avr-asm-tutorial.net

    ContentWhylearningAssembler?..........................................................................................................................1

    Shortandeasy.......................................................................................................................................1Fastandquick........................................................................................................................................1Assembleriseasytolearn.....................................................................................................................1AVRsareidealforlearningassembler..................................................................................................1Testit!....................................................................................................................................................2

    HardwareforAVRAssemblerProgramming...........................................................................................3TheISPInterfaceoftheAVRprocessorfamily...................................................................................3ProgrammerforthePCParallelPort....................................................................................................3Experimentalboards..............................................................................................................................4

    ExperimentalboardwithanATtiny13.............................................................................................4ExperimentalboardwithanAT90S2313/ATmega2313..................................................................5

    ReadytousecommercialprogrammingboardsfortheAVRfamily...................................................7STK200.............................................................................................................................................7STK500.............................................................................................................................................7AVRDragon.....................................................................................................................................8

    ToolsforAVRassemblyprograming........................................................................................................9Fromatextfiletoinstructionwordsintheflashmemory....................................................................9

    Theeditor..........................................................................................................................................9Structuringassemblercode.............................................................................................................10Comments.......................................................................................................................................10Thingstobewrittenontop.............................................................................................................10Thingsthatshouldbedoneatprogramstart...................................................................................11Structuringofprogramcode...........................................................................................................11Theassembler.................................................................................................................................14

    Programmingthechips........................................................................................................................15Simulationinthestudio.......................................................................................................................15Whatisaregister?...............................................................................................................................20Differentregisters................................................................................................................................21Pointerregisters...................................................................................................................................21

    Accessingmemorylocationswithpointers....................................................................................21ReadingprogramflashmemorywiththeZpointer........................................................................22Tablesintheprogramflashmemory..............................................................................................22Accessingregisterswithpointers...................................................................................................22

    Recommendationfortheuseofregisters............................................................................................23Ports.........................................................................................................................................................24

    WhatisaPort?....................................................................................................................................24Writeaccesstoports.......................................................................................................................24Readaccesstoports........................................................................................................................25ReadModifyWriteaccesstoports................................................................................................25Memorymappedportaccess..........................................................................................................25DetailsofrelevantportsintheAVR..............................................................................................26

    Thestatusregisterasthemostusedport.............................................................................................26Portdetails...........................................................................................................................................27

    SRAM......................................................................................................................................................28UsingSRAMinAVRassemblerlanguage.........................................................................................28WhatisSRAM?...................................................................................................................................28ForwhatpurposescanIuseSRAM?..................................................................................................28HowtouseSRAM?.............................................................................................................................28

    Directaddressing............................................................................................................................28Pointeraddressing...........................................................................................................................29Pointerwithoffset...........................................................................................................................29

    UseofSRAMasstack.........................................................................................................................29DefiningSRAMasstack................................................................................................................30Useofthestack...............................................................................................................................30Bugswiththestackoperation.........................................................................................................31

    JumpingandBranching............................................................................................................................32

  • Avr-Asm-Tutorial 2 http://www.avr-asm-tutorial.net

    Controllingsequentialexecutionoftheprogram................................................................................32Whathappensduringareset?.........................................................................................................32

    Linearprogramexecutionandbranches..............................................................................................33Branching........................................................................................................................................33

    Timingduringprogramexecution.......................................................................................................34Macrosandprogramexecution...........................................................................................................34Subroutines..........................................................................................................................................35Interruptsandprogramexecution........................................................................................................36

    Calculations..............................................................................................................................................39Numbersystemsinassembler.............................................................................................................39

    Positivewholenumbers(bytes,words,etc.)..................................................................................39Signednumbers(integers)...........................................