DOC PREVIEW
NMT EE 308 - Addition and subtraction of hexadecimal numbers.

This preview shows page 1-2-3-4-5 out of 14 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 14 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Spring 2003Addition and subtraction of hexadecimal numbers.Setting the C (Carry), V (overflow), N (negative) and Z (zero) bitsHow the C, V, N and Z bits of the CCR are changedCondition Code Register Bits N, Z, V, CN bit is set if result of operation in negative (MSB = 1)Z bit is set if result of operation is zero (All bits = 0)V bit is set if operation produced an overflowC bit is set if operation produced a carry (borrow on subtraction)Note: Not all instructions change these bits of the CCR1EE 308 Spring 2003Addition of hexadecimal numbersADDITION:C bit set when result does not fit in wordV bit set when P + P = N N + N = P 7A+52 CC+52 2A 7C+8A AC 36+72 AC 1EN bit set when MSB of result is 1Z bit set when result is 0C: 0 C: 1V: 0C: 0V: 1C: 1V: 1 V: 0N: 1 N: 0 N: 1Z: 0 Z: 0 Z: 0N: 0Z: 02EE 308 Spring 2003Subtraction of hexadecimal numbersSUBTRACTION:C bit set on borrow (when the magnitude of the subtrahendV bit set when N − P = P P − N = N is greater than the minuend) 7A−5C 1E−5C 8A 2E 5C−8A D2 2C−72 BAC: 0V: 0C: 1V: 0C: 0V: 1V: 1C: 1N: 0 N: 0 N: 1 N: 1Z: 0Z: 0Z: 0Z: 0N bit set when MSB is 1Z bit set when result is 0 3EE 308 Spring 2003Simple programs for the HC12A simple HC12 program fragment ldaa $0900 asra staa $0901 org $0800A simple HCS12 program with assembler operativesCODE: section .text swiDATA: section .data org dataresult: ds.b 1input: dc.b $07 asra ldaa input staa result org progprog: equ $0800data: equ $09004EE 308 Spring 2003How the HCS12 executes a simple program0x08000x08010x08020x08030x08040x08050x0806B609137A09PC = 0x0803Control unit reads address MSB 09PC = 0x0800 Control unit reads B6Control decodes B6Control units tells ALU to latch value contents of address 0x0913Control units tells memory to fetch Control unit reads address MSB 09Control unit reads address LSB 13PC = 0x0804PC = 0x0801PC = 0x0802Control unit reads 7AControl decodes 7AControl units fetches value of ACCA from ALUControl units tells memory to store valuePC = 0x0807PC = 0x0805PC = 0x0806EXECUTION OF SIMPLE HC12 PROGRAM0x0913 6C0x0914Control unit reads address LSB 14 at address 0x091414LDAA $0913STAA $0914NEGA40Control unit reads 40Control unit decodes 40Control unit tells ALU to negate ACCA5AAThings you need to know to write an HCS12 assembly language programHC12 Assembly Language ProgrammingProgramming ModelHC12 InstructionsAddressing ModesAssembler Directives5EE 308 Spring 2003HCS12 Programming Model — The registers inside the HCS12 CPUthe programmer needs to know about0150150150150BDXYSPPCCCR0015A7 7NIHXS Z V C6EE 308 Spring 2003Addressing Modes for the HCS12Almost all HCS12 instructions operate on data in memoryThe address of the data an instruction operates on is called the effective ad-dress of that instruction.Each instruction has information which tells the HCS12 the address of thedata in memory it operates on.The addressing mode of the instruction tells the HCS12 how to figure out theeffective address for the instructionThe HCS12 has 6 addressing modesMemory address used by instructionEffective Address:ADDRESSING MODE:How the HC12 calculates the effective addressHC12 ADDRESSING MODES:INH InherentIMM ImmediateDIR DirectEXT ExtendedIDXREL Relative (used only with branch instructions)Indexed (won’t study indirect indexed mode)Most of the HC12’s instructions access data in memoryThere are several ways for the HC12 to determine which address to access7EE 308 Spring 2003The Inherent (INH) addressing modeInherent (INH) Addressing ModeInstructions which work only with registers inside ALUABA ; Add B to A (A) + (B) −> A18 06CLRA ; Clear A 0 −> A87ASRA ; Arithmetic Shift Right A47TSTA ; Test A (A) − 0x00 Set CCR97479718870x09000x08001735024AC7AXB06There is no effective addressThe HC12 does not access memory8EE 308 Spring 2003The Extended (EXT) addressing modeExtended (EXT) Addressing ModeInstructions which give the 16−bit address to be accessedLDAA $0900 ; ($0900) −> AB6 09 00LDX $0901 ; ($0901:$0902) −> XSTAB $0903 ; (B) −> $09037B 09 03Effective address is specified by the two bytes following op codeFE 09 01FE09017B0903B609000x09000x08001735024AC7AXBEffective Address: $0900Effective Address: $0901Effective Address: $09039EE 308 Spring 2003The Direct (DIR) addressing modeDirect (DIR) Addressing ModeInstructions which give 8 LSB of address (8 MSB all 0)LDAA $20 ; ($0020) −> A96 20STX $21 ; (X) −> $0021:$00225E 21Effective address is specified by byte following op code21205E0x00200x08001735024AC7AXB96Effective Address: $0020Effective Address: $002110EE 308 Spring 2003The Immediate (IMM) addressing modeImmediate (IMM) Addressing Mode8B 0AValue to be used is part of instructionLDAA #$17 ; $17 −> AADDA #10 ; (A) + $0A −> A86 17Effective address is the address following the op code0AB6178B0x09000x08001735024AC7AXBEffective Address: PC + 1Effective Address: PC + 111EE 308 Spring 2003The Indexed (IDX) addressing modeXEFFADDRYADDREFFIndexed (IDX) Addressing ModeEffective address is obtained from X or Y register (or SP or PC)AB 45ADDA 5,Y ; Use (Y) + 5 as address to get value to add to rA6 00LDAA 0,X ; Use (X) as address to get value to put in ASimple FormsMore Complicated FormsEffective address: contents of XEffective address: contents of Y + 562 23Effective address: contents of X + 4 ; then increment the number at address (X) ; Add 4 to XINC 4,+X ; Pre−increment IndexedINC 2,X− ; Post−decrement Indexed ; then subtract 2 from X62 3E Effective address: contents of X ; Increment the number at address (X),12EE 308 Spring 2003Different types of indexed addressing(Note: There are several other types we will not discussPostincrementPreincrementPostdecrementPredecrement(X)+nLDAA n,XLDAA −n,X (X)−n0 to FFFF0 to FFFFExampleValue in XAfter Done(X)(X)RegistersTo UseX, Y, SP, PCX, Y, SP, PCOffsetLDAA n,X+ (X) (X)+n X, Y, SPLDAA n,+X (X)+n (X)+n X, Y, SPLDAA n,X−1 to 81 to 81 to 81 to 8X, Y, SPX, Y, SP(X)−nLDAA n,−X (X)−nConstant OffsetConstant OffsetACC OffsetLDAA A,X (X)+(A)(X)X, Y, SP, PC(Does not include


View Full Document

NMT EE 308 - Addition and subtraction of hexadecimal numbers.

Documents in this Course
Load more
Download Addition and subtraction of hexadecimal numbers.
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Addition and subtraction of hexadecimal numbers. and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Addition and subtraction of hexadecimal numbers. 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?