EE 308: Microcontrollers

Similar documents
EE 308: Microcontrollers

EE 308: Microcontrollers

EE 308: Microcontrollers

EE 308: Microcontrollers

EE 308: Microcontrollers

EE 308: Microcontrollers

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

AVR ISA & AVR Programming (I)

Module 8: Atmega32 Stack & Subroutine. Stack Pointer Subroutine Call function

COMP2121: Microprocessors and Interfacing

Microcontroller VU

Review on Lecture-1. ICT 6641: Advanced Embedded System. Lecture 2 Branch, Call and Delay Loops, AVR I/O port programming

CN310 Microprocessor Systems Design

EE 308: Microcontrollers

AVR Subroutine Basics

By: Dr. Hamed Saghaei

Chapter 4: Atmel s AVR 8-bit Microcontroller Part 1 Assembly Programming

COMP2121: Microprocessors and Interfacing. I/O Devices (II)

Addressing Modes Part II AVR Addressing Indirect READING

Programming Microcontroller Assembly and C

COMP2121: Microprocessors and Interfacing. Instruction Formats and Addressing Modes

APPENDIX D FLOWCHARTS AND PSEUDOCODE OVERVIEW

Module 2: Introduction to AVR ATmega 32 Architecture

Using SRAM in AVR assembler language

Microprocessors & Interfacing

Interrupts (II) Lecturer: Sri Parameswaran Notes by: Annie Guo

Data Transfer Instructions

Lecture 20: AVR Programming, Continued. AVR Program Visible State (ones we care about for now)

Objectives. I/O Ports in AVR. Topics. ATmega16/mega32 pinout. AVR pin out The structure of I/O pins I/O programming Bit manipulating 22/09/2017

APPENDIX A FOR SKEE3732 LABORATORY 1 SHEET

Programming. A. Assembly Language Programming. A.1 Machine Code. Machine Code Example: Motorola ADD

AVR Assembler Examples

8-bit Instruction Set

ECE 375 Computer Organization and Assembly Language Programming Winter 2018 Solution Set #2

Assembly Programming (III)

Assembly Programming (III) Lecturer: Sri Parameswaran Notes by: Annie Guo Dr. Hui Wu

8-bit Instruction Set

Logic Instructions and Programs READING

EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1. Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University

Digital Systems - Mini AVR 3

Today s Menu. >Use the Internal Register(s) >Use the Program Memory Space >Use the Stack >Use global memory

IAS0430 MICROPROCESSOR SYSTEMS

CHAPTER 2: AVR ARCHITECTURE & ASSEMBLY LANGUAGE PROGRAMMING

AVR. (AVR Assembly Language) Assembler . ก ก

AVR Instruction Set Encoding

COMP2121: Microprocessors and Interfacing

AVR. 2. (Assembler directives ) 3. ( Instruction field) 5. (Comment field) 1. (Label field) Assembler. 4. ก (Operands field) (AVR Assembly Language)

Microprocessors & Interfacing

COMP3221: Microprocessors and Embedded Systems

Mark II Aiken Relay Calculator

COMP2121: Microprocessors and Interfacing

COMP3221: Microprocessors and Embedded Systems

Input/Output Devices. Lecturer: Sri Parameswaran Notes by: Annie Guo

AT90S Bit Microcontroller with 1K bytes Downloadable Flash AT90S1200. Features. Description. Pin Configuration

Register-Level Programming

COMP2121: Microprocessors and Interfacing. Instruction Set Architecture (ISA)

Embedded Systems and Software

AVR Control Transfer -AVR Branching

Introduction to Assembly language

ET-BASE AVR ATmega64/128

Embedded Systems and Software. LCD Displays

Building A RISC Microcontroller in an FPGA. Yap Zi He

CHW 469 : Embedded Systems

COMP3221: Microprocessors and. and Embedded Systems. Overview. Variable Types and Memory Sections. Types of Variables in C

AVR and MeggyJr Simple

APPENDIX B AVR INSTRUCTIONS EXPLAINED OVERVIEW

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

University of Florida EEL 4744 Dr. Eric M. Schwartz. Page 1/11 Revision 0 20-Feb-14 Mixed C and Assembly (for Atmel XMEGA)

PIC Discussion. By Eng. Tamar Jomaa

