Storing data in Program Memory

Slides:



Advertisements
Similar presentations
Instruction Set Design
Advertisements

Instruction Set-Intro
Accessing Atmega32 SRAM data memory
Computer Organization and Architecture
Computer Organization and Architecture
+ CS 325: CS Hardware and Software Organization and Architecture Internal Memory.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
1 Computer Architecture MIPS Simulator and Assembly language.
1BA3 G Lacey Lecture 51 Evaluating mathematical expressions  How do computers evaluate x + y or any mathematical expression ?  Answer : “Reverse Polish.
What is memory? Memory is used to store information within a computer, either programs or data. Programs and data cannot be used directly from a disk or.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 4: Operating Systems.
Execution of an instruction
©Brooks/Cole, 2003 Chapter 5 Computer Organization.
Chapter 0 Introduction to Computing
Registers  Flip-flops are available in a variety of configurations. A simple one with two independent D flip-flops with clear and preset signals is illustrated.
Computer Organization Prepared by:Anh Q. Vu Course:CS-147 Professor:Sin-Min Lee Date:Summer
Computer Organization and Architecture
Chapter 5 Internal Memory
Memory Devices Wen-Hung Liao, Ph.D..
IT Systems Memory EN230-1 Justin Champion C208 –
CS-280 Dr. Mark L. Hornick 1 EEPROM Memory Storing, Reading, and Writing.
Memory and Storage - Sheetal Gosrani. Overview Memory Hierarchy RAM Memory Chip Organization ROM Flash Memory.
Memory. When we receive some instruction or information we retain them in our memory. Similarly a computer stores the instructions for solving a problem,
1 The 8051 Microcontroller and Embedded Systems CHAPTER INTERFACING TO EXTERNAL MEMORY.
Atmega32 Architectural Overview
Computer Organization - Syscalls David Monismith Jan. 28, 2015 Based on notes from Patterson and Hennessy Text and from Dr. Bill Siever.
Higher Computing Computer Systems S. McCrossan 1 Higher Grade Computing Studies 2. Computer Structure Computer Structure The traditional diagram of a computer...
 Memory Memory  Types of Memory Types of Memory  Memory Representation Memory Representation  Random Access Memory Random Access Memory  Read Only.
CS-280 Dr. Mark L. Hornick 1 Calling subroutines in assembly And using the Stack.
A Simple Tour of the MSP430. Light LEDs in C LEDs can be connected in two standard ways. Active high circuit, the LED illuminates if the pin is driven.
Physics 413 Chapter 1: Introduction to the HCS 12 Microcontroller.
Microcode Source: Digital Computer Electronics (Malvino and Brown)
Chapter 8 Memory Interface
CS-1030 Dr. Mark L. Hornick 1 Pointers are fun!
Memory Interface A Course in Microprocessor Electrical Engineering Dept. University of Indonesia.
LBSC 690 Session 4 Data Transformation and Representation.
MEMORY INTERFACE (ROMS, RAMS). Computer Memory Overview.
GCSE ICT Storing data - Internal memory, backing storage, and measuring memory.
Primary Storage Primary storage is the storage that is directly available to the CPU. It is also known as: Main Memory Main Memory Direct Access Storage.
Computer Architecture Lecture 24 Fasih ur Rehman.
Electronic Analog Computer Dr. Amin Danial Asham by.
CE-2810 Dr. Mark L. Hornick 1 Mixing C and assembly Safety goggles on!
Memory Devices 1. Memory concepts 2. RAMs 3. ROMs 4. Memory expansion & address decoding applications 5. Magnetic and Optical Storage.
Arrays in MIPS Assembly Computer Organization and Assembly Language: Module 6.
Arrays. Outline 1.(Introduction) Arrays An array is a contiguous block of list of data in memory. Each element of the list must be the same type and use.
STATUS REGISTER  It is a group of flip-flops. But it is not used to store data.  Each bit in the status register is used to indicate a particular condition.
The LC-3 – Chapter 5 COMP 2620 Dr. James Money COMP
Components of Hardware 1. Processor Memory Input and output devices Storage 2.
Dr. Iyad Jafar Introducing the PIC 16 Series and the 16F84A.
“Atmega32 Architectural Overview” SIGMA INSTITUTE OF ENGINEERING Prepared By: SR.NO NAME OF STUDENT ENROLLMENT 1 Parihar Shipra A Guided By:-
Components of Computer. Memory Unit Most important part of the computer Used to store data and instructions that are currently in use Main memory consists.
INTRODUCTION TO AVRASSEMBLY PROGRAMMING
MEMORY BYTES. MEMORY BYTES MEMORY MEMORY OUR Internal External.
Atmega32 Architectural Overview
Internal Memory.
Memory Units Memories store data in units from one to eight bits. The most common unit is the byte, which by definition is 8 bits. Computer memories are.
Memory chips Memory chips have two main properties that determine their application, storage capacity (size) and access time(speed). A memory chip contains.
L7 – Assembler Directives
Subject Name: Embedded system Design Subject Code: 10EC74
Chapter 7 LC-2 Assembly Language.
William Stallings Computer Organization and Architecture 7th Edition
Introduction to Computing Chapter 0
Tim Sumner, Imperial College, Rm: 1009, x47552
Chapter 7 Assembly Language
LC-2: The Little Computer 2
Some Assembly
Computer Memory.
Presentation transcript:

