2. Code conversion allows user to translate a number that is representated
using one coding system to other coding system.
The code conversion involves operations like :
1) Binary to BCD
2) BCD to Binary
3) BCD to Hex
4) Hex to BCD
5) BCD to Seven Segment
6) Binary to ASCII
7) ASCII to Binary
3. The microprocessor understands the binary/hex number
system. To convert BCD number into its binary equivalent
we need to use the principle of positional weighting in a
given number.
EXAMPLE : (2 Digit BCD to Binary)
60 = 6 x 0A H + 0
60 = 3C H + 0
60 = 3C H
4. LDA 2200H : Get the BCD number
MOV B, A : Save it
ANI OFH : Mask most significant four bits
MOV C, A : Save unpacked BCD 1 in C register
MOV A, B : Get BCD again
ANI FOH : Mask least significant four bits
RRC : Convert most significant four bits into unpacked BCD 2
RRC
RRC
RRC
MOV B, A : Save unpacked BCD 2 in B register
XRA A : Clear accumulator (sum = 0)
MVI D, 0AH : Set D as a multiplier of 10
SUM:ADD D : Add 10 until (B) = 0
DCR B : Decrement BCD2 by one
JNZ SUM : Is multiplication complete? If not, go back and add again
ADD C : Add BCD 1
STA 2300H : Store the result
HLT : Terminate program execution
INPUT :
2200 H : 60 H
OUTPUT :
2300 H : 3C H
5. The microprocessor processes data in binary
form but data that is displayed is in BCD form.
Hence, we require to convert the Binary data
to BCD.
The series of operations to be performed is
represented here using a flowchart.
6. Source Program:
LXI SP, 27FFH : Initialize stack pointer
LDA 6000H : Get the binary number in accumulator
CALL SUBROUTINE : Call subroutine
HLT : Terminate program execution
Subroutine to convert binary number into its equivalent BCD number:
PUSH B : Save BC register pair contents
PUSH D : Save DE register pair contents
MVI B, 64H : Load divisor decimal 100 in B register
MVI C, 0AH : Load divisor decimal 10 in C register
MVI D, 00H : Initialize Digit 1
MVI E, 00H : Initialize Digit 2
7. STEP1:CMP B : Check if number < Decimal 100
JC STEP 2 : if yes go to step 2
SUB B : Subtract decimal 100
INR E : update quotient
JMP STEP 1 : go to step 1
STEP2:CMP C : Check if number < Decimal 10
JC STEP 3 : if yes go to step 3
SUB C : Subtract decimal 10
INR D : Update quotient
JMP STEP 2 : Continue division by 10
STEP3:STA 6100H : Store Digit 0
MOV A, D : Get Digit 1
STA 6101H : Store Digit 1
MOV A, E : Get Digit 2
STA 6102H : Store Digit 2
POP D : Restore DE register pair
POP B : Restore BC register pair
RET : Return to main program
INPUT :
3040 H : 8A H
OUTPUT :
3041 H : 08 H
3042 H : 03 H
3043 H : 01 H
8. The ASCII (American Standard Code
for Information Interchange) is
used for communication purposes.
Hence, it is necessary to convert
Binary number to its ASCII
equivalent.
9. Source program:
LXI SP, 27FFH : Initialize stack pointer
LXI H, 2000H : Source memory pointer
LXI D, 2200H : Destination memory pointer
MVI C, O5H : Initialize the counter
BACK: MOV A, M : Get the number
CALL ASCII : Call subroutine ASCII
STAX D : Store result
INX H : Increment source memory pointer
INX D : Increment destination memory pointer
DCR C : Decrement count by 1
CJNZ : If not zero, repeat
HLT : Stop program execution a
10. Subroutine ASCII:
ASCII:CPI, OAH : Check if number is OAR
JNC NEXT : If yes go to next otherwise continue
ADI 30H
JMP LAST
NEXT:ADI 37H
LAST:RET : Return to main program
INPUT :
(2000H) = 1
(2001H) = 2
(2002H) = 9
(2003H) = A
(2004H) = B
OUTPUT :
(2200H) = 31
(2201H) = 32
(2202H) = 39
(2203H) = 41
(2204H) = 42
11. Steps for ASCII to Binary code conversion :
If ASCII code is less than 3A H then 30 H is subtracted from the number
to get its Binary Equivalent.
If the number is between 41 H and 5A H then 37 H is subtracted to get
the binary equivalent of the letter A-F.
EX:
41 H (ASCII) = 41 H - 37 H
= 04 H (BINARY)
12. Steps for BCD to HEX code conversion :
1) We get the value from the user.
2) Then we take the Most Significant Digit (MSD).
3) We multiply MSD by 10, using repeated addition.
4) Then we add the Least Significant Digit (LSD) to the result obtained
in previous step.
5) And finally the value is stored in the next memory location.
13. LXI H,0030H : Get the BCD number
MOV A,M : Initialize the memory Pointer
ADD A : Value in accumulator is doubled
MOV B,A : Value in accumulator is moved to register B
ADD A : Value in accumulator is doubled again
ADD A : Value in accumulator is doubled again
ADD B : Value in Register B is added to accumulator
(A is 10 x MSD of the BCD stored at 0030H)
INX H : Point to LSD
ADD M : LSD is added to accumulator
INX H Next location is pointed
MOV M,A : Value obtained is stored here
HLT : Terminate the program
INPUT :
0030 H : 02 H
0031 H : 09 H
OUTPUT :
0032 H : 1D H
14. Steps for HEX to BCD code conversion :
1) We get the HEX number from user.
2) Then shift the hexadecimal number to C register.
3) We perform repeated addition for C number of times.
4) And adjust for BCD count in each step.
5) Now the BCD value obtained is stored in memory.
15. LXI H,0030H : Get the HEX number
MOV C,M : Shift the number to C register
LOOP1: ADI 01H : Start a loop of repeated addition for C times
DAA : Adjust for BCD count
JNC LOOP2 : Start another loop for Higher order number
INR D
LOOP2: DCR C : Decrease C till it reaches Zero
JNZ LOOP1
STA 0051H : Store the Lower order here
MOV A,D : Move the Higher order value to accumulator
STA 0050H : Store the Higher order here
HLT
INPUT :
0030 H : 1D H
OUTPUT :
0050 H : 02 H
0051 H : 09 H
16. • The seven segment LCD display is used
for displaying the results in a
microprocessor based system.
• In such cases we need to convert the
results in the seven segment code.
• Such conversion can be obtained with
a look-up table.
0 3F
1 06
2 5B
3 4F
4 66
5 6D
6 7D
7 07
8 7F
9 6F
17. LXI H, 6200H : Initialize lookup table pointer
LXI D, 6000H : Initialize source memory pointer
LXI B, 7000H : Initialize destination memory pointer
BACK: LDAX D : Get the number
MOV L, A : A point to the 7-segment code
MOV A, M : Get the 7-segment code
STAX B : Store the result at destination memory location
INX D : Increment source memory pointer
INX B : Increment destination memory pointer
MOV A, C
CPI O5H : Check for last number
JNZ BACK : If not repeat
HLT : End of program
You can use this slide as your opening or closing slide. Should you choose to use it as a closing, make sure you review the main points of your presentation. One creative way to do that is by adding animations to the various graphics on a slide. This slide has 4 different graphics, and, when you view the slideshow, you will see that you can click to reveal the next graphic. Similarly, as you review the main topics in your presentation, you may want each point to show up when you are addressing that topic.
Add animation to images and graphics:
Select your image or graphic.
Click on the Animations tab.
Choose from the options. The animation for this slide is “Split”. The drop-down menu in the Animation section gives even more animations you can use.
If you have multiple graphics or images, you will see a number appear next to it that notes the order of the animations.
Note: You will want to choose the animations carefully. You do not want to make your audience dizzy from your presentation.