MAR Memory Address Register MDR Memory Data Register PC Program Counter IR Instruction Register IX, IY Index Register SP Stack Pointer ACCA

1 MAR – Memory Address Register MDR – Memory Data Register PC – Program Counter IR – Instruction Register IX, IY – Index Register SP – Stack Pointer ...
Author: Charlotte McCoy
1 downloads 1 Views 598KB Size
1

MAR – Memory Address Register MDR – Memory Data Register PC – Program Counter IR – Instruction Register IX, IY – Index Register SP – Stack Pointer ACCA – Accumulator A ACCB – Accumulator B CCR – Conditional Code Register ALU – Arithmetic Logic Unit

2



An ALU of Four Basic Operations

3



The result needs to be adjusted if necessary.  Add $6 to every sum digit greater than $9  Add $6 to every sum digit that had a carry of 1 to the next higher digit.



The fifth bit of the condition code register (CCR) is the halfcarry, or H flag, that keeps a carry from the lower 4 bits to the higher 4 bits during the addition.

4



The HCS12 has the DAA instruction that performs a decimal adjust accumulator A. - automatically adds $6 to any 4 bits that requires it.



Example 4.2.1 (Example 2.9) – Add the BCD numbers stored at $1000 and $1001 and save the sum at $1010.

Solution: LDAA ADDA DAA STAA

$1000 $1001 $1010 5



Example 4.2.2 – Separate two digits of a BCD number Assume that X = 25 (BCD), we want to get A = 2 and B = 5 Register Transfer Notation AX BA B  B & $0F AA/2 AA/2 AA/2 AA/2

Arithmetic A=X B=X B = LSN (X) A = X >> 1 A = X >> 2 A = X >> 3 A = X >> 4 = MSN(X)

Assembly Code LDAA X TAB ANDB #$0F LSRA LSRA LSRA LSRA

6

Example 4.2.3, we want convert a BCD number to its equivalent binary number: 6810 = (0110 1000)BCD = 0110 * 101 + 1000 * 100 The assembly program is as followed: ORG $0000 bcdval DS.B 1 ; BCD value binval DS.B 1 ; binary equivalent number. ORG $C000 LDAA bcdval ; A > 2 LSRB ; B = B >> 3 LSRB ; B = B >> 4 = MS bits of BCD number LSLB ; B