Accessing Atmega32 SRAM data memory

Slides:



Advertisements
Similar presentations
Instruction Set Design
Advertisements

Chapter 10- Instruction set architectures
There are two types of addressing schemes:
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
Computer Architecture CSCE 350
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
LC-3 Computer LC-3 Instructions
S. Barua – CPSC 240 CHAPTER 5 THE LC-3 Topics Memory organization Registers Instruction set Opcodes.
Target Processor Directives , When using.386, the program can only run on 386 and above processors.
Execution of an instruction
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
COMP3221: Microprocessors and Embedded Systems
CS-280 Dr. Mark L. Hornick 1 EEPROM Memory Storing, Reading, and Writing.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Spring 2013 Lecture 4: 80386DX memory, addressing.
ARM C Language & Assembler. Using C instead of Java (or Python, or your other favorite language)? C is the de facto standard for embedded systems because.
COMP3221: Microprocessors and Embedded Systems--Lecture 9 1 COMP3221: Microprocessors and Embedded Systems Lecture 9: Data Transfer Instructions
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
Atmega32 Architectural Overview
Writing an Assembly-language program Atmel assembly language CS-280 Dr. Mark L. Hornick 1.
Lab 1 – Assembly Language and Interfacing Start date: Week 3 Due date: Week 4 1.
Storing data in Program Memory
CS-280 Dr. Mark L. Hornick 1 Calling subroutines in assembly And using the Stack.
CoE3DJ4 Digital Systems Design
Computer Architecture and the Fetch-Execute Cycle
Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 7.
Execution of an instruction
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Microprocessor Microprocessor (cont..) It is a 16 bit μp has a 20 bit address bus can access upto 220 memory locations ( 1 MB). It can support.
Lecture Set 4 Programming the 8051.
Addressing Modes1 Addressing modes are concerned with how the CPU accesses the operands used by its instructions.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Instruction Sets: Addressing modes and Formats Group #4  Eloy Reyes  Rafael Arevalo  Julio Hernandez  Humood Aljassar Computer Design EEL 4709c Prof:
Functions/Methods in Assembly
Microprocessor Fundamentals Week 3 Mount Druitt College of TAFE Dept. Electrical Engineering 2008.
Microprocessors used in Personal Computers. The Memory Map of a Personal Computers Transient Program Area (TPA): Holds the operating system (interrupt.
BRANCHES SUBROUTINES AND MEMORY USAGE AVR Assembler M. Neil - Microprocessor Course 1.
1 ADDRESSING MODES Addressing Modes: * Specifies a rule for interpreting or modifying the address field of the instruction (before the operand is actually.
Dr. Iyad Jafar Introducing the PIC 16 Series and the 16F84A.
1 Contents: 3.1 Instruction format and Addressing Modes 3.2 Instruction Introduction Chapter 3 Instruction system.
“Atmega32 Architectural Overview” SIGMA INSTITUTE OF ENGINEERING Prepared By: SR.NO NAME OF STUDENT ENROLLMENT 1 Parihar Shipra A Guided By:-
“ INSTRUCTIONS SET OF AVR MICROCONTROLLER ” SIGMA INSTITUTE OF ENGINEERING Prepared By: SR.NO NAME OF STUDENT ENROLLMENT 1 Abhishek Lakhara
Assembly language programming
INTRODUCTION TO AVRASSEMBLY PROGRAMMING
Displacement (Indexed) Stack
CHAPTER ADDRESSING MODES.
ECE 3430 – Intro to Microcomputer Systems
Format of Assembly language
Addressing Modes in Microprocessors
Atmega32 Architectural Overview
Data Transfers, Addressing, and Arithmetic
COMP2121: Microprocessors and Interfacing
Microprocessor and Assembly Language
Microcomputer Programming
William Stallings Computer Organization and Architecture 8th Edition
SCHOOL OF ELECTRONICS ENGINEERING Electronics and Communication
Introduction to Micro Controllers & Embedded System Design Addressing Mode Department of Electrical & Computer Engineering Missouri University of Science.
MIPS Instruction Encoding
Addressing Modes Register Direct, with 1 and 2 registers I/O Direct
COMP2121: Microprocessors and Interfacing
MIPS Instruction Encoding
Tim Sumner, Imperial College, Rm: 1009, x47552
Computer Architecture and the Fetch-Execute Cycle
COMP3221: Microprocessors and Embedded Systems
Introduction to Micro Controllers & Embedded System Design
COMP3221: Microprocessors and Embedded Systems
Addressing Modes in 8051 MC S. Lourduraj Asst. Prof. of Physics
Computer Architecture and System Programming Laboratory
Presentation transcript:

Accessing Atmega32 SRAM data memory Addressing Modes Load and Store Instructions CS-280 Dr. Mark L. Hornick

Atmega32 Memory Address bus (16-bit in Atmega32) Data bus (8-bit) A unique 16-bit address references each memory byte. Data bus (8-bit) Volatile – RAM (fast RW) SRAM (no refresh req’d) DRAM (refresh needed, but cheaper; none on Atmega32, but typical on PC’s) Nonvolatile – ROM (fast R – slow W) EEPROM (data store) Flash ROM (program store) ROM (none on Atmega32) PROM (none on Atmega32) EPROM (none on Atmega32) CS-280 Dr. Mark L. Hornick

CS-1020 4/11/2017 Addressing Modes So far, we’ve been loading immediate values into Registers LDI R20, 123 ; load 123 into R20 The operand 123 is an Immediate value This is called Immediate Addressing Note: LDI cannot be used with R0-R15 In general, an operand of an instruction may be specified by An Immediate value Direct addressing Indexed addressing Address modes specify how and where the values specified by the operand(s) are located LDI rD, N is assembled to: Note: Only 4 bits are used for dddd 1110 nnnn dddd nnnn CS-280 Dr. Mark L. Hornick Dr. Mark L. Hornick

Direct Addressing accesses a 8-bit (byte) value from SRAM data memory at the address specified directly within the instruction Example: LDS R20, 0x60 ; LoaD value at SRAM addr 0x0060 to R20 STS 0x60, R20 ; STore value in R20 to SRAM addr 0x0060 Note data address values are 16-bit since data memory addresses can range from 0x0 - 0xFFFF (0 - 65535) Even though Atmega32 only has 2KB SRAM It may help to keep in mind that 0x60 is the same as 0x0060 Each byte (8 bits) of data memory has a unique address As opposed to each word (2 bytes) of program flash memory having a unique address CS-280 Dr. Mark L. Hornick

Memory Map: Data memory Actual SRAM data memory starts at address 0x0060! And ends at 0x085F .EQU SRAM_START=0x60 is found in m32def.inc GP Registers are assigned the first 32 data memory addresses LDS R20, 0x0 loads the value of R0 into R20 (same as MOV R20, R0) IO Registers are assigned the next 64 addresses Add 0x20 to convert an IO memory address to it’s corresponding data memory address STS PORTB+0x20, R20 same as OUT PORTB, R20 2048 (0x800) bytes of SRAM in the Atmega32 CS-280 Dr. Mark L. Hornick

Referring to raw memory addresses is not ideal We can explicitly define constant symbols to refer to addresses using the .EQU directive Example: .EQU x1=0x0060 ; define a symbol “x1” LDS R20, x1 ; data load addr is referred to by x1 STS x1, R20 ; data store addr is x1 CS-280 Dr. Mark L. Hornick

An even better way to specify addresses is to use labels We defined labels to identify addresses in program memory to be used as jump/branch targets loop: RJMP loop The address assigned to a label is determined automatically by the Assembler Similarly, we can define labels to identify addresses in data memory to be used as load/store targets CS-280 Dr. Mark L. Hornick

Using labels to refer to data memory locations: .DSEG ; subsequent directives refer to data segment .ORG SRAM_START ; address where Data Memory starts (0x60) x1: .byte 1 ; reserve 1 byte of SRAM, assign label x1=0x60 x2: .byte 2 ; reserve 2 bytes of SRAM, assign label x2=0x61 x3: .byte 1 ; reserve 1 byte of SRAM, assign label x3=0x63 .CSEG ; switch further directives to code segment .ORG 0x2A ; set addr for start of program instructions LDS R20, x1 ; load value at data addr specified by x1 STS x2, R20 ; store value in R20 to data addr x2 The addresses are assigned automatically by the Assembler The .byte n directive tells the assembler to allocation n bytes Be very careful about using .ORG for addresses < 0x60 CS-280 Dr. Mark L. Hornick

The X, Y, and Z Registers The X, Y, and Z 16-bit registers overlap the last six 8-bit registers R26 through R31 CS-280 Dr. Mark L. Hornick

Indirect Addressing Accesses a 8-bit (byte) value from SRAM data memory at the address specified indirectly via the 16-bit X, Y, or Z index-registers Example: LD R20, X ; load value at data addr held in X to R20 ST Y, R20 ; store value in R20 to data addr held in Y Note X, Y, Z hold data address values that are 16-bits CS-280 Dr. Mark L. Hornick

How do you load an address value into X, Y, or Z? We can’t use a single instruction like LDI Because LDI loads values into 8-bit registers But we could potentially use two LDI instructions… Consider X: overlaps R26 and R27 The first 8 bits of X are R26; the second 8 bits are R27 To set X to hold the 16-bit address: .DSEG ; subsequent directives refer to data segment .ORG 0x60 ; set SRAM address where label assignments start x1: .byte 1 ; reserve 1 byte of SRAM, assign label x1=0x0060 .CSEG ; switch further directives to code segment .ORG 0x2A ; set addr for start of program instructions LDI R26, LOW(x1) ; load R26 with the low 8 bits of the address (0x0060) LDI R27, HIGH(x1) ; load R27 with the high 8 bits of the address (0x0060) LD R20, X ; load value at data addr contained in register X LOW() and HIGH() are Assembler functions or macros i.e. functions that are executed by the Assembler during assembly They are NOT functions that execute on the Atmega32 CS-280 Dr. Mark L. Hornick

How do you remember that the low 8-bits of X is R26 and the high 8-bits are R27? You don’t have to; m32def.inc helps with some definitions: .DEF XL=R26 .DEF XH=R27 .DSEG ; subsequent directives refer to data segment .ORG 0x60 ; set SRAM address where label assignments start x1: .byte 1 ; reserve 1 byte of SRAM, assign label x1=0x0060 .CSEG ; switch further directives to code segment .ORG 0x2A ; set addr for start of program instructions LDI XL, LOW(x1) ; load R26 with the low 8 bits of the addr assigned to x1 LDI XH, HIGH(x1) ; load R27 with the high 8 bits of x1 LD R20, X ; load value at data addr contained in register X CS-280 Dr. Mark L. Hornick

Addresses contained within the X, Y, and Z registers can be automatically indexed via pre- and post-decrement syntax Syntax is somewhat similar to the C++/Java increment/decrement syntax: Ex: int a=3; b=4; a = b++; // assigns b to a and then increments b; result is a=7 a = b--; // assigns b to a and then decrements b; result is a=7 a = ++b; // increments b BEFORE assigning b to a; result is a=8 a = --b; // decrements b before assigning b to a; result is a=6 .DSEG ; subsequent directives refer to data segment .ORG 0x60 ; set SRAM address where label assignments start x1: .byte 1 ; reserve 1 byte of SRAM, assign label x1=0x0060 .CSEG ; switch further directives to code segment .ORG 0x2A ; set addr for start of program instructions LDI XL, LOW(x1) ; load R26 with the low 8 bits of the addr assigned to x1 LDI XH, HIGH(x1) ; load R27 with the high 8 bits of x1 LD R20, X+ ; load value from addr in register X; then increment X (to 0x0061) LD R21, +X ; incr X (to 0x0062), then load value from addr in register X LD R22, X- ; load value from addr in register X; then decrement X (to 0x0061) LD R21, -X ; decr X (to 0x0060), then load value from addr in register X CS-280 Dr. Mark L. Hornick

An offset from the address contained in an index register can be specified with the LDD instruction .EQU offset=10 .DSEG ; subsequent directives refer to data segment .ORG 0x60 ; set SRAM address where label assignments start x1: .byte 1 ; reserve 1 byte of SRAM, assign label x1=0x0060 .CSEG ; switch further directives to code segment .ORG 0x2A ; set addr for start of program instructions LDI XL, LOW(x1) ; load R26 with the low 8 bits of the addr assigned to x1 LDI XH, HIGH(x1) ; load R27 with the high 8 bits of x1 LDD R20, X+2 ; load value from offset addr (X+2 = 0x62); does NOT increment X LDD R20, X+offset ; load value from offset addr (X+10=0x6A); does NOT increment X The maximum value that an index register may be offset in this way is 64 CS-280 Dr. Mark L. Hornick

Note that instructions such as INC and ADD cannot use X, Y, or Z as operands INC X ; illegal ADD X, Y ; illegal LDI Z, 0x1234 ; illegal However, the following is a valid Atmega32 instruction: ADIW r31:r30, 0x1 ; add immediate value (to Z) The value may be 0-63 (decimal) CS-280 Dr. Mark L. Hornick

FYI: There are a number of Assembler functions besides LOW() and HIGH() LOW(0xabcd) returns the low byte (0xcd) of an expression HIGH(0xabcd) returns the second (0xab) byte of an expression BYTE1(0xabcd) is the same function as LOW BYTE2(0xabcd) is the same function as HIGH BYTE3(0x1234abcd) returns the third byte (0x34) of an expression BYTE4(0x1234abcd) returns the fourth byte (0x12) of an expression LWRD(0x1234abcd) returns bits 0-15 of an expression (0xabcd) HWRD(0x1234abcd) returns bits 16-31 of an expression (0x1234) CS-280 Dr. Mark L. Hornick

The Z Register can also be used to hold a jump target address Syntax: IJMP ; jump indirectly to the address contained in Z The Z register is implied and not a required operand Z can hold any address in the 0-65535 Similar in capacity to JMP CS-280 Dr. Mark L. Hornick