Docsity

Arithmetic Operations of MC68HC11: Unsigned and Signed Numbers, Carry and Overflow Flags -, Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download Arithmetic Operations of MC68HC11: Unsigned and Signed Numbers, Carry and Overflow Flags - and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

ECE 447 - Lecture 7

Arithmetic operations of

MC68HC

B = b 7 b 6 b 5 b 4 b 3 b 2 b 1 b 0

Unsigned vs. signed numbers

Unsigned number

Signed number

B = b 7 b 6 b 5 b 4 b 3 b 2 b 1 b 0

B = b 7 b 6 b 5 b 4 b 3 b 2 b 1 b 0

weights 128 64 32 16 8 4 2 1

weights -128 64 32 16 8 4 2 1

B = b 020 + b 121 + b 222 + b 323 + b 424 + b 525 + b 626 + b 727 = ∑bi 2 i

i=

7

B = b 020 + b 121 + b 222 + b 323 + b 424 + b 525 + b 626 - b 727 = - b 727 + ∑bi^2 i

i=

6

7 0111 1111 0111 0111 6 0110 1110 0110 0110 5 0101 1101 0101 0101 4 0100 1100 0100 0100 3 0011 1011 0011 0011 2 0010 1010 0010 0010 1 0001 1001 0001 0001 0 0000 1000 0000 0000 -0 1000 1111 -1 1001 0111 1111 1110 -2 1010 0110 1110 1101 -3 1011 0101 1101 1100 -4 1100 0100 1100 1011 -5 1101 0011 1011 1010 -6 1110 0010 1010 1001 -7 1111 0001 1001 1000 -8 0000 1000

Signed- magnitude Biased Two’s complement

One’s complement

Two’s complement representation of signed numbers

-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

X

k =

X >0 0 X <

(^0) X +2 k^ = X+

Definition of the Condition Code Register flags (2)

C = 1 if result > MAX_UNSIGNED or result < 0 0 otherwise where MAX_UNSIGNED = 2^8 -1 for 8-bit operands (registers A, B) 216 -1 for 16-bit operands (register D)

V = 1 if result > MAX_SIGNED or result < MIN_SIGNED 0 otherwise where MAX_SIGNED = 27 -1 for 8-bit operands (registers A, B) 215 -1 for 16-bit operands (register D) MIN_SIGNED = -2^7 for 8-bit operands (registers A, B) -2^15 for 16-bit operands (register D)

Carry flag - C

Overflow flag - V

out-of-range for unsigned numbers

out-of-range for signed numbers

Overflow for signed numbers (1)

Indication of overflow

Positive

+ Positive

= Negative

Negative

+ Negative

= Positive

Formulas

Overflow2’s complement = xk-1 yk-1 sk-1 + xk-1 yk-1 sk-1 =

= ck ⊕ ck-

Overflow for signed numbers (2)

xk-1 yk-1 ck-1 ck sk-1 overflow ck Ü ck-

Arithmetic instructions (1)

1. addition Acc + M ü Acc

ADD [A, B, D]

ADC [A, B]

2. subtraction Acc – M ü Acc

SUB [A, B, D] SBC [A, B]

IMM, DIR, EXT, IND

N Z V C

IMM, DIR, EXT, IND

EXT, IND

INH

3. negation -X

NEG [A, B]

NEG

Extending the number of bits of a signed number

xk -1 xk -2 … x 1 x 0

yk’ -1 yk’ -2 … yk yk -1 yk -2 … y 1 y 0

X

Y

two’s complement

xk -1 xk -1 xk -1... xk -1 xk -2 … x 1 x 0