APPLICATION EXAMPLES

2 BYTE PROCESSING SYSTEM

A suggested model of a processing routine

(If Equal) Sets Flag and Exits

takes two single byte inputs from different

(If Not Equal) and Outputs the Larger to a

ports, compares them, and performs the

Third Port

following, depending on the result of the

 

comparison:

 

INPUT FIRST OPERAND

 

INPUT SECOND OPERAND

 

 

NOT EQUAL

PROCESS: CLR

FO

;CLEAR FO BIT (INITIALIZE)

IN

A,P1

;READ FIRST INPUT, STORE IN RO

MOV

RO,A

 

IN

A,P2

;READ SECOND INPUT, STORE IN R1

MOV

R1,A

 

CPL

A

;SUBTRACT SECOND FROM FIRST

INC

A

;(2'sCOMPLEMENT AND ADD)

ADD

A,RO

 

JZ

EQUL

;BRANCH IF THEY ARE EQUAL

JNC

SECOND ;IF NEGATIVE, SECOND WAS LARGER

MOV

A,RO

;ELSE, OUTPUT FIRST

OUTL

BUS,A

 

JMP

DONE

;EXIT

SECOND: MOV

A,R1

;OUTPUT SECOND

OUTL

BUS,A

 

JMP

DONE

;EXIT

EQUL: CPL

FO

;SET FO

JMP

DONE

;EXIT

5·25

Page 136
Image 136
Intel mcs-48 Application Examples Byte Processing System, R1,A, CPL Subtract Second from First INC, 2sCOMPLEMENT and ADD