Storing data in Program Memory Special-purpose 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) Nonvolatile – ROM (fast R – slow W) ROM PROM EPROM EEPROM (permanent data store) Flash ROM (program store) Volatile – RAM (fast RW) SRAM (temp data store) DRAM CS-280 Dr. Mark L. Hornick

SRAM is volatile memory Power must be supplied to maintain values stored in SRAM SRAM values disappear when power is shut off SRAM is cleared when power is first applied CS-280 Dr. Mark L. Hornick

Review: Program vs. Data Memory Addressing 0x0000 0x0001 0x0002 0x0003 0x0004 Byte 0 Byte 1 Program Memory is organized and accessed in words A word is 2 bytes Each word has a unique address Data Memory is organized and accessed in bytes Each byte has a unique address Byte 2 Byte 3 Byte 4 Byte 5 Byte 6 Byte 7 Byte 8 Byte 9 0x0060 0x0061 0x0062 0x0063 0x0064 Byte 0 Byte 1 Byte 2 Byte 3 Byte 4 CS-280 Dr. Mark L. Hornick

Review: Allocating SRAM Data memory .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

Review: 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

Review: 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

Data values can be stored permanently by allocating them to non-volatile Program Memory .DSEG ; subsequent directives refer to data segment .ORG SRAM_START ; address where Data Memory starts (0x60) x1: .byte 5 ; reserve 5 bytes of (uninitialized) volatile SRAM .CSEG ; switch further directives to code segment .ORG 0x2A ; set addr for start of program instructions y1: .db 1,5 ; alloc 2 bytes in Prog Memory with initial values of 1 and 5 title: .db ‘c’,’s’,’2’,’8’,’0’,0 ; allocate 6 bytes in Program Memory course: .db “CS-280”, 0 ; allocate 7 bytes in Program Memory Note assembler does NOT automatically insert a NULL char at the end of the string The .byte n directive tells the assembler to allocate n bytes in Data Memory No initial value can be specified to SRAM data memory values The .db n,m,… (“define byte”) directive tells the assembler to allocate and store the bytes n,m… in Program Memory The initial values of the memory are specified The assembler always starts data on a word boundary in memory CS-280 Dr. Mark L. Hornick

Review: ASCII Encoding CS-1020 4/21/2017 Review: ASCII Encoding For example, character 'O' is 79 (row value 70 + col value 9 = 79). O 9 70 Characters can be stored in a computer memory using the ASCII encoding. The ASCII codes range from 0 to 127. The character 'A' is represented as 65, for example. The ASCII values from 0 to 32 are called nonprintable control characters. For example, ASCII code 04 eot stands for End of Transmission. We can use this character to signal the end of transmission of data when sending data over a communication line. CS-280 Dr. Mark L. Hornick Dr. Mark L. Hornick

Accessing (reading) data from Program Memory There are three instructions to load (read) data from Program Memory to a register LPM loads from byte address in Z register to R0, where Z and R0 are implied arguments LPM Rn, Z loads from byte address in Z to Rn (R0-R31); note that X and Y are not allowed LPM Rn, Z+ Same as above, but increments Z after loading CS-280 Dr. Mark L. Hornick

Big Red Flag When using LPM, the Z register must contain the data’s byte address Recall: Program Memory is organized by words – each word has an address Byte address is 2*word address CS-280 Dr. Mark L. Hornick

How do you load a byte address value into Z? .CSEG ; switch further directives to code segment .ORG 0x2A ; set addr for start of program instructions LDI ZL, LOW(2*values) ; load ZL with the low 8 bits of the address LDI ZH, HIGH(2*values) ; load ZH with the high 8 bits of the address LPM R20, Z ; load Program Memory byte addr contained in Z values: .db 5, 10, 11, 12, 13 ; define 5 bytes of Program Memory Use LOW() and HIGH() are Assembler functions “values” label contains the word address of the location of the first reserved byte The assembler expression “2*values” correctly computes the associated byte address CS-280 Dr. Mark L. Hornick

There are certain conventions for defining Program Memory The .db directives are placed after program instructions, so that the data itself is placed in memory after the instruction opcodes When defining numeric data values, the first value specifies the number of values to follow: y1: .db 1,5 ; alloc 2 bytes in Prog Memory with initial values of 1 and 5 When defining character or string data values, the last value speicified should always be zero, indicating that the character data is terminated with a null-character: title: .db ‘c’,’s’,’2’,’8’,’0’,0 ; allocate 6 bytes in Program Memory course: .db “CS-280”, 0 ; allocate 7 bytes in Program Memory CS-280 Dr. Mark L. Hornick

Note: The Z register can also be incremented explicitly ADIW ZH:ZL, 5 ; add immediate value (to Z) The value may be 0-63 (decimal) So you can use ADIW in conjuction with LPM and LPM Rn, Z instructions to post-increment the Z register to point to the address of the next character in program memory CS-280 Dr. Mark L. Hornick

There is also an SPM instruction…. But due to the nature of Flash memory, writing to it is more complex Before writing, an entire page of memory must be erased Page size is device-specific On some devices, only entire pages can be written In CE2800, use the .DB directive to write to Flash memory Only writes once, when the program is downloaded to the device CS-280 Dr. Mark L. Hornick