6 – processor status flag operations, 1 – sign flag, Ds4830a user’s guide – Maxim Integrated DS4830A Optical Microcontroller User Manual

Page 195

Advertising
background image

DS4830A User’s Guide

195

23.5.3 – ALU Operations Using the Active Accumulator and a Source
The following arithmetic and logical operations can use any register or immediate value as a source. The active
accumulator Acc is always used as the second operand and the implicit destination. Also, Acc may not be used as
the source for any of these operations.

add A[4]

; Acc = Acc + A[4]

addc #32h

; Acc = Acc + 0032h + Carry

sub A[15]

; Acc = Acc – A[15]

subb A[1]

; Acc = Acc – A[1] - Carry

cmp #00h

; If (Acc == 0000h), set Equals flag

and A[0]

; Acc = Acc AND A[0]

or #55h

; Acc = Acc OR

xor A[1]

; Acc = Acc XOR A[1]

23.5.4 – ALU Operations Using Only the Active Accumulator
The following arithmetic and logical operations operate only on the active accumulator.

cpl

; Acc = NOT Acc

neg

; Acc = (NOT Acc) + 1

rl

; Rotate accumulator left (not using Carry)

rlc

; Rotate accumulator left through Carry

rr

; Rotate accumulator right (not using Carry)

rrc

; Rotate accumulator right through Carry

sla

; Shift accumulator left arithmetically once

sla2

; Shift accumulator left arithmetically twice

sla4

; Shift accumulator left arithmetically four times

sr

; Shift accumulator right, set Carry to Acc.0, set Acc.15 to zero

sra

; Shift accumulator right arithmetically once

sra2

; Shift accumulator right arithmetically twice

sra4

; Shift accumulator right arithmetically four times

xchn

; Swap low and high nibbles of each Acc byte

xch

; Swap low byte and high byte of Acc


23.5.5 – ALU Bit Operations Using Only the Active Accumulator
The following operations operate on single bits of the current active accumulator in conjunction with the Carry flag.
Any of these operations may use an Acc bit from 0 to 15.

move C, Acc.0

; copy bit 0 of accumulator to Carry

move Acc.5, C

; copy Carry to bit 5 of accumulator

and Acc.3

; Acc.3 = Acc.3 AND Carry

or Acc.0

; Acc.0 = Acc.0 OR Carry

xor Acc.1

; Acc.1 = Acc.1 OR Carry

None of the above bit operations will cause the auto-increment, auto-decrement, or modulo operations defined by
the accumulator pointer control (APC) register.


23.5.6 – Example: Adding Two 4-Byte Numbers Using Auto-Increment

move A[0], #5678h

; First number – 12345678h

move A[1], #1234h
move A[2], #0AAAAh

; Second number – 0AAAAAAAh

move A[3], #0AAAh
move APC, #81h

; Active Acc = A[0], increment low bit = mod 2

add A[2]

; A[0] = 5678h + AAAAh = 0122h + Carry

addc A[3]

; A[1] = 1234h + AAAh + 1 = 1CDFh
; 12345678h + 0AAAAAAAh = 1CDF0122h

23.6

Processor Status Flag Operations

The Processor Status Flag (PSF) register contains five flags that are used to indicate and store the results of
arithmetic and logical operations. Four of these flags can be used for conditional program branching.

23.6.1 – Sign Flag
The Sign flag (PSF.6) reflects the current state of the most significant bit of the active accumulator, (Acc.15). If
signed arithmetic is being used, this flag indicates whether the value in the accumulator is positive or negative.

Advertising