Setting the C (Carry), V (overflo w), N (negative) and Z ...

EE 308

Spring 2002

Addition and subtraction of hexadecimal numbers.

Setting the C (Carry), V (overflow), N (negative) and Z (zero) bits

How the C, V, N and Z bits of the CCR are changed

Condition Code Register Bits N, Z, V, C

N 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 overflow

C bit is set if operation produced a carry (borrow on subtraction)

Note: Not all instructions change these bits of the CCR

1

EE 308

Spring 2002

Addition of hexadecimal numbers

ADDITION:

C bit set when result does not fit in word

V bit set when

P + P = N

N + N = P

N bit set when MSB of result is 1

Z bit set when result is 0

7A

+52

2A

+52

AC

+8A

AC

+72

CC

7C

36

1E

C: 0

C: 0

C: 1

C: 1

V: 1

V: 0

V: 1

V: 0

N: 1

N: 0

N: 0

N: 1

Z: 0

Z: 0

Z: 0

Z: 0

2

EE 308

Spring 2002

Subtraction of hexadecimal numbers

SUBTRACTION:

C bit set on borrow (when the magnitude of the subtrahend

is greater than the minuend)

V bit set when

N ? P = P

P ? N = N

N bit set when MSB is 1

Z bit set when result is 0

7A

?5C

8A

?5C

5C

?8A

2C

?72

1E

2E

D2

BA

C: 0

C: 0

C: 1

C: 1

V: 0

V: 1

V: 1

V: 0

N: 0

N: 0

N: 1

N: 1

Z: 0

Z: 0

Z: 0

Z: 0

3

EE 308

Spring 2002



Simple programs for the HC12

A simple HC12 program fragment

org

ldaa

asra

staa

$0800

$0900

$0901

A simple HC12 program with assembler operatives

prog:

data:

equ

equ

$0800

$0900

CODE:

section

org

ldaa

asra

staa

swi

.text

prog

input

section

org

dc.b

ds.b

.data

data

$07

1

DATA:

input:

result:

4

result

EE 308

Spring 2002

How the HC12 executes a simple program

EXECUTION OF SIMPLE HC12 PROGRAM

LDAA $0913

PC = 0x0800

NEGA

PC = 0x0801

PC = 0x0802

Control

Control

Control

Control

Control

unit reads B6

decodes B6

unit reads address MSB 09

unit reads address LSB 13

units tells memory to fetch

contents of address 0x0913

Control units tells ALU to latch value

STAA $0914

0x0800

0x0801

0x0802

0x0803

0x0804

0x0805

0x0806

B6

09

13

40

7A

09

14

PC = 0x0803

Control unit reads 40

Control unit decodes 40

Control unit tells ALU to negate ACCA

PC = 0x0804

Control

Control

Control

Control

Control

Control

PC = 0x0805

PC = 0x0806

unit reads 7A

decodes 7A

unit reads address MSB 09

unit reads address LSB 14

units fetches value of ACCA from ALU

units tells memory to store value

at address 0x0914

PC = 0x0807

0x0913

0x0914

6C

5A

A

Things you need to know to write an HC12 assembly language program

HC12 Assembly Language Programming

Programming Model

HC12 Instructions

Addressing Modes

Assembler Directives

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download