Intel mcs-48 manual Application Examples Binary Multiply, Interrupt Handling

Models: mcs-48

1 478
Download 478 pages 26.88 Kb
Page 135
Image 135

APPLICATION EXAMPLES

BINARY MULTIPLY

BMPY:

MOV

R3,#08H

;SET COUNTER TO 8

 

CLR

A

;CLEAR A

 

CLR

C

;CLEAR CARRY BIT

BMPI:

RRC

A

;DOUBLE SHIFT RIGHT ACC & R1

 

XCH

A,R1

;INTO CARRY

 

RRC

A

 

 

XCH

A,R1

 

 

JNC BMP3

;IF CARRY=1 ADD, OTHERWISE DON'T

 

ADD

A,R2

;ADD MULTIPLICAND TO ACCUMULATOR

BMP3:

DJNZ

R3,BMPI

;DECREMENT COUNTER AND LOOP IF 0

 

RRC

A

;DO A FINAL RIGHT SHIFT AT THE

 

XCH

A,R1

;END OF THE ROUTINE

 

RRC

A

 

 

XCH

A,R1

 

INTERRUPT HANDLING

This interrupt routine assumes single level interrupt. The purpose is to store the status of the machine at the time the interrupt occurs by storing contents of all registers, accumu- lator, and the status word. At the end of the interrupt the state of the machine is restored and interrupts are enabled again.

INTRPT: SEL

RB1

;SAVE WORKING REGISTERS

MOV

@RO,A

;RO IN ALTERNATE REGISTER

 

 

;BANK CONTAINS SACC

 

 

;POINTER FOR SAVING

 

 

;ACCUMULATOR

 

 

flNTERRUPT SERVICE

 

 

lROUTINE

MOV

RO,SACC ;RESTORE SACC

MOV

A,@RO

;RESTORE ACCUMULATOR

RETR

 

;RESTORE WORKING REGISTERS

 

 

;RESTORE PSW AND

 

 

;RE-ENABLE INTERRUPTS

5-24

Page 135
Image 135
Intel mcs-48 manual Application Examples Binary Multiply, Interrupt Handling