Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 7 Indexed Addressing Mode Read Mazidi, Chapter 6. Homework #7 and Lab #7 due next week. Quiz next week.

Slides:



Advertisements
Similar presentations
Ch. 7 Local Variables and Parameter Passing From the text by Valvano: Introduction to Embedded Systems: Interfacing to the Freescale 9S12.
Advertisements

H. Huang Transparency No.1-1 The HCS12/MC9S12 Microcontroller Copyright © 2010 Delmar Cengage Learning HCS12 Instruction Examples The LOAD and STORE Instructions.
EET 2261 Unit 6 The Stack; Subroutines
EET 2261 Unit 3 Assembly Language; Load, Store, & Move Instructions  Read Almy, Chapters 5 and 6.  Homework #3 and Lab #3 due next week.  Quiz next.
CPU Review and Programming Models CT101 – Computing Systems.
The 8051 Microcontroller and Embedded Systems
There are two types of addressing schemes:
SUPPLEMENTARY CHAPTER 2 Instruction Addressing Modes
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
 Suppose for a moment that you were asked to perform a task and were given the following list of instructions to perform:
EET 2261 Unit 8 Seven-Segment Displays; S19 Records; System Clocks
EET 2261 Unit 5 Tables; Decision Trees & Logic Instructions
Lab6 – Debug Assembly Language Lab
H. Huang Transparency No.1-1 The 68HC11 Microcontroller Chapter 1: Introduction to 68HC11 The 68HC11 Microcontroller.
TK 2633 Microprocessor & Interfacing
Execution of an instruction
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
8051 ASSEMBLY LANGUAGE PROGRAMMING
EET 2261 Unit 2 HCS12 Architecture
Part II: Addressing Modes
ECE 265 – LECTURE 4 The M68HC11 Address Modes 8/14/ ECE265.
© 2010 Kettering University, All rights reserved..
Assembly & Machine Languages
Lecture 18 Last Lecture Today’s Topic Instruction formats
Lab 1 – Assembly Language and Interfacing Start date: Week 3 Due date: Week 4 1.
Module 10 Adapted By and Prepared James Tan © 2001.
Physics 413 Chapter 1: Introduction to the HCS 12 Microcontroller.
ME4447/6405 The George W. Woodruff School of Mechanical Engineering ME4447/6405 Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics.
Computer Architecture and the Fetch-Execute Cycle
Objectives Implement pointers using indexed addressing modes Use pointers to access arrays, strings, structures, tables, and matrices Present finite-state.
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
Dr. José M. Reyes Álamo 1.  Review: ◦ Statement Labels ◦ Unconditional Jumps ◦ Conditional Jumps.
Physics 413 Chapter 4 A Fork in the Road LDAB # $ 13 here :ADDA # $ 24 DEC B BNE here WAI BNE is the new instruction. Branch if not equal to zero.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Execution of an instruction
The 8051 Microcontroller and Embedded Systems
ME4447/6405 The George W. Woodruff School of Mechanical Engineering ME4447/6405 Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
Addressing Modes1 Addressing modes are concerned with how the CPU accesses the operands used by its instructions.
1 ECE 372 – Microcontroller Design Assembly Programming HCS12 Assembly Programming Addressing Modes Stack Operations Subroutines.
1 Microcontroller Fundamentals & Programming Addressing Modes.
Computer Systems – Machine & Assembly code. Objectives Machine Code Assembly Language Op-code Operand Instruction Set.
Addressing Modes. Register Addressing Immediate Addressing Base Addressing Indexed Addressing PC-Relative Addressing.
JUMP, LOOP, AND CALL INSTRUCTIONS
1 EKT 225 MICROCONTROLLER I CHAPTER ASSEMBLY LANGUAGE PROGRAMMING.
Computer Organization Instructions Language of The Computer (MIPS) 2.
1 Subroutines Advanced Programming. 2 Top-Down approach to problem solving Algorithm step by step description of how to solve a problem Divide and Conquer.
Data Transmission and Networks Transmission error checking & correcting.
EE345 Chapter 2 Lecture 3 April 4. Quiz every Wednesday 1 quiz = 1% extra credit five quizzes before midterm  5% for midterm. five quizzes before final.
F453 Module 8: Low Level Languages 8.1: Use of Computer Architecture.
EE345 Chapter 2 Lecture 3 April Instruction and addressing modes 1.Extended Addressing 2.Direct Addressing 3.Inherent Addressing 4.Immediate Addressing.
EET 2261 Unit 6 The Stack; Subroutines
EET 2261 Unit 3 Assembly Language; Load, Store, & Move Instructions
Addressing Modes in Microprocessors
Part of the Assembler Language Programmers Toolbox
ECE 3430 – Intro to Microcomputer Systems
The 8051 Microcontroller and Embedded Systems
Chapter 4 Addressing modes
Microcomputer Programming
Packetizing Error Detection
ME4447/6405 Microprocessor Control of Manufacturing Systems and
Packetizing Error Detection
Introduction to Micro Controllers & Embedded System Design Addressing Mode Department of Electrical & Computer Engineering Missouri University of Science.
Packetizing Error Detection
EET 2261 Unit 8 Seven-Segment Displays
8051 ASSEMBLY LANGUAGE PROGRAMMING
EET 2261 Unit 6 The Stack; Subroutines
Indexing Through Memory
Presentation transcript:

