eet 2261 unit 2 hcs12 architecture

Download EET 2261 Unit 2 HCS12 Architecture

Post on 22-Feb-2016




0 download

Embed Size (px)


EET 2261 Unit 2 HCS12 Architecture. Read Almy , Chapters 3, 4, and 5. Homework #2 and Lab #2 due next week. Quiz next week. Programming Model. Inside any processor’s CPU are certain registers that the programmer has access to. - PowerPoint PPT Presentation


EET 2261 PowerPoint Slides

EET 2261 Unit 2HCS12 Architecture Read Almy, Chapters 3, 4, and 5.

Homework #2 and Lab #2 due next week.

Quiz next week.1Handouts: Quiz 1, Instruction Summary practice sheet, Addressing Modes practice sheet, Condition Code practice sheet.CPU Programming ModelInside any processors CPU are certain registers that the programmer has access to.The list of these registers is often called the CPU programming model. For the HCS12:RegisterNumber of bitsAccumulator A8Accumulator B8Accumulator D16Index Register X16Index Register Y16Stack Pointer16Program Counter16Condition Code Register82HCS12 CPU Programming ModelSee page 30 of textbook or page 375 of CPU Reference Manual.

3Purposes of the RegistersAccumulators A, B, and D are general-purpose registers that the programmer can use however she wants.PC and CCR are special-purpose registers that always perform specific functions:PC always holds the address of the next instruction to be executed.CCR always holds three mask bits and five status flags.The other registers (X, Y, and SP) sometimes serve as general-purpose registers and sometimes perform specific functions.4Accumulators A, B, and DThe HCS12 has two 8-bit accumulators, named A and B. These two can also be regarded as forming a single 16-bit accumulator named D.

Some instructions operate on Accumulator A or Accumulator B. Other instructions operate on Accumulator D.Examples: LDAA loads an 8-bit number into A.LDAB loads an 8-bit number into B.LDD loads a 16-bit number into D.

5HCS12 Instruction SetA processors instruction set is the list of instructions (or commands) that the CPU recognizes.Most of these instructions manipulate the CPUs registers or locations in memory (or both).6

Instruction Set SummaryFor a summary of the HCS12s instruction set, see the table on pages 381-394 of the CPU Reference Manual.

7Example: ABAThis table uses many abbreviations and special symbols. Theyre all explained in the pages before the table (pages 377-380 of the CPU Reference Manual.)Lets look at one instruction, ABA, which adds Accumulator B to Accumulator A and puts the results in Accumulator A.

8First Column: Source FormThis column shows how youll type the instruction when you start writing assembly language programs next week. ABA is very simple. Other instructions are more complicated and have additional things you need to type, explained here:

9Second Column: OperationThis column explainsthe operation that the instruction performs.Some symbols used in this column:

10Third Column: Addressing ModeThis column shows the addressingmode(s) used by the instruction. As well see below, there aresix different addressing modes.Some abbreviations used in this column:

11Fourth Column: Machine CodingComputers use numbers torepresent all kinds of information, including the instructions in a program. This column shows the numbers (in hex) that represent each instruction.Some abbreviations used in this column:

12Fifth Column: Access DetailThis column shows howmany cycles each instruction takes to execute, and what happens during each of those cycles.Some abbreviations used in this column:

13The only thing well care about is the number of cycles required for a particular instruction to execute.Last Two Columns: Condition CodesThese columns show howeach instruction affects the bits in the Condition Code Register.Symbols used in these columns:

14Start a new project in CodeWarrior, go into the debugger, place an ABA instruction at $2000, set the PC to $2000, set values in A and B, and single-step.SummaryThis table summarizes a lot of useful information for every one of the 207 instructions that you can use when writing programs for the HCS12.Youll refer to this table often.

15Do practice sheet on instructionSummary.Instruction Set DetailsFor details on all 207 of the HCS12s instructions, see pages 100-309 of the CPU Reference Manual.

16RISC Architecture versus CISC Architecture Some commercially available microprocessors use a RISC (Reduced Instruction Set Computer) architecture.Small instruction set (maybe 25 or 30 instructions).Each instruction performs a simple operation and executes quickly.The HCS12 is an example of a CISC (Complex Instruction Set Computer) processor.Large instruction set (207 in the HCS12s case).Some instructions perform complex operations that might require a dozen or more instructions in a RISC processor.17Theres a lot of debate over which architecture is better.Categories of InstructionsThe Instruction Set Summary table lists instructions alphabetically. Sometimes its more useful to have instructions grouped into categories of similar instructions.Examples of categories:Load and Store InstructionsAddition and Subtraction InstructionsBoolean Logic Instructions

