Intel mcs-48 manual Application Examples Double Exchange, Double Left Logical Shift

Models: mcs-48

1 478
Download 478 pages 26.88 Kb
Page 134
Image 134

APPLICATION EXAMPLES

DOUBLE EXCHANGE

DEX:

DEC

RXO

;EXCHANGE A AND LOW BYTE

 

XCH

A,@RXO

 

 

INC

RXO

;EXCHANGE AEX AND HIGH BYTE

 

XCH

A,AEX

 

 

XCH

A,@RXO

 

 

XCH

A,AEX

 

 

RET

 

;RETURN

DOUBLE LEFT LOGICAL SHIFT

LLSH:

RLC

A

;SHIFT A

 

XCH

A,AEX

;SHIFT AEX

 

RLC

A

 

 

XCH

A,AEX

 

 

RET

 

;RETURN

DOUBLE RIGHT LOGICAL SHIFT

RLSH:

XCH

A,AEX

;SHIFT AEX

 

RRC

A

 

 

XCH

A,AEX

 

 

RRC

A

;SHIFT A

 

RET

 

;RETURN

DOUBLE RIGHT ARITHMETIC SHIFT

RASH:

CLR

C

;SET CARRY

 

CPL

C

 

 

XCH

A,AEX

;IF AEX[7]<>1 THEN

 

JB7

$+3

;CLEAR CARRY

 

CLR

C

 

RRC

A

;SHIFT C INTO AEX

 

XCH

A,AEX

 

 

RRC

A

;SHIFT A

 

RET

 

;RETURN

SINGLE PRECISION BINARY MULTIPLY

This routine assumes a one-byte multiplier and a one-byte multiplicand. The product, therefore, is two-bytes long.

The algorithm follows these steps:

1. The registers are arranged as follows:

ACC-O

R1 - Multiplier

R2 - Multiplicand

R3 - Loop Counter (=8)

The Accumulator and register R1 are treated as a register pair when they are shifted right (see Step 2)

2.The Accumulator and R1 are shifted right one place, thus the LSB of the multiplier goes into the carry.

3.The multiplicand. is added to the accumulator if the carry bit is a 'one'No. action if the carry is a 'zero'.

4.Decrement the loop counter and loop (return to Step 2) until it reaches zero.

5.Shift the result right one last time just before exiting the routine

*The result will be found in the Accumulator (MS Byte) and R1 (LS Byte).

5-23

Page 134
Image 134
Intel mcs-48 manual Application Examples Double Exchange, Double Left Logical Shift, Double Right Logical Shift