Вы находитесь на странице: 1из 4

VYSYA COLLEGE, SALEM-103

SUBJECT: DCF & MICROPROCESSOR UNIT: IV


CLASS: I BSC CS DATE: 08.10.13
CODE CONVERSION
In the microprocessor, data processing is usually performed in binary, but in some cases arithmetic operations
are performed in BCD numbers. Therefore the data must be converted from one code to another code.
The programming techniques used for code conversion fall into four general categories:
1. Conversion based on the position of a digit in a number (BCD to binary and Vice Versa).
2. Code conversion based on hardware consideration (Binary to 7 Segment code).
3. Code conversion based on sequential order of digits (Binary to ASCII and Vice versa)
4. Decimal adjustment in BCD arithmetic operations.
BCD TO BINARY CONVERSION:
In most microprocessor-based products, data are entered and displayed in decimal numbers. For example in
instrumentation laboratory, reading such as voltage and current are maintained in decimal numbers, and data are
entered through a decimal keyboard.
The system monitor program of the instrument converts each key into an equivalent 4-bit binary numbers and
store two BCD numbers in an 8-bit register or memory location. These numbers called packed BCD. The conversion
of a BCD number into its binary equivalent employs the principle of positional weighting in a given number.
For example: 7210=7x10 +2
The digit 7 represents 70, based on its second position from the right. Therefore converting 72 BCD into its
binary equivalent requires multiplying the second digit by 10 and adding the first digit.
Process:
Converting a two digit BCD number into its binary equivalent requires the following steps:
1. Separate an 8-bit packed BCD number into two 4-bit unpacked BCD digits BCD1 and BCD2
2. Convert each digit into its binary value according to its position.
3. Add both binary numbers to obtain the binary equivalent of the BCD number.
Example: Convert 72BCD into its binary equivalent.

7210 = 0111 0010


Step-1: 0111 0010 0000 0010 unpacked BCD1
0000 0111 unpacked BCD2
Step-2: Multiply BCD2 by 10 (7 x 10)
Step-3: Add BCD1 to the answer in step-2.
The multiplication of BCD2 by 10 can be performed by various methods. One method is multiplication with
repeated addition i.e. add 10 seven times.
Example program:
START: LXI SP, STACK
LXI H, INBUF
LXI B, OUTBUF
MOV A, B
CALL BCDBIN
STAX B
HLT
BDCBIN: PUSH B
PUSH D
MOV B, A
ANI 0FH
MOV C, A
MOV A, B
ANI 0FH
JZ BCD1
RRC
RRC
RRC
49
RRC
MOV D, A
XRA A
MVI E, 0AH
SUM: ADD E
DCR D
JNZ SUM
BCD1: ADD C
POP D
POP B
RET
BINARY TO BCD CONVERSION:
The conversion of binary to BCD is performed by dividing the number by powers of 10. The division is done by
subtraction method. Assume the binary number as 1111 11112=25510. The equivalent BCD number is
0010 0101 0101
BCD3 BCD2 BCD1
The conversion steps are as follows:
Step1: If the number is less than 100, go to step 2; otherwise divide by 100. i.e., subtract 100 repeatedly until the
remainder is less than 100. The quotient is the most significant BCD digit, BCD3.
Step 2: If the number is less than 10, go to step3. Otherwise divide by 10 repeatedly until the remainder is less
than 10. The quotient is BCD2.
Step 3: The remainder from step 2 is BCD1.
55
- 100 = 155
-------------- Step-1
- 100 = 55
Quotient = 2  BCD3
55
- 10 = 45
- 10 = 35
- 10 = 25 Step2
- 10 = 15
- 10 = 5
Quotient = 5 = BCD2
BCD1 = 5 Step-3
BCD TO 7 SEGMENT LED CODE CONVERSION:
1. When a BCD number is to be displayed, by a seven-segment LED, it is necessary to convert the BCD
number to its 7 segment code.
2. A seven segment LED consists of seven light-emitting diode segments and one segment for the decimal point. To
display a number, the necessary segments are lit by sending an appropriate signal for current flow through diodes.
3. The code is determined by hardware consideration such as common-cathode or common-anode LED; the code
has no direct relationship to binary numbers.
4. To display a BCD digit at a seven-segment LED, table look-up technique is used.
5. In the table look-up technique, the codes of digits to be displayed are stored sequentially in memory.
6. The conversion program locates the code of a digit based on its magnitude and transfers.
7. The code to the MPU to send out to a display part.
Example:
LXI SP, STACK
LXI H, XX50H
MVI D, 03H
CALL UNPAK
HLT

UNPAK: LXI B, BUFFER


50
MOV A, M
ANI F0H
RRC
RRC
RRC
RRC
CALL LEDCOD
INX B
MOV A, B
ANI 0FH
CALL LEDCOD
INX B
INX H
DCR D
JNZ NXTBCD
RET

LEDCOD: PUSH H
LXI H, CODE
ADD L
MOV L, A
MOV A, M
STAX B
POP H
RET

CODE: 3F
06
5B
4F
66
6D
7D
07
7F
6F
00
BINARY TO ASCII AND ASCII TO BINARY CODE CONVERSION:
The American Standard Code for Information Interchange (ASCII) is used commonly in data communication.
It is a seven-bit code and its 128 combinations are assigned different alphanumeric characters. The ASCII keyboard
is a standard input device for entering programs in a microcomputer. When an ASCII character is entered, the
microprocessor receives the binary equivalent of the ASCII hex number, For example, when the ASCII key for digit 9
is pressed, the microprocessor receives the binary equivalent of 39H which must be converted to binary 1001 for
arithmetic operations. Similarly, to display a digit 9 at the terminal, the microprocessor must send out the ASCII hex
code (39H). These conversions are done through software.
Binary to ASCII hex code conversion.
LXI SP, STACK
LXI H, XX50H
LXI D, XX60H
MOV A, M
MOV B, A
RRC
RRC
RRC
RRC
51
CALL LOOP
STAX D
INX D
MOV A, B
CALL LOOP
STAX D
HLT
LOOP: ANI 0FH
CPI 0AH
JC CODE
ADI 07H
CODE: ADI 30H
RET
ASCII Hex to binary conversion:
To convert an ASCII Hex number into its binary equivalent, a calling program places the ASCII number in the
accumulator, and the subroutine should pass the conversion back to the accumulator.
Example:
ASCBIN : SUI 30H
CPI 0AH
RC
SUI 07H
RET
BCD ARITHMETIC OPERATIONS
BCD ADDITION:
The addition of two BCD numbers may not represent an appropriate BCD value. The microprocessor cannot
recognize BCD numbers. It adds any two numbers in binary. In BCD addition, any number larger than 9 is invalid
and needs to be adjusted by adding 6 in binary.

DAA
A special instruction called DAA (Decimal Adjust Accumulator) performs the function of adjusting a BCD
sum in the 8085 instruction set. This instruction uses the Auxiliary Carry flip-flop to sense that the value of the least
four bits is larger than 9 and adjusts the bits to the BCD value. Similarly, it uses the Carry flag to adjust the most
significant four bits.

BCD SUBTRACTION:
Two BCD numbers can be subtracted by using the procedure of 100’s complement, similar to 2’s complement.
The 100’s complement of a subtrahend can be added to a minuend. For example, 82-48=34 can be performed as
follows:
100’s complement of subtrahend 52 (100-48)
Add minuend +82
------------
134  The sum is 34 and carry is ignored.
------------

~~~~~~~~~~ UNIT V COMPLETED ~~~~~~~~~~

52

Вам также может понравиться