5. 8086
5. 8086 Assembly Language Programm
Assembly Language Programming
ing
24 Marks 24 Marks Syllabus:
Syllabus: 5.1
5.1 Model Model of of 8086 8086 assembly assembly language language programs.programs. 5.2
5.2 Programming using assemblerProgramming using assembler – –
Arithmetic operations on Hex and BCD numbers - Addition, Subtraction, Multiplication andArithmetic operations on Hex and BCD numbers - Addition, Subtraction, Multiplication and
Division Division
Sum of SeriesSum of Series
Smallest and Largest numbers from arraySmallest and Largest numbers from array
Sorting numbers in Ascending and Descending orderSorting numbers in Ascending and Descending order
Finding ODD/EVEN numbers in the arrayFinding ODD/EVEN numbers in the array
Finding Positive and Negative Numbers in arrayFinding Positive and Negative Numbers in array
Block transferBlock transfer
String Operations - Length, Reverse, String Operations - Length, Reverse, Compare, Concatenation, CopyCompare, Concatenation, Copy
Count Numbers of ‘1’ and ‘0’ in 8/16 bit Count Numbers of ‘1’ and ‘0’ in 8/16 bit number number
BCD to Hex and Hex to BCD to Hex and Hex to BCD number conversionBCD number conversion
Model of assembly language programming: Model of assembly language programming:
The general structure of assembly language program of 8086 microprocessor is given below. In the The general structure of assembly language program of 8086 microprocessor is given below. In the structure only data and code segments are shown. If required, other logical segments can be defined in structure only data and code segments are shown. If required, other logical segments can be defined in the same way.
the same way.
;Comments ;Comments ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA DATA SEGMENT
DATA SEGMENT ;
;
;program data declaration here ;program data declaration here ; ; DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, DATAAX, DATA MOV
MOV DS, DS, AXAX ;
;
;program code here ;program code here ;
; MOV
MOV AH, AH, 4CH4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START
Sample programs: Sample programs:
In this section some programming examples are given. No algorithm or flow chart is provided. Try out In this section some programming examples are given. No algorithm or flow chart is provided. Try out to draw flow chart and write algorithm for the given programs. For more examples, you can refer the to draw flow chart and write algorithm for the given programs. For more examples, you can refer the MSBTE manual for MAP subject. Also, good examples are given in following books:
MSBTE manual for MAP subject. Also, good examples are given in following books:
1. Microprocessor & interfacing (programming & hardware) BY Douglas V-Hall 1. Microprocessor & interfacing (programming & hardware) BY Douglas V-Hall
Tata McGraw Hill Tata McGraw Hill 2.
2. Advanced microprocessor & peripheral BY Advanced microprocessor & peripheral BY A.K. Ray & A.K. Ray & K.M. BhurchandiK.M. Bhurchandi
Tata McGraw Hill Tata McGraw Hill
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;
;Program to add two 32-bit numbers ;Program to add two 32-bit numbers ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA
INC BX INC BX MOV AX, [BX] MOV AX, [BX] LEA BX, NUM2 LEA BX, NUM2 INC BX INC BX INC BX INC BX MOV DX, [BX] MOV DX, [BX] D D T T SEGMENTSEGMENT NUM1 NUM1 DD DD 12345678H12345678H NUM2 NUM2 DD DD 87654321H87654321H RESULT RESULT DD DD ?? DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX LEA BX, NUM1 LEA BX, NUM1 MOV AX, [BX] MOV AX, [BX] LEA BX, NUM2 LEA BX, NUM2 MOV DX, [BX] MOV DX, [BX] DD DD AX, DX AX, DX LEA BX, RESULT LEA BX, RESULT MOV [BX], AX MOV [BX], AX LEA BX, NUM1 LEA BX, NUM1 INC BX INC BX DC DC AX, DX AX, DX LEA BX, RESULT LEA BX, RESULT INC BX INC BX INC BX INC BX MOV [BX], AX MOV [BX], AX MOV AH, 4CH MOV AH, 4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;
;Program to subtract two 32-bit numbers ;Program to subtract two 32-bit numbers ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA
RESULT RESULT DD DD ?? DATA ENDS DATA ENDS INC BX INC BX INC BX INC BX MOV [BX], AX MOV [BX], AX MOV AH, 4CH MOV AH, 4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to add data bytes of one array wit
;Program to add data bytes of one array with data bytes of secondh data bytes of second ;array and store result in third array
;array and store result in third array ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA
;
; set set 3 3 pointers pointers for for arraysarrays ; ; countcount MOV [BX], AL MOV [BX], AL D D T T SEGMENTSEGMENT NUM1 NUM1 DD DD 87654321H87654321H NUM2 NUM2 DD DD 12345678H12345678H CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX LEA BX, NUM1 LEA BX, NUM1 MOV AX, [BX] MOV AX, [BX] LEA BX, NUM2 LEA BX, NUM2 MOV DX, [BX] MOV DX, [BX] SUB SUB AX, DX AX, DX LEA BX, RESULT LEA BX, RESULT MOV [BX], AX MOV [BX], AX LEA BX, NUM1 LEA BX, NUM1 INC BX INC BX INC BX INC BX MOV AX, [BX] MOV AX, [BX] LEA BX, NUM2 LEA BX, NUM2 INC BX INC BX INC BX INC BX MOV DX, [BX] MOV DX, [BX] SBB SBB AX, DX AX, DX LEA BX, RESULT LEA BX, RESULT D D T T SEGMENTSEGMENT ARRAY1 ARRAY1 DB DB 01H, 01H, 02H, 02H, 03H, 03H, 04H, 04H, 05H, 05H, 06H, 06H, 07H07H ARRAY2 ARRAY2 DB DB 10H, 10H, 20H, 20H, 30H, 30H, 40H, 40H, 50H, 50H, 60H, 60H, 70H70H ARRAY3 ARRAY3 DB DB ?? DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX LEA
LEA SI, SI, ARRAY1 ARRAY1 LEA DI, ARRAY2 LEA DI, ARRAY2 LEA BX, ARRAY3 LEA BX, ARRAY3 MOV
MOV CL, CL, 07H 07H UP:
UP: MOV MOV AL, AL, [SI][SI] ADD AL, [DI] ADD AL, [DI]
INC
INC SI SI ; ; increment increment pointerspointers INC DI INC DI INC BX INC BX DEC CL DEC CL JNZ UP JNZ UP MOV AH, 4CH MOV AH, 4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to find area and perimeter of rectangle ;Program to find area and perimeter of rectangle ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA
;
; result result will will be be 16-bit16-bit
MOV AL, HEIGHT MOV AL, HEIGHT MOV BL, WIDTH MOV BL, WIDTH ADD
ADD AL, AL, BL BL ; ; AL AL = = AL AL + + BLBL MOV BL, 02H
MOV BL, 02H MUL
MUL BL BL ; AL ; AL = = 02H 02H x x ALAL MOV
MOV PERIM, PERIM, AX AX ; ; store store perimeterperimeter MOV AH, 4CH MOV AH, 4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to multiply two 16-bit ;Program to multiply two 16-bit ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA
;
; result result will will be be 32-bit32-bit
;
; clear clear DXDX ;
; get get first first no. no. in in AXAX ;
; get get second second no. no. in in BXBX D D T T SEGMENTSEGMENT HEIGHT HEIGHT DB DB 15H15H WIDTH WIDTH DB DB 25H25H AREA AREA PERIM PERIM DWDW ? DWDW ? ?? DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX
MOV AL, HEIGHT ; get HEIGHT in AL MOV AL, HEIGHT ; get HEIGHT in AL MOV
MOV BL, BL, WIDTH WIDTH ; ; get get WIDTH WIDTH in in BLBL ;
; Area Area = = HEIGHT HEIGHT x x WIDTHWIDTH ;
; store store AREAAREA ; ; ; perimeter=2(height+width) ; perimeter=2(height+width) MUL MUL BL BL MOV
MOV AREA, AREA, AX AX
signed signed numbers numbers D D T T SEGMENTSEGMENT NUM1 NUM1 DW DW 2001H2001H NUM2 NUM2 DW DW 0004H0004H RESULT RESULT DDDD ? ? DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX MOV
MOV DX, DX, 0000H 0000H MOV
MOV AX, AX, NUM1 NUM1 MOV
MOV BX, BX, NUM2 NUM2 IMUL
IMUL BX BX
LEA DI, RESULT LEA DI, RESULT
MOV
MOV [DI], [DI], AX AX ; ; store store lower lower word word of of resultresult INC DI
INC DI INC DI INC DI MOV
MOV [DI], [DI], DX DX ; ; store store higher higher word word of of resultresult MOV AH, 4CH MOV AH, 4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to divide 32-bit/16-bit ;Program to divide 32-bit/16-bit ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA ;
; 32-bit 32-bit numbernumber ;
; 16-bit 16-bit numbernumber ;
; result result will will be be 16-bit16-bit ;
; remainder remainder will will be be 16-bit16-bit
;
; get get lower lower 16 16 bits bits of of 1st 1st number number in in AXAX ;
; get get higher higher 16 16 bits bits of of 1st 1st number number in in DXDX ;
; get get second second number number in in BXBX ;
; dividedivide
MOV RESULT, AX ; store result MOV RESULT, AX ; store result MOV REMAIN, DX ; store remainder MOV REMAIN, DX ; store remainder MOV
MOV AH, AH, 4CH4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to divide 16-bit/16-bit ;Program to divide 16-bit/16-bit ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA ;
; 16-bit 16-bit numbernumber ;
; 16-bit 16-bit numbernumber ;
; result result will will be be 16-bit16-bit ;
; remainder remainder will will be be 16-bit16-bit
;
; get get 1st 1st number number in in AXAX ;
; Clear Clear DXDX ;
; get get second second number number in in BXBX ; ; dividedivide INT 21H INT 21H signed signed numbers numbers D D T T SEGMENTSEGMENT NUM1 NUM1 DD DD 12345678H 12345678H NUM2 NUM2 DW DW 5678H 5678H RESULT RESULT DW DW ? ? REMAIN REMAIN DW DW ? ? DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX LEA SI, NUM1 LEA SI, NUM1 MOV
MOV AX, AX, [SI] [SI] INC SI
INC SI INC SI INC SI MOV
MOV DX, DX, [SI] [SI] MOV
MOV BX, BX, NUM2 NUM2 IDIV IDIV BX BX unsigned unsigned numbers numbers D D T T SEGMENTSEGMENT NUM1 NUM1 DW DW 1234H 1234H NUM2 NUM2 DW DW 0064H 0064H RESULT RESULT DW DW ? ? REMAIN REMAIN DW DW ? ? DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX MOV
MOV AX, AX, NUM1 NUM1 MOV
MOV DX, DX, 0000H 0000H MOV
MOV BX, BX, NUM2 NUM2 DIV
DIV BX BX
MOV RESULT, AX ; store result MOV RESULT, AX ; store result MOV REMAIN, DX ; store remainder MOV REMAIN, DX ; store remainder MOV
CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to divide 8-bit/8-bit ;Program to divide 8-bit/8-bit ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA ;
; 8-bit 8-bit numbernumber ;
; 8-bit 8-bit numbernumber ;
; result result will will be be 8-bit8-bit ;
; remainder remainder will will be be 8-bit8-bit
;
; get get 1st 1st number number in in ALAL ;
; Clear Clear AHAH ;
; get get second second number number in in BLBL ; ; dividedivide >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to add two BCD numbers ;Program to add two BCD numbers ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA
RESULT, RESULT, ALAL MOV
MOV AH, AH, 4CH4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to subtract two BCD numbers ;Program to subtract two BCD numbers ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA
unsigned unsigned numbers numbers D D T T SEGMENTSEGMENT NUM1 NUM1 DB DB 34H 34H NUM2 NUM2 DB DB 14H 14H RESULT RESULT DB DB ? ? REMAIN REMAIN DB DB ? ? DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX MOV
MOV AL, AL, NUM1 NUM1 MOV
MOV AH, AH, 00H 00H MOV
MOV BL, BL, NUM2 NUM2 DIV
DIV BL BL
MOV RESULT, AL ; store result MOV RESULT, AL ; store result MOV REMAIN, AH ; store remainder MOV REMAIN, AH ; store remainder MOV
MOV AH, AH, 4CH4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START D D T T SEGMENTSEGMENT NUM1 NUM1 DB DB 06H06H NUM2 NUM2 DB DB 04H04H RESULT RESULT DB DB ?? DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX MOV AL, NUM1 MOV AL, NUM1 ADD AL, NUM2 ADD AL, NUM2 MOV
MOV
D
NUM1 NUM1 DB DB 06H06H NUM2 NUM2 DB DB 04H04H RESULT RESULT DB DB ?? DATA ENDS DATA ENDS RESULT, RESULT, ALAL AH, AH, 4CH4CH >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to multiply two BCD numbers ;Program to multiply two BCD numbers ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA
MOV BL, NUM2 MOV BL, NUM2 UP:
UP: ADD ADD AL, AL, NUM1NUM1
INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to divide two BCD numbers ;Program to divide two BCD numbers ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA
;
; To To store store the the resultresult UP:
UP: CMP CMP AL, AL, NUM2 NUM2 ;; CODE SEGMENT
CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX MOV AL, NUM1 MOV AL, NUM1 SUB AL, NUM2 SUB AL, NUM2 D S D S MOV MOV MOV MOV INT 21H INT 21H CODE ENDS CODE ENDS END START END START D D T T SEGMENTSEGMENT NUM1 NUM1 DB DB 06H06H NUM2 NUM2 DB DB 04H04H RESULT RESULT DB DB ?? DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX MOV AL, 00 MOV AL, 00 DEC BL DEC BL JNZ UP JNZ UP MOV
MOV RESULT, RESULT, ALAL MOV
MOV AH, AH, 4CH4CH
D D T T SEGMENTSEGMENT NUM1 NUM1 DB DB 24H24H NUM2 NUM2 DB DB 04H04H RESULT RESULT DB DB ?? REMAIN REMAIN DB DB ?? TEMP TEMP DB DB ?? DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV
MOV DS, DS, AXAX MOV
MOV AH, AH, 00H 00H MOV
JB
JB DOWN DOWN ; ; If If AL AL is is less less then then stopstop SUB
SUB AL, AL, NUM2NUM2
;
; Adjust Adjust remainderremainder ;
; Adjust Adjust resultresult AH,
AH, ALAL AL,
AL, TEMPTEMP JMP UP
JMP UP DOWN:
DOWN: MOV MOV RESULT, RESULT, AHAH MOV
MOV REMAIN, REMAIN, ALAL MOV
MOV AH, AH, 4CH4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to find smallest of an array of
;Program to find smallest of an array of 8-bit unsigned numbers8-bit unsigned numbers ;
;
ASSUME
ASSUME DS:DATA, DS:DATA, CS:CODECS:CODE
LEA BX, ARRAY LEA BX, ARRAY MOV AH, [BX] MOV AH, [BX] BACK:
BACK: INC INC BXBX
CMP AH, [BX] CMP AH, [BX] JB GO JB GO MOV AH, [BX] MOV AH, [BX] GO:
GO: LOOP LOOP BACKBACK
MOV RESULT, AH MOV RESULT, AH MOV AH, 4CH MOV AH, 4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to find largest of an array of 8
;Program to find largest of an array of 8 -bit unsigned numbers-bit unsigned numbers ;
;
ASSUME
ASSUME DS:DATA, DS:DATA, CS:CODECS:CODE
BACK:
BACK: INC INC BXBX D S D S MOV
MOV TEMP, TEMP, ALAL ADD
ADD AH, AH, 0101 MOV
MOV AL, AL, AH AH MOV MOV MOV MOV D D T T SEGMENTSEGMENT ARRAY ARRAY DB DB 52H, 52H, 42H, 42H, 05H, 05H, 63H, 63H, 09H09H RESULT RESULT DB DB ?? DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX MOV CX, 04H MOV CX, 04H D D T T SEGMENTSEGMENT ARRAY ARRAY DB DB 52H, 52H, 42H, 42H, 05H, 05H, 63H, 63H, 09H09H RESULT RESULT DB DB ?? DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX MOV CX, 04H MOV CX, 04H LEA BX, ARRAY LEA BX, ARRAY MOV AH, [BX] MOV AH, [BX]
CMP AH, [BX] CMP AH, [BX] JA GO JA GO MOV AH, [BX] MOV AH, [BX] GO:
GO: LOOP LOOP BACKBACK
MOV RESULT, AH MOV RESULT, AH MOV AH, 4CH MOV AH, 4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to find positive and negative numbers of an array of
;Program to find positive and negative numbers of an array of 8-bit8-bit ;signed numbers
;signed numbers ;
;
ASSUME
ASSUME DS:DATA, DS:DATA, CS:CODECS:CODE
;
; countercounter BACK:
BACK:
;
; if if CF=1, CF=1, no.is no.is -ve-ve ;
; else else if if CF=0, CF=0, no. no. is is +ve+ve JMP SKIP
JMP SKIP DOWN:
DOWN: INC INC NEG_CNEG_C SKIP:
SKIP: INC INC BXBX LOOP
LOOP BACK BACK ; ; decrement decrement CX CX by by 1 1 and and goto goto label label BACKBACK ; if CX != 0 ; if CX != 0 MOV AH, 4CH MOV AH, 4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to find even and odd numbers of an
;Program to find even and odd numbers of an array of 8-bit unsignedarray of 8-bit unsigned ;numbers
;numbers ;
;
ASSUME
ASSUME DS:DATA, DS:DATA, CS:CODECS:CODE
;
; countercounter BACK:
BACK:
JC
JC DOWN DOWN ; ; if if CF=1, CF=1, no.is no.is oddodd D
D T T SEGMENTSEGMENT ARRAY
ARRAY DB DB 52H,42H,05H,63H,89H,0ACH,52H,42H,05H,63H,89H,0ACH,5FH,37H,07AH,99H5FH,37H,07AH,99H POS_C
POS_C DB DB 00H 00H ; ; positive positive number number countercounter NEG_C
NEG_C DB DB 00H 00H ; ; negative negative number number countercounter DATA ENDS
DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX MOV
MOV CX, CX, 0AH 0AH LEA BX, ARRAY LEA BX, ARRAY MOV
MOV AL, AL, [BX][BX] SHL AL, 1 SHL AL, 1 JC
JC DOWN DOWN INC
INC POS_C POS_C
D
D T T SEGMENTSEGMENT ARRAY
ARRAY DB DB 52H,42H,05H,63H,09H,0ACH,52H,42H,05H,63H,09H,0ACH,5FH,37H,07AH,99H5FH,37H,07AH,99H EVEN_C
EVEN_C DB DB 00H 00H ; ; even even number number countercounter ODD_C
ODD_C DB DB 00H 00H ; ; odd odd number number countercounter DATA ENDS
DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX MOV
MOV CX, CX, 0AH 0AH LEA BX, ARRAY LEA BX, ARRAY MOV
MOV AL, AL, [BX][BX] SHR AL, 1 SHR AL, 1
INC
INC EVEN_C EVEN_C ; ; else else if if CF=0, CF=0, no. no. is is eveneven JMP SKIP
JMP SKIP DOWN:
DOWN: INC INC ODD_CODD_C SKIP:
SKIP: INC INC BXBX LOOP
LOOP BACK BACK ; ; decrement decrement CX CX by by 1 1 and and goto goto label label BACKBACK ; if CX != 0 ; if CX != 0 MOV AH, 4CH MOV AH, 4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to arrange numbers in array in ascending order ;Program to arrange numbers in array in ascending order ;
;
ASSUME
ASSUME DS:DATA, DS:DATA, CS:CODECS:CODE
;
; pass pass countercounter OUTER:
OUTER: INNER: INNER:
;
; compare compare current current and and next next numbernumber ;
; if if current current no. no. is is smaller smaller no no exchangeexchange ;
; else else exchange exchange numbersnumbers MOV [BX], AL MOV [BX], AL DEC BX DEC BX MOV [BX], DL MOV [BX], DL INC BX INC BX DOWN:
DOWN: DEC DEC CH CH ; ; decrement decrement comparison comparison countercounter JNZ INNER
JNZ INNER DEC
DEC CL CL ; decrement ; decrement pass pass countercounter JNZ OUTER JNZ OUTER MOV AH, 4CH MOV AH, 4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to arrange numbers in array in descending order ;Program to arrange numbers in array in descending order ;
;
ASSUME
ASSUME DS:DATA, DS:DATA, CS:CODECS:CODE
;
; pass pass countercounter OUTER: OUTER: INNER: INNER: D D T T SEGMENTSEGMENT ARRAY
ARRAY DB DB 52H,42H,05H,63H,09H,0ACH,52H,42H,05H,63H,09H,0ACH,5FH,37H,07AH,99H5FH,37H,07AH,99H DATA ENDS
DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX MOV
MOV CL, CL, 0AH 0AH LEA
LEA BX, BX, ARRAYARRAY MOV
MOV CH, CH, 09H 09H ; ; comparison comparison countercounter MOV
MOV AL, AL, [BX][BX] INC BX INC BX CMP CMP AL, AL, [BX] [BX] JC JC DOWN DOWN MOV MOV DL, DL, [BX] [BX] D D T T SEGMENTSEGMENT ARRAY
ARRAY DB DB 52H,42H,05H,63H,09H,0ACH,52H,42H,05H,63H,09H,0ACH,5FH,37H,07AH,99H5FH,37H,07AH,99H DATA ENDS
DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV DS, AX MOV DS, AX MOV
MOV CL, CL, 0AH 0AH LEA
LEA BX, BX, ARRAYARRAY MOV
MOV CH, CH, 09H 09H ; ; comparison comparison countercounter MOV
MOV AL, AL, [BX][BX] INC BX
CMP
CMP AL, AL, [BX] [BX] ; ; compare compare current current and and next next numbernumber ;
; if if current current no. no. is is larger larger no no exchangeexchange ;
; else else exchange exchange numbersnumbers
DOWN:
DOWN: ; ; decrement decrement comparison comparison countercounter DEC
DEC CL CL ; decrement ; decrement pass pass countercounter JNZ OUTER JNZ OUTER MOV AH, 4CH MOV AH, 4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to transfer block of data using string instruction ;Program to transfer block of data using string instruction ;
;
ASSUME
ASSUME DS:DATA, DS:DATA, ,ES: ,ES: EXTRA, EXTRA, CS:CODECS:CODE
;
; initialize initialize datasegmentdatasegment MOV
MOV ES, ES, AX AX ; ; initialize initialize extra extra segmentsegment LEA SI, BLOCK1
LEA SI, BLOCK1 LEA DI, BLOCK2 LEA DI, BLOCK2 MOV
MOV CX, CX, 000AH 000AH ; ; councounter ter
CLD
CLD ; ; set set auto auto increment increment modemode REP MOVSB REP MOVSB MOV AH, 4CH MOV AH, 4CH INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to find sum of numbers in an
;Program to find sum of numbers in an arrayarray ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA
;Initialize
;Initialize data data segmentsegment ;No.
;No. of of elements elements in in arrayarray ;Pointer
;Pointer to to ARRAYARRAY UP:
UP: ;Copy ;Copy current current element element in in ALAL ;Add
;Add current current element element to to RESULTRESULT ;Store
;Store CarryCarry JNC JNC DOWN DOWN MOV MOV DL, DL, [BX] [BX] MOV [BX], AL MOV [BX], AL DEC BX DEC BX MOV [BX], DL MOV [BX], DL INC BX INC BX DEC DEC CH CH JNZ INNER JNZ INNER BLOCK1
BLOCK1 DB DB 52H,42H,05H,63H,09H,0ACH,52H,42H,05H,63H,09H,0ACH,5FH,37H,07AH,99H5FH,37H,07AH,99H BLOCK2
BLOCK2 DB DB 10 10 DUP(00H)DUP(00H) DATA ENDS
DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV AX, AX, DATADATA MOV MOV DS, DS, AX AX D D T T SEGMENTSEGMENT ARRAY DB 10H, 20H, 30H, 40H, 50H ARRAY DB 10H, 20H, 30H, 40H, 50H RESULT DB 0H RESULT DB 0H CARRY DB 0H CARRY DB 0H DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV DX, DX, DATADATA MOV
MOV DS, DS, DX DX MOV
MOV CL, CL, 05H 05H MOV
MOV SI, SI, OFFSET OFFSET ARRAY ARRAY MOV
MOV AL, AL, [SI] [SI] ADD
ADD RESULT, RESULT, AL AL JNC NEXT
JNC NEXT INC
NEXT:
NEXT: INC INC SI SI ;Increment ;Increment pointer pointer to to nextnext ;element
;element LOOP UP
LOOP UP MOV
MOV AH, AH, 4CH 4CH ;Terminate ;Terminate programprogram INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to find sum of series 1+2+3+ … +9+10 ;Program to find sum of series 1+2+3+ … +9+10 ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA
;Initialize
;Initialize data data segmentsegment ;No.
;No. of of elements elements in in seriesseries MOV
MOV AL, AL, 01H 01H ;First ;First number number of of seriesseries UP:
UP: ADD ADD RESULT, RESULT, AL AL ;Add ;Add current current element element to to RESULTRESULT JNC NEXT
JNC NEXT INC
INC CARRY CARRY ;Store ;Store CarryCarry NEXT:
NEXT: INC INC AL AL ;Next ;Next element element of of seriesseries LOOP UP
LOOP UP MOV
MOV AH, AH, 4CH 4CH ;Terminate ;Terminate programprogram INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to reverse the string ;Program to reverse the string ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA
;Initialize
;Initialize data data segmentsegment ;Pointer
;Pointer to to STRINGSTRING ;Length
;Length of of StringString ;Pointer
;Pointer to to REVREV ;Place
;Place pointer pointer at at the the lastlast ;location in REV
;location in REV UP:
UP: MOV MOV AL, AL, [SI] [SI] ;Transfer ;Transfer current current character character ofof ;STRING to AL
;STRING to AL MOV
MOV [DI], [DI], AL AL ;Tansfer ;Tansfer character character in in AL AL to to REVREV INC
INC SI SI ;Update ;Update pointerspointers DEC DI DEC DI LOOP UP LOOP UP D D T T SEGMENTSEGMENT RESULT DB 0H RESULT DB 0H CARRY DB 0H CARRY DB 0H DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV DX, DX, DATADATA MOV
MOV DS, DS, DX DX MOV
MOV CL, CL, 0AH 0AH
D
D T T SEGMENTSEGMENT
STRING DB 'Good Morning' STRING DB 'Good Morning' REV DB 12 DUP(0) REV DB 12 DUP(0) DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV DX, DX, DATADATA MOV
MOV DS, DS, DX DX LEA
LEA SI, SI, STRING STRING MOV
MOV CX, CX, 0CH 0CH LEA
LEA DI, DI, REV REV ADD
MOV
MOV AH, AH, 4CH 4CH ;Terminate ;Terminate programprogram INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to find length string ;Program to find length string ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA
;Initialize
;Initialize data data segmentsegment ;Pointer
;Pointer to to STRINGSTRING ;Counter
;Counter for for lengthlength ;String
;String termination termination charactercharacter ;Check
;Check end end of of is is reachedreached ;If
;If 'yes', 'yes', exitexit ;If
;If 'no', 'no', increment increment countercounter ;Update
;Update pointerpointer EXIT:
EXIT:
;Terminate
;Terminate programprogram CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to concatenate two strings ;Program to concatenate two strings ;
;
ASSUME CS:CODE, DS:DATA ASSUME CS:CODE, DS:DATA
;First
;First StringString ;Second
;Second StringString ;Concatenated
;Concatenated stringstring
;Initialize
;Initialize data data segmentsegment ;Pointer
;Pointer to to STR1STR1 ;Pointer
;Pointer to to STR3STR3 ;String
;String termination termination charactercharacter NEXT1:
NEXT1: ;Check ;Check if if end end of of STR1 STR1 is is reachedreached ;If
;If 'yes', 'yes', start start copying copying second second STR2STR2 ;If
;If 'no', 'no', move move current current character character fromfrom ;STR1
;STR1 to to STR3STR3 ;Update
;Update pointerspointers DOWN:
DOWN: ;Pointer ;Pointer to to STR2STR2 NEXT2:
NEXT2: CMP CMP AL, AL, [SI] [SI] ;Check ;Check if if end end of of STR2 STR2 is is reachedreached D
D T T SEGMENTSEGMENT
STRING DB 'Good Morning$' STRING DB 'Good Morning$' LEN DB ? LEN DB ? DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV DX, DX, DATADATA MOV
MOV DS, DS, DX DX LEA
LEA SI, SI, STRING STRING MOV
MOV CL, CL, 00H 00H MOV
MOV AL, AL, '$' '$' NEXT:
NEXT: CMP CMP AL, AL, [SI] [SI] JZ JZ EXIT EXIT ADD ADD CL, CL, 01H 01H INC INC SI SI JMP NEXT JMP NEXT MOV
MOV LEN, LEN, CLCL MOV
MOV AH, AH, 4CH 4CH INT 21H INT 21H D D T T SEGMENTSEGMENT STR1 STR1 DB DB 'Good$' 'Good$' STR2 STR2 DB DB 'Morning$' 'Morning$' STR3 STR3 DB DB 11 11 DUP(0) DUP(0) DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV DX, DX, DATADATA MOV
MOV DS, DS, DX DX LEA
LEA SI, SI, STR1 STR1 LEA
LEA DI, DI, STR3 STR3 MOV
MOV AL, AL, '$' '$' CMP
CMP AL, AL, [SI] [SI] JZ
JZ DOWN DOWN MOV
MOV AH, AH, [SI] [SI] MOV
MOV [DI], [DI], AH AH INC INC SI SI INC DI INC DI JMP NEXT1 JMP NEXT1 LEA
JZ
JZ DOWN2 DOWN2 ;If ;If 'yes', 'yes', exitexit MOV
MOV AH, AH, [SI] [SI] ;If ;If 'no', 'no', move move current current character character fromfrom MOV
MOV [DI], [DI], AH AH ;STR2 ;STR2 to to STR3STR3 INC
INC SI SI ;Update ;Update pointerspointers INC DI
INC DI JMP NEXT2 JMP NEXT2 DOWN2:
DOWN2: MOV MOV AH, AH, 4CH 4CH ;Terminate ;Terminate programprogram INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to convert decimal number to hexadecimal ;Program to convert decimal number to hexadecimal ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA
;Initialize
;Initialize data data segmentsegment ;Move
;Move decimal decimal no. no. to to ALAL ;Separate
;Separate the the lower lower nibblenibble ;store
;store lower lower nibble nibble to to DLDL ;Move
;Move decimal decimal no. no. to to ALAL ;Separate
;Separate upper upper nibblenibble ;Move
;Move upper upper nibble nibble toto ROL
ROL AL, AL, CL CL ;lower 4 ;lower 4 bit bit positionposition MOV
MOV DH, DH, 0AH 0AH ;; MUL
MUL DH DH ;Multiply ;Multiply shifted shifted nibble nibble by by 1010 ADD
ADD AL, AL, DL DL ;Add lower ;Add lower nibble nibble to to above above resultresult MOV
MOV HEX, HEX, AL AL ;Store ;Store resultresult MOV
MOV AH, AH, 4CH 4CH ;Terminate ;Terminate programprogram INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to count number of zeros in 8 bit
;Program to count number of zeros in 8 bit numbernumber ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA
;Initialize
;Initialize data data segmentsegment ;Move
;Move NUM NUM to to ALAL ;Setup
;Setup a a counter counter with with no. no. of of bitsbits ;in NUM
;in NUM MOV BL, 00H
MOV BL, 00H UP:
UP: ROR ROR AL, AL, 1 1 ;Rotate ;Rotate AL AL to to rightright JC
JC DOWN DOWN ;If ;If CF=1, CF=1, the the LSB LSB was was 11 D D T T SEGMENTSEGMENT DECI DB 55H DECI DB 55H HEX HEX DB DB ?? DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV DX, DX, DATADATA MOV
MOV DS, DS, DX DX MOV
MOV AL, AL, DECI DECI AND
AND AL, AL, 0FH 0FH MOV
MOV DL, DL, AL AL MOV
MOV AL, AL, DECI DECI AND
AND AL, AL, 0F0H 0F0H MOV MOV CL, CL, 04H 04H D D T T SEGMENTSEGMENT NUM DB 73H NUM DB 73H ZEROS DB 00H ZEROS DB 00H DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV DX, DX, DATADATA MOV
MOV DS, DS, DX DX MOV
MOV AL, AL, NUM NUM MOV
INC
INC BL BL ;If ;If CF=0, CF=0, the the LSB LSB was was 00 DOWN:
DOWN: LOOP LOOP UPUP
MOV ZEROS, BL MOV ZEROS, BL MOV
MOV AH, AH, 4CH 4CH ;Terminate ;Terminate programprogram INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to count number of ones in 8
;Program to count number of ones in 8 bit numberbit number ;
;
ASSUME
ASSUME CS:CODE, CS:CODE, DS:DATADS:DATA
;Initialize
;Initialize data data segmentsegment ;Move
;Move NUM NUM to to ALAL ;Setup
;Setup a a counter counter with with no. no. of of bitsbits ;in NUM
;in NUM MOV BL, 00H
MOV BL, 00H UP:
UP: ROR ROR AL, AL, 1 1 ;Rotate ;Rotate AL AL to to rightright JNC
JNC DOWN DOWN ;If ;If CF=0, CF=0, the the LSB LSB was was 00 INC
INC BL BL ;If ;If CF=1, CF=1, the the LSB LSB was was 11 DOWN:
DOWN: LOOP LOOP UPUP
MOV NUM, BL MOV NUM, BL MOV
MOV AH, AH, 4CH 4CH ;Terminate ;Terminate programprogram INT 21H INT 21H CODE ENDS CODE ENDS END START END START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; ;
;Program to convert 8 bit hexadecimal number to decimal number ;Program to convert 8 bit hexadecimal number to decimal number ;
;
ASSUME CS:CODE, DS:DATA ASSUME CS:CODE, DS:DATA
;Initialize
;Initialize data data segmentsegment ;Move
;Move decimal decimal no. no. to to ALAL ;Separate
;Separate the the lower lower nibblenibble ;store
;store lower lower nibble nibble to to DLDL MOV
MOV AL, AL, HEX HEX ;Move ;Move decimal decimal no. no. to to ALAL AND
AND AL, AL, 0F0H 0F0H ;Separate ;Separate upper upper nibblenibble MOV
MOV CL, CL, 04H 04H ;Move ;Move upper upper nibble nibble toto ROL
ROL AL, AL, CL CL ;lower 4 ;lower 4 bit bit positionposition MOV BL, AL MOV BL, AL MOV AL, 00H MOV AL, 00H MOV AH, 00H MOV AH, 00H D D T T SEGMENTSEGMENT NUM DB 55H NUM DB 55H ONES DB 00H ONES DB 00H DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV DX, DX, DATADATA MOV
MOV DS, DS, DX DX MOV
MOV AL, AL, NUM NUM MOV MOV CX, CX, 08H 08H D D T T SEGMENTSEGMENT HEX DB 0FFH HEX DB 0FFH DECI DW ? DECI DW ? DATA ENDS DATA ENDS CODE SEGMENT CODE SEGMENT START:
START: MOV MOV DX, DX, DATADATA MOV
MOV DS, DS, DX DX MOV
MOV AL, AL, HEX HEX AND
AND AL, AL, 0FH 0FH MOV
UP:
UP: ADD ADD AL, AL, 16H 16H ;Multiplication ;Multiplication by by successivesuccessive JNC
JNC DOWN1 DOWN1 ;add ;add operation operation and and adjustadjust INC
INC AH AH ;current ;current sum sum according according toto DOWN1:
DOWN1: DAA DAA ;decimal addition;decimal addition JNC DOWN2
JNC DOWN2 INC AH INC AH DOWN2:
DOWN2: DEC DEC BLBL JNZ UP JNZ UP ADD
ADD AL, AL, DL DL ;Add lower ;Add lower nibble nibble to to above above resultresult JNC
JNC DOWN3 DOWN3 ;and ;and adjust adjust itit INC AH INC AH DOWN3: DAA DOWN3: DAA JNC DOWN4 JNC DOWN4 INC AH INC AH DOWN4:
DOWN4: MOV MOV DECI, DECI, AX AX ;Store ;Store resultresult MOV
MOV AH, AH, 4CH 4CH ;Terminate ;Terminate programprogram INT 21H INT 21H CODE ENDS CODE ENDS END START END START