Anda di halaman 1dari 8

CODE CONVERSIONS

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

Initialize stack pointer

4103

21, 00, 42

LXI H, 4200

Initialize HL register pair


with a source pointer

4106

01,00,43

LXI B 4300

4109
410A

7E
CD, 0F,41

MOV A,M
CALL BCD
BIN

Load BC register pair with


destination pointer
Move [M] to Accumulator
Call sub routine BCD BIN

410D

02

STAX B

Store the Binary number in


the destination location

410E

76

HLT

End of execution

SUBROUTINE
Memory
Location

Machine code

Label

Mnemonics

Comment

410F

C5

BCD
BIN

PUSH B

Push [B C ] into stack pointer

4110

05

PUSH D

Push [D E] into stack pointer

4111
4112

47
E6,0F

MOV B,A
ANI 0F

4114

4F

MOV C,A

Move [A] to B register


And immediate the
accumulator with 0F
Move[A] to C register

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

And immediate accumulator


with F0
Jump on zero to BCD loop
Rotate accumulator content to
right through carry
Rotate accumulator content to
right through carry

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

Rotate accumulator content to


right through carry
Rotate accumulator content to
right through carry
Move [A] to D register
Clear accumulator
Move 0A to E register
Add E with accumulator
content
Decrement D register.
Jump on no zero to sum
Add [C] to accumulator
Retrieve the content of D
from stack
Retrieve the content of B
from stack
Return to main program

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

Initialize stack pointer

4103

21, 00, 42

LXI H,4200

Initialize HL register pair


with a source pointer

4106
4107

7E
CD, 0B,41

Move [M] to Accumulator


Call sub routine PWRTEN

410A

76

MOV A,M
CALL
PWRTEN
HLT

End the execution

Subroutine 1
Memory
Location

Machine code

Label

Mnemonics

Comment

410B

21,00,43

PWRTEN LXIH, 4300

410E

06,64

MVI B,64

Move 64h to B register

4110

CD,1A,41

Call subroutine BIN BCD

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

Return to main program

Load HL register pair with


4300

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

Move FFh to memory


location

411C

34

NXTBOF INR M

411D
411E

90
D2, 1C, 41

SUB B
JNC NXT

Increment memory pointer


Subtract B from accumulator
Jump on no carry to NXT

4121

80

BUF
ADD B

4122

23

INX H

Increment memory pointer

RET

Return to main program

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

Initialize stack pointer

4103

21, 00, 42

LXI H,4200

Initialize HL register pair


with a source pointer

4106

11,00,43

LXI D 4300

4109
410A

7E
47

MOV A,M
MOV B,A

Initialize DE reg pair with


destination pointer
Move M to accumulator
Move A to B register

410B

0F

RRC

Rotate the accumulator


content to right

410C

0F

RRC

Rotate the accumulator


content to right

410D

0F

RRC

Rotate the accumulator


content to right

410E

0F

RRC

Rotate the accumulator


content to right

410F

CD,1A,41

CALL SUB

Call subroutine SUB

4112

12

STAX D

Store the first ASCII value in


4300

4113

13

INX D

Increment memory pointer

4114

78

MOV A,B

Move B to accumulator

4115

CD,1A, 41

CALL SUB

Call subroutine SUB

4118

12

STAX D

Store the second ASCII value


in 4301

4119

76

HLT

End of execution

SUBROUTINE
Memory
Location

Machine code

Label

Mnemonics

Comment

411A

E6,0F

SUB

ANI 0F

Mask higher order nibble

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

Jump on carry loop


Add immediately 07
Add immediately 30 with
accumulator

4125

C9

RET

Return to main program

Loop

d. ASCII to Binary
ALGORITHM:

Initialize stack pointer


Initialize register pair as source pointer
Initialize DE register pair with destination pointer
Move contents of memory pointer to accumulator
Call subroutine
Store the result in destination address
End of execution
SUBROUTINE

Subtract 30h from accumulator


If the result is less that 10, return to main program
Else subtract 07h from the result
Return to main program

Memory
Location

Machine code

4100

Label

Mnemonics

Comment

31,FF,4F

LXI SP,
4FFF

Initialize stack pointer

4103

21, 00, 42

LXI H,4200

Initialize HL register pair


with a source pointer

4106

11,00,43

LXI D 4300

4109
410A

7E
CD,0F,41

MOV A,M
CALL SUB

Initialize DE reg pair with


destination pointer
Move M to accumulator
Call subroutine SUB

410D

12

STAX D

Store the result in 4300

410E

76

HLT

End of execution

Mnemonics

Comment

SUBROUTINE
Memory
Location

Machine code

Label

410F

D6,30

4111

SUB

SUI

Subtract 30h from


accumulator

FE,0A

CPI 0A

Compare 0A with
accumulator content

4113

D8

RC

4114
4123

D6,07
C6,30

ADI 07
SUI 07

Move the smallest number to


memory location
Add immediately 07
Subtract 07 from the
accumulator

4116

C9

RET

Return to main program

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.

Anda mungkin juga menyukai