AIM:
To write an 8085 assembly language program that executes the following
conversions
i)
BCD TO BINARY.
ii)
Binary to BCD
iii)
Binary to ASCII
iv)
ASCII to Binary
APPARATUS REQUIRED:
8085 microprocessor kit, Power supply.
ALGORITHM:
BCD TO BINARY:
Step 1: Initialize stack pointer
Step 2: Initialize HL register pair with a source pointer.
Step 2: Initialize BC register pair with a destination pointer.
Step 3: Move contents of memory pointer to accumulator.
Step 4: Call subroutine BCD BIN.
Step 5: Store the content of Accumulator in destination.
Step 6: End of execution.
SUBROUTINE:
1. Push the content of BC & DE register pair to stack pointer.
2. Logically AND the number 0F with accumulator to get LSB
3. Again logically AND the number F0with accumulator and rotate the content to the
right four times to get MSB
4. Multiply the MSB with 0A and add with LSB
Memory
Location
Machine code
4100
Label
Mnemonics
Comment
31,FF,4F
LXI SP,
4FFF
4103
21, 00, 42
LXI H, 4200
4106
01,00,43
LXI B 4300
4109
410A
7E
CD, 0F,41
MOV A,M
CALL BCD
BIN
410D
02
STAX B
410E
76
HLT
End of execution
SUBROUTINE
Memory
Location
Machine code
Label
Mnemonics
Comment
410F
C5
BCD
BIN
PUSH B
4110
05
PUSH D
4111
4112
47
E6,0F
MOV B,A
ANI 0F
4114
4F
MOV C,A
4115
78
MOV A,B
Move[B] to Accumulator
4116
E6,F0
ANI F0
4118
411B
CA,28,41
0F
JZ BCD
RRC
411C
0F
RRC
411D
0F
RRC
411E
0F
RRC
411F
4120
4121
4123
57
AF
1E, 0A
83
MOV D,A
XRA A
MVI E, 0A
ADD E
4124
4125
4128
4129
15
C2,23,41
81
D1
412A
C1
POP B
412B
C9
RET
SUM
BCD
DCR D
JNZ SUM
ADD C
POP D
b) Binary to BCD:Algorithm:
Step 1: Initialize stack pointer
Step 2: Initialize the register pair as memory pointer.
Step 3: Move Binary number to accumulator
Step 4: Call subroutine 1
Step 5:End of the execution
SUBROUTINE 1:
Step 1: Load HL register pair with MP
Step 2: Store 64h in B register.
Step 3: Call subroutine 2.
Step 4: Store 0Ah in B register & call subroutine2
Step 5: Store accumulator contents in next memory location
Step 6: Return to Main program.
SUB ROUTINE 2:
Step 1: Clear Memory location
Step 2: Subtract the B register from accumulator
Step 3: If the subtraction results a carry add B register content with accumulator and
increment memory pointer.
Memory
Location
Machine code
4100
Label
Mnemonics
Comment
31,FF,4F
LXI SP,
4FFF
4103
21, 00, 42
LXI H,4200
4106
4107
7E
CD, 0B,41
410A
76
MOV A,M
CALL
PWRTEN
HLT
Subroutine 1
Memory
Location
Machine code
Label
Mnemonics
Comment
410B
21,00,43
410E
06,64
MVI B,64
4110
CD,1A,41
4113
4115
06,0A
CD,1A,41
CALL BIN
BCD
MVI B,0A
CALL BIN
BCD
4118
77
MOV M,A
Move[A] to memory
location
4119
C9
RET
Move 0A to B register
Call subroutine BIN BCD
Subroutine 2
Memory
Location
Machine code
Label
Mnemonics
Comment
411A
36,FF
BIN
BCD
MVI M, FF
411C
34
NXTBOF INR M
411D
411E
90
D2, 1C, 41
SUB B
JNC NXT
4121
80
BUF
ADD B
4122
23
INX H
RET
4123
C9
c) Binary to ASCII
BOF
Add the content of B register
with accumulator
ALGORITHM:
Initialize stack pointer
Initialize register pair as source pointer
Initialize DE register pair with destination pointer
Move contents of memory pointer to accumulator
Shift higher order nibble to lower order nibble by rotating the accumulator
contents to right for 4 times
Call subroutine
Store the converted number in memory location 4300 and 4301
End of execution
SUBROUTINE
And immediately the binary data with OFh & mask the higher order bit &
store it in the accumulator.
Compare the accumulator content with 07
If carrt results ad 30h to the number else add 37h to the number
Return to main program
Memory
Location
Machine code
4100
Label
Mnemonics
Comment
31,FF,4F
LXI SP,
4FFF
4103
21, 00, 42
LXI H,4200
4106
11,00,43
LXI D 4300
4109
410A
7E
47
MOV A,M
MOV B,A
410B
0F
RRC
410C
0F
RRC
410D
0F
RRC
410E
0F
RRC
410F
CD,1A,41
CALL SUB
4112
12
STAX D
4113
13
INX D
4114
78
MOV A,B
Move B to accumulator
4115
CD,1A, 41
CALL SUB
4118
12
STAX D
4119
76
HLT
End of execution
SUBROUTINE
Memory
Location
Machine code
Label
Mnemonics
Comment
411A
E6,0F
SUB
ANI 0F
411C
FE,0A
CPI 0A
Compare A with 0A
411E
4121
4123
DA, 23, 41
C6,07
C6,30
JC loop
ADI 07
ADI 30
4125
C9
RET
Loop
d. ASCII to Binary
ALGORITHM:
Memory
Location
Machine code
4100
Label
Mnemonics
Comment
31,FF,4F
LXI SP,
4FFF
4103
21, 00, 42
LXI H,4200
4106
11,00,43
LXI D 4300
4109
410A
7E
CD,0F,41
MOV A,M
CALL SUB
410D
12
STAX D
410E
76
HLT
End of execution
Mnemonics
Comment
SUBROUTINE
Memory
Location
Machine code
Label
410F
D6,30
4111
SUB
SUI
FE,0A
CPI 0A
Compare 0A with
accumulator content
4113
D8
RC
4114
4123
D6,07
C6,30
ADI 07
SUI 07
4116
C9
RET
Result:
Thus the assembly language program for code conversion like BCD to binary, Binary to
BCD, Binary to ASCII and ASCII to Binary were performed.