Beruflich Dokumente
Kultur Dokumente
3C
The arithmetic instruction set enables arithmetic operations to be performed between an accumulator and an operand. The arithmetic operations supported by the HC12 are: Add and Subtract Multiply and Divide
Adding and Subtracting is primarily done using the A, B, or D accumulators in combination with an immediate value or memory location (variable). Accumulator A Accumulator B Accumulator D Addition ADDA ADDB ADDD Subtraction SUBA SUBB SUBD
#32 #12
;A = 32 +12
;A=45 +12
When adding or subtracting multi-byte or multi-word numbers, the carry or borrow bit must be passed on the next operation.
Accumulator A
Accumulator B
Add with Carry
Subtract with Burrow
ADCA ADCB
SBCA SBCB
Example
... LDAA
#32
;A=32 (%00100000) NEGA
... ;A=-32 (%11100000)
On the HS12 we can multiply both 8 and 16 bit numbers, and these number can be signed or unsigned. Multiplying eight bit numbers When multiplying eight bit numbers, the number to be multiplied are loaded into the accumulators A and B. The multiply command is issued and the result is made available in accumulator D.
Unsigned 8 bit Multiply
Saturday, 22 August 2009
MUL
10
Example
.... LDAA LDAB MUL ... #5 #6 ; A=5 ; B=6 ; D=5 * 6 = 30
11
Multiplying sixteen bit numbers When multiplying sixteen bit numbers, the numbers to be multiplied are loaded into the D accumulator and the Y index register. The multiply command is issued and the result is made available, the most signicant word is in Y and the least signicant in D.
Unsigned 16 bit Multiply
Signed 16 bit Multiply
EMUL EMULS
12
Example
.... LDD #-250 LDY #6 EMULS ... ; D=-250 ; Y=6 ; Y:D=-250 * 6 = -1500
13
The CPU12 instruction set includes instruction for the division of 16 and 32 bit numbers. Dividing 16 bit numbers The number to be divided is loaded into D and the number to divide it by is loaded into X. The divide command is then issued and the result is available in X and the remainder in D.
IDIV IDIVS
14
Example
.... LDD #32 LDX #6 IDIV ... ; D=32 ; X=6 ; 32/6 (X=5, D=2)
15
Dividing 32 bit numbers The number to be divided is loaded into Y:D and the number to divide it by is loaded into X. The divide command is then issued and the result is available in Y and the remainder in D.
EDIV EDIVS
16
Example
.... LDY #$1234 LDD #$0032 LDX #$6666 EDIV ... ; ; ; ; ; Y=$1234 D=$0032 X=$6666 $12340032/$6666 (Y=$2d82,D=0)
17
18
Example
.... LDDA ANDA ... #23 #08 ; A=23 ; A=A&8 = 0
19
Compare A to Memory Compare B to Memory Compare D to Memory Compare X to Memory Compare Y to Memory Compare SP to Memory
20
Operand
21
Examples
.... LDAA TSTA ... .... LDAA CMPA ... #23 #23 ; A=23 ; Z=1,N=0,H=0,V=0,C=0 #23 ; A=23 ; Z=0,N=0,H=0,V=0,C=0
22
23
Branch if greaterthan
Branch if no Overow
24
25
Long Branches
Capable of branching anywhere.
26
Branch if no Overow
27
Examples
.... LDAA BNE ... #23; A=23,Z=0,N=0,H=0,V=0,C=0 LOOP ; IF (Z==0) branch to LOOP
28
Decrement Counter and branch if (counter != 0) Decrement Counter and branch if (counter == 0) Increment Counter and branch if (counter != 0) Increment Counter and branch if (counter == 0) Test Counter and branch if (counter != 0)
29
A=A - 1
Back to LOOP
T
A!=0
30
31
...
32
This will set the msb of CCR (S=1) ANDCC can be used for clearing the bits. ANDCC #%01111111
33
CLI SEI
CLI and SEI are no longer directly supported by CPU12 however many assemblers translate this mnemonic to the CPU12 equivalent of:
CLI
SEI
ANDCC
#%11101111 ORCC
#%00010000
34
This instruction tells the processor to do nothing, but it takes the processor exactly 1 clock cycle to do it.
Saturday, 22 August 2009 35