See Section 5 (starting on p. 55) of the CPU Reference Manual.18The manuals categories are very similar to, but not exactly the same as, the textbooks categories on pages 45-47 and in Chapters 6 11.MnemonicsIn this course well write programs in a language called assembly language.Assembly language contains many mnemonics, which are abbreviations for actions that we want to perform. (Mnemonics appear in the Source Form column of the Instruction Set Summary.)Some examples:

MnemonicActionABAAdd Accumulator B to Accumulator ALDAALoad Accumulator A with a numberSTAAStore Accumulator A into memory19OperandsSome HCS12 instructions require the programmer to specify one or two operands, in addition to the mnemonic.These operands are the data (usually numbers) to be operated on.Example: The LDAA instruction loads some number into accumulator A. The number thats to be loaded is the operand.In the instruction LDAA #5, the operand is 5.20But there are other ways to specify the operand. For example, instead of specifying the number to be loaded right in the instruction itself, maybe we want to load the number from a particular memory location into ACCA.OpcodesWhen an instruction is translated into machine code, the mnemonic is replaced by an opcode.

Example: The assembly-language instruction LDAA #5 becomes $8605

in machine code, because $86 is the opcode for LDAA.MnemonicOperandOpcode21Review: Memory AddressesEvery computer system has memory, where programs and data are stored.Each location within this memory has an address by which we identify it. And each location holds some contents, which is one byte.The HCS12 uses a 16-bit address bus.So the addresses of its memory locations range from $0000 to $FFFF. (In decimal, thats 0 to 65,535.) So we have 65,536 memory locations, each of which holds one byte.22Review: Memory MapProgrammers must pay attention to where in memory their programs and data are stored. Some of a systems memory is reserved for special purposes. Therefore, within the range of possible addresses, only some can be used by your programs. A memory map shows which memory addresses are reserved, and which are available for your use.Next slide shows memory map for our HCS12 chip.23See page 26 of Device User Guide.Reserved addresses:$0000 to $03FF are reserved for special-function registers.$FF00 to $FFFF are reserved for interrupt vectors.HCS12 Memory Map

24Addressing ModesEvery instance of an instruction uses an addressing mode.The HCS12s six addressing modes are:InherentImmediateDirectExtendedIndexed (which has several variations)Relative25Which Addressing Mode(s) Does an Instruction Use?Some instructions come in only one flavor: they can only use one addressing mode.Example: The ABA instruction always uses the inherent addressing mode.Other instructions come in two or more flavors.Example: The LDAA instruction can use immediate, direct, extended, or indexed addressing.26The instruction summary tells you the possible addressing modes for any instruction.Inherent Addressing ModeIn inherent addressing mode, the programmer doesnt specify any operands, because the mnemonic itself contains all of the information needed.Example: The ABA instruction adds the numbers in Accumulators A and B. So we already know where the two operands are located, and we dont need to say any more. We just write ABA, instead of writing something like ABA #5.27Immediate Addressing ModeIn immediate addressing mode, the programmer gives the operand(s) as part of the instruction. The pound sign (#) indicates immediate addressing.Example: LDAA #15 causes the number 15 to be loaded into Accumulator A.The following are all equivalent:LDAA #15LDAA #$FLDAA #%111128In CodeWarrior, hand-code and run an LDAA #15.Direct Addressing ModeIn direct addressing mode, the programmer gives the operands address as part of the instruction. Example: LDAA 51 causes the number located at memory address 51 to be loaded into Accumulator A.The following are all equivalent:LDAA 51LDAA $33LDAA %0011001129In CodeWarrior, hand-code and run an LDAA 51.

Limitation of Direct Addressing ModeIn direct addressing mode, the operands address can only be one byte long.So the highest address we can use with direct addressing is $FF, or 255. Since there are 65,536 locations in memory, this means that 65,281 of those locations cant be reached by direct addressing!Solution: use extended addressing mode instead of direct addressing mode. (See next slide.)30Extended Addressing ModeIn extended addressing, the programmer gives the operands address as part of the instruction (just as in direct addressing). But this address is two bytes long, so we can reach any memory location.Example: LDAA $701F causes the number located at memory address $701F to be loaded into Accumulator A.The following are all equivalent:LDAA 28703LDAA $701FLDAA %011100000001111131Summary: Addressing ModesWeve discussed the first four of the HCS12s six addressing modes:InherentImmediateDirectEx