8-bit Microcontroller with 2/4/8K Bytes In-System Programmable Flash. ATtiny261/V ATtiny461/V ATtiny861/V. Preliminary

AN703. Micro64/128. Accessing the 36k of SRAM 12/3/04

Lecture 4: MIPS Instruction Set

CPU. Objectives. Introduction to Assembly Chapter 2. Topics. AVR s CPU 12/09/2017

CodeWarrior. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

8-bit Microcontroller with 4K Bytes In-System Programmable Flash. ATtiny40. Preliminary

Laboratory: Introduction to Mechatronics. Instructor TA: Edgar Martinez Soberanes Lab 2. PIC and Programming

COMP2121 Experiment 4

8-bit Microcontroller with 8K Bytes Programmable Flash AT90C8534. Preliminary

Grundlagen Microcontroller Processor Core. Günther Gridling Bettina Weiss

EXPERIMENT NO. 1 THE MKT 8085 MICROPROCESSOR TRAINER

Embedded Systems and Software

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Mitsubishi M16C Instruction Set Architecture

ECED 3204 Microprocessor Midterm Reference Solution

Menu. The Cost of Debugging

Lecture 04: Machine Instructions

COMP2121: Microprocessors and Interfacing. I/O Devices (I)

Computer Organization MIPS ISA

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Review Topics

2.1. Basic Assembler Functions:

8-bit Microcontroller with 2/4/8K Bytes In-System Programmable Flash. ATtiny261 ATtiny461 ATtiny861. Automotive

Buses and Parallel Input/Output

8-bit Microcontroller with 8K Bytes In-System Programmable Flash. ATmega8515 ATmega8515L. Features

8051 Microcontroller Assembly Programming

Speed and Size-Optimized Implementations of the PRESENT Cipher for Tiny AVR Devices

Practical Malware Analysis

CSIS1120A. 10. Instruction Set & Addressing Mode. CSIS1120A 10. Instruction Set & Addressing Mode 1

EE 3170 Microcontroller Applications

;Compiler Options.NOLIST.INCLUDE "C:\Program Files (x86)\atmel\avr Tools\AvrAssembler2\Appnotes\m8515def.inc"

Transcription:

EE 308: Microcontrollers Introduction to the Assmbly Language Aly El-Osery Electrical Engineering Department New Mexico Institute of Mining and Technology Socorro, New Mexico, USA January 25, 2018 Aly El-Osery (NMT) EE 308: Microcontrollers January 25, 2018 1 / 14

Introduction to Assembly This lecture will introduce you to the assembly language, the compilation and downloading process. Aly El-Osery (NMT) EE 308: Microcontrollers January 25, 2018 2 / 14

Fields of an assembly language instruction [label:] mnemonic [operands] [;comment] label... marks lines that can be referred to by the program mnemonic... instruction and results in an opcode operands... could be registers, address to a desired memory, or constant depending on the instruction comments... comments start with a semicolon Aly El-Osery (NMT) EE 308: Microcontrollers January 25, 2018 3 / 14

LDI instruction LDI Rd, K ;load Rd with immediate value k K is an 8-bit value Rd can only be R16 to R31 Hex values for K can be represented using 0 Machine code for LDI 1110 kkkk dddd kkkk Examples: LDI R20,0 x3f ;load R20 with immediate hex value 0x3F E 3 4 F Aly El-Osery (NMT) EE 308: Microcontrollers January 25, 2018 4 / 14

ADD instruction ADD Rd, Rr ;Add Rr to Rd and store result to Rd Uses the ALU Result affects the status register Examples: ADD R16, R17 ;Add R17 to R16 and store in R16 Aly El-Osery (NMT) EE 308: Microcontrollers January 25, 2018 5 / 14

LDS instruction LDS Rd, K ;load Rd with the content of memory location K Loads the register directly from data space (one byte value) Examples: LDS R5,0 x400 ;load R5 with content of memory location 0x400 LDS R6,0 x1 ;load R6 with content of memory location 0x1 What is in memory locate 0x1? Aly El-Osery (NMT) EE 308: Microcontrollers January 25, 2018 6 / 14