Floyd, Digital Fundamentals, 10 th ed EET 2261 Unit 7 Indexed Addressing Mode Read Mazidi, Chapter 6. Homework #7 and Lab #7 due next week. Quiz next week.

Review: Addressing Modes The HCS12s six addressing modes are: Inherent Immediate Direct Extended Relative Indexed (which has several variations) Weve studied all of these except indexed addressing mode.

Indexed Addressing Mode Indexed addressing mode comes in at least five variations: Constant offset indexed addressing Auto pre/post decrement/increment indexed addressing Accumulator offset indexed addressing Constant indirect indexed addressing Accumulator D indirect indexed addressing Of these five variations, well use only the three in bold above. For the others, see the section starting on p. 34 of the HCS12 CPU Reference Manual.HCS12 CPU Reference Manual

The Original Indexed Addressing Mode In older microcontrollers (including the Freescale HC11) indexed addressing meant what were calling constant offset indexed addressing. The HCS12 added the other variations.

Variation #1: Constant Offset Indexed Addressing Mode In constant offset indexed addressing mode, the operands address is found by adding a constant offset to the contents of an index register (usually IX or IY, but possibly also SP or PC). Example: The instruction LDAA 3,X uses Index Register X, with 3 as the constant offset. If Index Register X contains $1500, then this instruction loads Accumulator A with the contents of memory location $1503.

Simple Example of Indexed Addressing ORG $2000 LDX #$1500 LDY #$1600 LDAA 3,X INCA STAA 8,Y BRA * END

Copying a Block of Data A typical use of indexed addressing mode is copying a block of data (many bytes) from one place in memory to another. Example: Suppose we have some data in memory locations $1200 through $128F, and we want to copy it to memory locations $1300 through $138F.

Copying a Block of Data: The Hard Way Without indexed addressing mode, wed have to do something like the following: ORG $2000 LDAA $1200 ;copy first byte STAA $1300 LDAA $1201 ;copy second byte STAA $1301 LDAA $128F ;copy last byte STAA $138F......

Copying a Block of Data: The Smart Way With indexed addressing, its much easier: ORG $2000 LDAB #$90 ;number of bytes LDX #$1200 ;pointer to source bytes LDY #$1300 ;pointer to destination bytes L1: LDAA 0,X STAA 0,Y INX INY DECB BNE L1 END

Variation #2: Auto Pre/post Decrement/ increment Indexed Addressing Mode In the previous program, we incremented IX and IY each time through the loop. Since this is such a common thing to do, the HCS12 gives us a quicker way to do it. In place of these two instructions: LDAA 0,X INX We can use this one instruction: LDAA 1,X+

Copying a Block of Data With Auto Post-Increment Indexed Addressing Once more, our earlier program made easier: ORG $2000 LDAB #$90 ;number of bytes LDX #$1200 ;pointer to source bytes LDY #$1300 ;pointer to destination bytes L1: LDAA 1,X+ STAA 1,Y+ DECB BNE L1 END

Variation #3: Accumulator Offset Indexed Addressing Mode In accumulator offset indexed addressing, the operands address is found by adding the contents of Accumulator A or B or D to the contents of an index register. Example: The instruction LDAA B,X uses Index Register X, with the contents of Accumulator B as the offset. If Index Register X holds $1500 and Accumulator B holds $07, then this instruction loads Accumulator A with the contents of memory location $1507.

