EMAC PRIMER Instruction Manual page 42

Table of Contents

Advertisement

LESSON 11: Division
NEW INSTRUCTIONS
RAR
Shift all the bits in the accumulator one position right and put the carry flag in bit 7 and put the value that
was shifted out of bit 0 into the carry flag. Only the carry flag is affected.
MOV
A,D
The contents of the D register are copied to register A. No flags are affected.
MOV
D,A
The contents of the A register are copied to register D. No flags are affected.
MOV
A,E
The contents of the E register are copied to register A. No flags are affected.
MOV
E,A
The contents of the A register are copied to register E. No flags are affected.
Just as shifting a number to the right is the same as multiplying it by its base, shifting a number to the left is the same as
dividing the number by its base. This allows the 8085 to perform division by 2 by shifting a binary number to the right.
When division is done this way, the remainder will be the bit shifted out of the lowest bit position. The following program
divides the number in DE by two, leaving the quotient in DE and the remainder in the carry flag.
org
loop:
mov
ora
rar
mov
mov
rar
mov
rst
end
ADDRESS
FF01
FF02
FF03
FF04
FF05
FF06
FF07
FF08
Load the program into memory, load the DE register pair with 0007 hex and then run the program. You will see that DE is
now 3 and if you examine the A.F. register you will see that the carry flag is 1 which indicates a remainder of 1. Try other
values of DE and verify that the program actually does divide the DE register by 2.
In the lesson "Using Monitor Operating System Subroutines" is a description of a division service which divides a value in
the HL register pair by the value in the DE register pair.
op code = 1F
op code = 7A
op code = 57
op code = 7B
op code = 5F
0ff01h
a,d
; load A with high byte first
a
; clear the carry flag (cy=0)
; rotate right through carry
d,a
; store in D
a,e
; load A with low byte
; whatever was shifted out of bit 0 in the last RAR will be put
; in the CY flag which is shifted into bit 7 in this RAR
e,a
; store in E
7
; return to MOS
DATA
INSTRUCTION
7A
MOV
A,D
B7
ORA
A
1F
RAR
57
MOV
D,A
7B
MOV
A,E
1F
RAR
5F
MOV
E,A
FF
RST
7
42

Advertisement

Table of Contents
loading

Table of Contents