STS instruction STS K, Rr ;store register into location K Store direct to data space Location could be any value in the data space Examples: STS 0 x400, R25 ;store R25 to data space location 0x230 STS 0 x27, R16 ;store R16 to memory locate 0x27 What is in memory locate 0x27? Aly El-Osery (NMT) EE 308: Microcontrollers January 25, 2018 7 / 14

IN instruction IN Rd, A ;load an I/O location Rd A is an I/O location 0 to 0x3F I/O locations are offset from memory addresses by 0x20 therefore they start at 0x00 Examples: IN R19,0 x10 ;load R19 with data from location 0x10 What is in memory locate 0x10? Aly El-Osery (NMT) EE 308: Microcontrollers January 25, 2018 8 / 14

Difference between IN and LDS IN is faster IN is a 2-byte instruction vs the 4-byte instruction LDS Can use I/O register names with IN IN as opposed to LDS it is available in all AVRs Aly El-Osery (NMT) EE 308: Microcontrollers January 25, 2018 9 / 14

OUT instruction OUT A, Rr ;store register Rr to I/O location A Cannot copy and immediate value to an I/O register nor to an SRAM location Examples: OUT PORTA, R0 ;load R19 with data from location 0x10 What is PORTA? Aly El-Osery (NMT) EE 308: Microcontrollers January 25, 2018 10 / 14

Assembly language Assembly language consists of, instructions referred to as mnemonics, directives and labels.. INCLUDE " M1284DEF. INC " LDI R16, hi8 ( RAMEND ) OUT SPH, R16 LDI R16, lo8 ( RAMEND ) 5 OUT SPL, R16 ;initialize stack pointer SBI DDRC, 0 ;set bit 0 of DDRC HERE : SBI PORTC, 0 10 CALL DELAY ;call DELAY subroutine CBI PORTC, 0 CALL DELAY RJMP HERE 15 DELAY : LDI R20, 255 DL1 : DEC R20 BRNE DL1 RET Aly El-Osery (NMT) EE 308: Microcontrollers January 25, 2018 11 / 14

Assembly language Assembly language consists of, instructions referred to as mnemonics, directives and labels.. INCLUDE " M1284DEF. INC " LDI R16, hi8 ( RAMEND ) OUT SPH, R16 LDI R16, lo8 ( RAMEND ) 5 OUT SPL, R16 ;initialize stack pointer SBI DDRC, 0 ;set bit 0 of DDRC HERE : SBI PORTC, 0 10 CALL DELAY ;call DELAY subroutine CBI PORTC, 0 CALL DELAY RJMP HERE 15 DELAY : LDI R20, 255 DL1 : DEC R20 BRNE DL1 RET Directive Label Comment Instruction Aly El-Osery (NMT) EE 308: Microcontrollers January 25, 2018 11 / 14

Intel Hex Intel Hex :1000000000E40EBF0FEF0DBF389A409A0E940C001B :1000100040980E940C00F9CF4FEF4A95F1F70895F0 :00000001FF Start code (:) Byte count data only (2 characters) Address (4 characters) Record type (2 characters) 00 data record 01 end of file Data (2k characters) Checksum (2 characters) Aly El-Osery (NMT) EE 308: Microcontrollers January 25, 2018 12 / 14

Intel Hex Intel Hex :1000000000E40EBF0FEF0DBF389A409A0E940C001B :1000100040980E940C00F9CF4FEF4A95F1F70895F0 :00000001FF Start code (:) Byte count data only (2 characters) Address (4 characters) Record type (2 characters) 00 data record 01 end of file Data (2k characters) Checksum (2 characters) What is this code represent? Aly El-Osery (NMT) EE 308: Microcontrollers January 25, 2018 12 / 14

What to download on the microcontroller Assembler replaces mnemonics by their opcodes, resolves include directives, translates register names to addresses, removes comments, etc. avr-as -mmcu=atmega1284 -o ex.o ex.s Linker links multiple files avr-ld -mavr51 -o ex.elf ex.o Translate object files avr-objcopy -j.text -j.data -O ihex -o ex.hex ex.elf Aly El-Osery (NMT) EE 308: Microcontrollers January 25, 2018 13 / 14

Downloading the hex file avrdude -v -c dragon_jtag -p m1284 -Pusb -U flash:w:ex.hex Aly El-Osery (NMT) EE 308: Microcontrollers January 25, 2018 14 / 14