Look-Up Tables Indexed addressing mode is also useful for implementing look-up tables. Look-up tables can save us time in a program by storing the results of frequently used computations in memory so that we can look up the results when we need them instead of having to perform the calculation.

Look-Up Tables: Example Example: Suppose your program frequently needs to raise numbers to the 2 nd power. Instead of including instructions in your program to do the math, you can store a table of squares in memory, and then look up the values when you need them. xx2x

Implementing Our Look-Up Table Example: Part 1 First, we need to store the square values in consecutive bytes of memory. Typically youll store them in EEPROM so that the values are retained when power is lost. AddressValue $05000 $05011 $05024 $05039 $ $ …… Lets say we want our look-up table to start at address $0500. Then heres what we need to store in memory:

The DC.B Assembler Directive The DC.B (Define Constant Byte) directive lets us set up constant values in memory bytes. To define our look-up table, wed do the following: ORG $0500 DC.B 0, 1, 4, 9, 16, 25, 36

Three Ways to Load Values into Memory: First Way You now know at least three ways to place a specific value into a memory location. Example: Suppose we want to place the value $A1 into memory location $0600. The first way is to do it manually, using CodeWarriors Memory window.

Three Ways to Load Values into Memory: Second Way The second way is to use HCS12 instructions in your program, which of course will execute when the program runs. LDAA #$A1 STAA $0600

Three Ways to Load Values into Memory: Third Way The third way is to use the DC.B assembler directive, which places the value into memory when the program is downloaded to the chip, before the program runs. ORG $0600 DC.B $A1

Implementing Our Look-Up Table Example: Part 2 Now that weve defined our look-up table in memory, how do we use the table? Heres where indexed addressing is handy. Suppose we have a number in Accumulator B and we want to load that numbers square into Accumulator A. Heres how to do it: LDX #$0500 ;point to the table LDAA B,X ;load tables Bth value

Putting It All Together Combining the two pieces, we have: ABSENTRY Entry ;Define the look-up table. ORG $0500 DC.B 0, 1, 4, 9, 16, 25, 36 ;Use the look-up table. ORG $2000 Entry: LDX #$0500 ;point to the table LDAA B,X ;load tables Bth value

Using a Label for the Table Instead of using the tables address, wed do better to use a label: ABSENTRY Entry ;Define the look-up table. ORG $0500 Table: DC.B 0, 1, 4, 9, 16, 25, 36 ;Use the look-up table. ORG $2000 Entry: LDX #Table ;point to the table LDAA B,X ;load tables Bth value

Checksums A checksum byte is an extra byte appended to data that is being transmitted. Its purpose is to allow error checking by the receiver. Similar to a parity bit.

Different Ways to Compute Checksums There are many different ways to compute checksum bytes. Theyre all effective, as long as the sender and the receiver are using the same method. Similar to parity, where we can use even parity or odd parity. It doesnt matter which one we use, as long as the sender and receiver use the same method. See next two slides for the checksum method discussed in Chapter 6. But as well see in Chapter 8, CodeWarrior uses a slightly different method when sending a program to the HCS12 chip.

Chapter 6s Method for Generating the Checksum Byte The sender uses the following method to calculate the checksum byte: 1.Add all of the data bytes together, discarding any carries. 2.Take the twos-complement of the sum. The result of Step 2 is the checksum byte, which is appended to the data bytes when the data is transmitted.

Chapter 6s Method for Checking the Checksum The receiver uses the following method to check for errors: 1.Add all of the data bytes and the checksum byte together, discarding any carries. 2.The result should equal 0. If it does not equal 0, an error has occurred during transmission.

Review: Subroutines Subroutines are useful for at least two reasons: 1.They let you execute code repeatedly without having to type the code again. 2.They help your organize long programs into separate parts that each do their own little task. Example: Review the use of the Delay subroutine in Lab05BlinkingLEDs.Lab05BlinkingLEDs

Macros and Modules Macros and modules are similar to subroutines. For example, think of a module as a subroutine that is saved in its own separate file, instead of being part of the main.asm file. The book explains the extra steps you must take to call code in one file from another file. Macros and modules are advanced topics that we wont use in this course.