BINARY TO BCD CODE CONVERTION
AIM:
To write a assembly language program to perform binary to BCD code
convertion .
ALGORITHM:
Step 1: Start the program.
Step 2: Initialize DS using AX.
Step 3: Load address of input string N01 into SI.
Step 4: Load address of output array D1 into DI.
Step 5: Set CX = 04H to process four groups.
Step 6: Label TOP to process each 4-bit group.
Step 7: Clear BX register (BX = 0000H).
Step 8: Load a byte from memory into AX and rotate right; if carry = 1, add 8 to BX.
Step 9: Increment SI, load next byte, rotate right; if carry = 1, add 4 to BX.
Step 10: Increment SI, load next byte, rotate right; if carry = 1, add 2 to BX.
Step 11: Increment SI, load next byte, rotate right; if carry = 1, add 1 to BX.
Step 12: Store BX into memory location pointed by DI.
Step 13: Increment DI and SI, decrement CX; if CX ≠ 0, repeat from TOP.
Step 14: Terminate the program.
PROGRAM:
DATA SEGMENT
N0 1 DB “1001000000110110”
D1 DW 4 DUP(?)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START:
MOV AX,DATA
MOV DS,AX
LEA SI,N01
LEA DI,D1
MOV CX,04H
TOP:
MOV BX,00H
MOV AX,[SI]
ROR AX,1
JNC P2
ADD BX,08H
P2:
INC SI
MOV AX,[SI]
ROR AX,1
JNC P3
ADD BX,04H
P3:
INC SI
MOV AX,[SI]
ROR AX,1
JNC P4
ADD BX,02H
P4:
INC SI
MOV AX,[SI]
ROR AX,1
JNC P5
ADD BX,01H
P5:
MOV [DI], BX
INC DI
INC SI
DEC CX
JNZ TOP
MOV AH,4CH
INT 21H
CODE ENDS
END START
FLOWCHART:
START
Initialize data segment register
Load address of input into SI and output into DI
Set CX = 4
GO TO TOP
Clear BX register
Read byte and rotate right
No
CF = 1
Yes
Add eight to BX
Increment SI
Read byte and rotate right
No
CF = 1
Yes
Add four to BX
Increment SI
Read byte and rotate right
No
CF = 1
yes
Add two to BX
Increment SI
Read byte and rotate right
No
CF = 1
Yes
Add one to BX
Store result in memory
Increments DI
DECREMENT CX BY ONE
No
CX ≠ 0
Yes
Top
STOP
MEMORY MNEMONICS OPERAND OPCODE COMMANDS
ADDRESS
8000 MOV AX,DATA B8 LOAD DATA SEGMENT ADDRESS INTO
AX
8001 00
8002 00
8003 MOV DS,AX 8E INTIALIZE DS REGISTER
8004 D8
8005 LEA SI,N01 8D LOAD ADDRESS OF INPUT STRING
INTO SI
8006 36
8007 00
8008 00
8009 LEA DI,D1 8D LOAD ADDRESS OF OUTPUT ARRAY
INTO DI
800A 3E
800B 10
800C 00
800D MOV CX,0004H B9 SET LOOP COUNTER 4
800E 04
800F 00
8010 TOP: MOV BX,0000 BB CLEAR BX FOR RESULT
8011 00
8012 00
8013 MOV AX,[SI] 8B LOAD DATA FROM MEMORY INTO AX
8014 04
8015 ROR AX,1 D1 ROTATE RIGHT ,LSB→CARRY FLAG
8016 C8
8017 JNC P2 73 JUMP IF CARRY =0
8018 03
8019 ADD BX,08 83 ADD WEIGHT 8 IF BIT=1
801A C3
801B 08
801C P2: INC SI 46 INCREMENT SI
801D MOV AX,[SI] 8B LOAD NEXT DATA FROM MEMORY TO
AX
801E 04
801F ROR AX,1 D1 ROTATE RIGHT
8020 C8
8021 JNC P3 73 SKIP IF BIT=0
8022 03
8023 ADD BX,04 83 ADD WEIGHT 4
8024 C3
8025 04
8026 P3: INC SI 46 INCREMENT SI
8027 MOV AX,[SI] 8B LOAD DATA FROM MEMORY INTO AX
8028 04
8029 ROR AX,1 D1 ROTATE RIGHT
802A C8
802B JNC P4 73 SKIP IF 0
802C 03
802D ADD BX,02 83 ADD WEIGHT 2
802E C3
802F 02
8030 P4: INC SI 46 INCREMENT SI
8031 MOV AX,[SI] 8B LOAD DATA FROM MEMORY INTO AX
8032 04
8033 ROR AX,1 D1 ROTATE RIGHT
8034 C8
8035 JNC P5 73 SKIP IF 0
8036 03
8037 ADD BX,01 83 ADD WEIGHT 1
8038 C3
8039 01
803A P5: MOV [DI],BX 89 STORE RESULT IN OUTPUT LOCATION
803B 1D
803C INC DI 47 INCREMENT DI
803D INC SI 46 INCREMENT SI
803E DEC CX 49 DECREMENT CX
803F JNZ TOP 75 REPEAT LOOP IF CX IS NOT EQUAL TO
0
8040 CF
8041 MOV AH,4CH B4 PREPARE DOS EXIT FUNCTION
8042 4C
8043 INT 21H CD TERMINATE PROGRAM
8044 21
OUTPUT VERIFICATION:
INPUT:
N01 DB “1001000000110110
OUTPUT:
DS:0009→09
DS:000A→00
DS:000B→03
DS:000C→06
RESULTS:
Thus, the program for finding binary to BCD code conversion
has been implemented and the output is verified successfully.
BCD TO BINARY CODE CONVERTION
AIM:
To write an assembly language program to perform BCD to binary code
convertion.
APPARATUS REQUIRED:
8086 Microprocessor kit.
ALGORITHM:
1. Start the program.
2. Initialize the data segment by loading its address into AX and moving AX into DS
register.
3. Load the offset address of input string NO1 into SI register.
4. Load the offset address of output array D1 into DI register.
5. Initialize CX register with 04H to process four characters.
6. Load one ASCII character from memory pointed by SI into AL register and clear
AH register to form AX.
7. Initialize DX register with 0CH to control the loop for bit extraction/rotation.
8. Rotate AX left by one bit and check the carry flag.
9. If carry flag is set, store 1 at memory location pointed by DI; otherwise store 0.
10. Increment DI to store the next bit.
11. Decrement DX and repeat steps 8–10 until DX become 0.
12. Increment SI to move to the next character.
13. Decrement CX and repeat steps 6–12 until all four characters are processed.
14. Move AH = 4CH and terminate the program using INT 21H.
15. End the program.
FLOWCHART: START
Initialize DS by loading DATA address into AX and moving AX into DS
Load SI with address of NO1, DI with address of D1, and initialize CX = 04H
Load one ASCII character from NO1 into AL register and clear AH to form
AX
Set DX = 04H for bit extraction loop
Rotate AX left by 1 bit, check Carry Flag, and store result
No IF CF=1
Yes
Store 1 at the memory location pointed by DI
ELSE ,Store 0 at the memory location pointed by DI
Increment DI
Decrement DX
YES
IF DX ≠ 0
NO
Increment SI
Decrement CX
YES
IF CX ≠ 0
NO
Move AH = 4CH and terminate program using INT 21H
STOP
PROGRAM:
DATA SEGMENT
NO1 DB “9036”
D2 DB ?
D1 DB 16 DUP(?)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
LEA SI, NO1
LEA DI,D1
MOV CX, 04H
TOP:
MOV AL, [SI]
MOV DX, 0CH
UP1:
ROL AX,1
DEC DX
JNZ UP1
AND AX, 1111000000000000B
MOV DX,04H
UP2:
ROL AX,1
JNC DN
MOV BX,1
MOV [DI],BX
JMP DN2
DN:
MOV BX,0
MOV [DI],BX
DN2:
INC DI
DEC DX
JNZ UP2
INC SI
DEC CX
JNZ TOP
INT 21H
CODE ENDS
END START
MEMORY MNEMONICS OPERAND OPCODE COMMANDS
ADDRESS
8000 MOV AX,DATA B8 Load data segment address into AX
8001 00
8002 00
8003 MOV DS,AX 8E Initialize DS register with data segment
8004 D8
8005 LEA SI,N01 8D Load address of input string (N01)into
SI
8006 36
8007 00
8008 00
8009 LEA DI,D1 8D Load address of output array (D1)into
DI
800A 3E
800B 05
800C 00
800D MOV CX,0004H B9 Set loop counter into 04H
800E 04
800F 00
8010 MOV AL,[SI] 8A LOAD ONE ASCII DIGIT
8011 04
8012 MOV DX,000CH BA Set counter =12
8013 0C
8014 00
8015 ROL AX,1 D1 ROTATE AX LEFT
8016 C0
8017 DEC DX 4A DECREMENT DX
8018 JNZ UP1 75 REPEAT UNTIL DX=0
8019 FB
801A AND AX,F000H 25 EXTRACT UPPER 4 BITS
801B 00
801C F0
801D MOV DX,0004H BA SET BIT COUNTER
801E 04
801F 00
8020 ROL AX,1 D1 SHIFT NEXT BIT
8021 C0
8022 JNC DN 73 IF CARRY=0 ,GO TO DN
8023 05
8024 MOV BX,0001H BB STORE 1
8025 01
8026 00
8027 MOV [DI],BX 89 SAVE 1 IN MEMORY
8028 1D
8029 JMP DN2 EB JUMP TO DN2
802A 05
802B MOV BX,0000H BB STORE 0
802C 00
802D 00
802E MOV [DI],BX 89 SAVE 0
802F 1D
8030 INC DI 47 INCREMENT DI
8031 DEC DX 4A DECREMENT DX
8032 JNZ UP2 75 REPEAT FOR 4 BITS
8033 EC
8034 INC SI 46 INCREMENT SI
8035 DEC CX 49 DECREMENT CX
8036 JNZ TOP 75 REPEAT FOR ALL DIGITS
8037 D8
8038 MOV AH,4CH B4 DOS TERMINATE FUNCTION
8039 4C
803A INT 21H CD INTERRUPT CALL
803B 21
OUTPUT VERIFICATION:
INPUT:
N01=”9036”
OUTPUT:
DS:0005 → 1
DS:0006 →0
DS:0007 →0
DS:0008 →1
DS:0009 →0
DS:000A →0
DS:000B →0
DS:000C →0
DS:000D →0
DS:000E →0
DS:000F →1
DS:0010 →1
DS:0011 →0
DS:0012 →1
DS:0013 →1
DS:0014 →0
RESULTS:
Thus ,the program for finding BCD to binary code conversion has been
implemented and the output is verified successfully.
STRING DISPLAY
AIM:
To write an 8086 assembly language program to display a
string on the screen using DOS interrupt.
APPARATUS REQUIRED:
8086 microprocessor kit.
ALGORITHM:
1. Start the program.
2. Define the data segment and store the message string (terminated
with $).
3. Initialize the data segment by moving its address into AX and then
into DS.
4. Load function number 09H into AH to display the string.
5. Load the offset address of the message into DX.
6. Call interrupt 21H to display the string on the screen.
7. Load function number 4CH into AH to terminate the program.
8. Call interrupt 21H to return control to the operating system.
9. Stop the program.
PROGRAM:
DATA SEGMENT
MSG DB 0DH,0AH,"WELCOME TO MICROPROCESSOR LAB$"
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AH, 09H
MOV DX, OFFSET MSG
INT 21H
MOV AH, 4CH
INT 21H
CODE ENDS
END START
FLOWCHART:
START
Initialize data segment by moving DATA into DS
Load 09H into AH to select string display function
Load offset address of MSG into DX register
Call INT 21H to display the string on the screen
Load 4CH into AH to select program termination function
Call INT 21H to terminate the program
STOP
MEMORY MNEMONICS OPERAND OPCODE COMMANDS
ADDRESS
8000 MOV AX,DATA B8 LOAD DATA SEGMENT ADDRESS INTO
AX
8001 00
8002 00
8003 MOV DS,AX 8E INTIALIZE DS WITH DATA SEGMENT
8004 D8
8005 MOV AH,09H B4 SELECT STRING DISPLAY FUNCTION
8006 09
8007 MOV DX,0000H BA LOAD OFFSET OF MSG INTO DX
8008 00
8009 00
800A INT 21H CD CALL DOS INTERRUPT TO DISPLAY
STRING
800B 21
800C MOV AH,4CH B4 SELECT TERMINATE FUNCTION
800D 4C
800E INT 21H CD RETURN CONTROL TO DOS
800F 21
OUTPUT VERIFICATION:
OUTPUT:
WELCOME TO MICROPROCESSOR LAB.
RESULTS:
This is an 8086 assembley language program to display an string
on the screen using DOS interrupt.