5-8086 Assembly Language Programming
Short Description
MSBTE Computer Engineering CO-4G subject Microprocessor and Programming (MAP-17431) notes....
Description
Microprocessor and Programming
The art of Assembly Language Programming
5. 8086 Assembly Language Programming Programming 24 Marks Syllabus: 5.1 Model of 8086 assembly language programs. Programming using assembler – 5.2 Arithmetic operations on Hex and BCD numbers - Addition, Subtraction, Multiplication and Division Sum of Series Smallest and Largest numbers from array Sorting numbers in Ascending and Descending order Finding ODD/EVEN numbers in the array Finding Positive and Negative Numbers in array Block transfer String Operations - Length, Reverse, Compare, Concatenation, Copy
Count Numbers of ‘1’ and ‘0’ in 8/16 bit number
BCD to Hex and Hex to BCD number conversion
Model of assembly language programming:
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 the same way.
;Comments ASSUME DATA
CS:CODE, DS:DATA SEGMENT
; ;program data declaration here ; DATA
ENDS
CODE
SEGMENT
START: MOV MOV
AX, DATA DS, AX
; ;program code here ; MOV
AH, 4CH
INT
21H
CODE
ENDS
END
START
Computer Department, Jamia Polytechnic, Akkalkuwa
1
Microprocessor and Programming
The art of Assembly Language Programming
Sample programs:
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 MSBTE manual for MAP subject. Also, good examples are given in following books:
1. Microprocessor & interfacing (programming & hardware) BY Douglas V-Hall Tata McGraw Hill 2. Advanced microprocessor & peripheral BY A.K. Ray & K.M. Bhurchandi Tata McGraw Hill
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to add two 32-bit numbers ; ASSUME CS:CODE, DS:DATA NUM1 NUM2 RESULT DATA
DD 12345678H DD 87654321H DD ? ENDS
START:
MOV MOV LEA MOV LEA MOV
CODE END
AX, DATA DS, AX BX, NUM1 AX, [BX] BX, NUM2 DX, [BX] AX, DX LEA BX, RESULT MOV [BX], AX LEA BX, NUM1 INC BX INC BX MOV AX, [BX] LEA BX, NUM2 INC BX INC BX MOV DX, [BX] AX, DX LEA BX, RESULT INC BX INC BX MOV [BX], AX MOV AH, 4CH INT 21H ENDS START
Computer Department, Jamia Polytechnic, Akkalkuwa
2
Microprocessor and Programming
The art of Assembly Language Programming
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to subtract two 32-bit numbers ; ASSUME CS:CODE, DS:DATA NUM1 NUM2 RESULT DATA
DD 87654321H DD 12345678H DD ? ENDS
START:
MOV MOV LEA MOV LEA MOV
CODE END
AX, DATA DS, AX BX, NUM1 AX, [BX] BX, NUM2 DX, [BX] AX, DX LEA BX, RESULT MOV [BX], AX LEA BX, NUM1 INC BX INC BX MOV AX, [BX] LEA BX, NUM2 INC BX INC BX MOV DX, [BX] AX, DX LEA BX, RESULT INC BX INC BX MOV [BX], AX MOV AH, 4CH INT 21H ENDS START
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to add data bytes of one array with wit h data bytes of second ;array and store result in third array ; ASSUME CS:CODE, DS:DATA ARRAY1 ARRAY2 ARRAY3 DATA
DB 01H, 02H, 03H, 04H, 05H, 06H, 07H DB 10H, 20H, 30H, 40H, 50H, 60H, 70H DB ? ENDS
START:
MOV MOV LEA LEA LEA MOV MOV ADD MOV
UP:
AX, DATA DS, AX SI, ARRAY1 DI, ARRAY2 BX, ARRAY3 CL, 07H AL, [SI] AL, [DI] [BX], AL
; set 3 pointers for arrays ; count
Computer Department, Jamia Polytechnic, Akkalkuwa
3
Microprocessor and Programming
The art of Assembly Language Programming
INC SI INC DI INC BX DEC CL JNZ UP MOV AH, 4CH INT 21H ENDS START
CODE END
; increment pointers
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to find area and perimeter of rectangle ; ASSUME CS:CODE, DS:DATA HEIGHT WIDTH AREA PERIM DATA
DB 15H DB 25H ? ? ENDS
START:
MOV MOV MOV MOV
; result will be 16-bit
AX, DATA DS, AX AL, HEIGHT BL, WIDTH BL MOV AREA, AX
; ; ; ; ; ;
get HEIGHT in AL get WIDTH in BL Area = HEIGHT x WIDTH store AREA perimeter=2(height+width)
MOV AL, HEIGHT MOV BL, WIDTH ADD AL, BL ; AL = AL + BL MOV BL, 02H MUL BL ; AL = 02H x AL MOV PERIM, AX ; store perimeter MOV AH, 4CH INT 21H ENDS START
CODE END
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to multiply two 16-bit ; ASSUME CS:CODE, DS:DATA NUM1 NUM2 RESULT DATA
DW 2001H DW 0004H ? ENDS
START:
MOV MOV MOV MOV MOV
AX, DS, DX, AX, BX, BX LEA DI,
DATA AX 0000H NUM1 NUM2
numbers
; result will be 32-bit
; clear DX ; get first no. in AX ; get second no. in BX
RESULT
Computer Department, Jamia Polytechnic, Akkalkuwa
4
Microprocessor and Programming
MOV [DI], AX INC DI INC DI MOV [DI], DX MOV AH, 4CH INT 21H ENDS START
CODE END
The art of Assembly Language Programming
; store lower word of result ; store higher word of result
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to divide 32-bit/16-bit ; ASSUME CS:CODE, DS:DATA NUM1 NUM2 RESULT REMAIN DATA
DD 12345678H DW 5678H DW ? DW ? ENDS
START:
MOV AX, DATA MOV DS, AX LEA SI, NUM1 MOV AX, [SI] INC SI INC SI MOV DX, [SI] MOV BX, NUM2 IDIV BX MOV RESULT, AX MOV REMAIN, DX MOV AH, 4CH INT 21H ENDS START
CODE END
; ; ; ;
numbers
32-bit number 16-bit number result will be 16-bit remainder will be 16-bit
; get lower 16 bits of 1st number in AX ; ; ; ; ;
get higher 16 bits of 1st number in DX get second number in BX divide store result store remainder
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to divide 16-bit/16-bit ; ASSUME CS:CODE, DS:DATA NUM1 NUM2 RESULT REMAIN DATA
DW 1234H DW 0064H DW ? DW ? ENDS
START:
MOV MOV MOV MOV MOV DIV MOV MOV MOV INT
AX, DATA DS, AX AX, NUM1 DX, 0000H BX, NUM2 BX RESULT, AX REMAIN, DX AH, 4CH 21H
numbers
; ; ; ;
16-bit number 16-bit number result will be 16-bit remainder will be 16-bit
; ; ; ; ; ;
get 1st number in AX Clear DX get second number in BX divide store result store remainder
Computer Department, Jamia Polytechnic, Akkalkuwa
5
Microprocessor and Programming
CODE END
The art of Assembly Language Programming
ENDS START
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to divide 8-bit/8-bit ; ASSUME CS:CODE, DS:DATA NUM1 NUM2 RESULT REMAIN DATA
DB 34H DB 14H DB ? DB ? ENDS
START:
MOV AX, DATA MOV DS, AX MOV AL, NUM1 MOV AH, 00H MOV BL, NUM2 DIV BL MOV RESULT, AL MOV REMAIN, AH MOV AH, 4CH INT 21H ENDS START
CODE END
numbers
; ; ; ;
8-bit number 8-bit number result will be 8-bit remainder will be 8-bit
; ; ; ; ; ;
get 1st number in AL Clear AH get second number in BL divide store result store remainder
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to add two BCD numbers ; ASSUME CS:CODE, DS:DATA NUM1 NUM2 RESULT DATA
DB 06H DB 04H DB ? ENDS
START:
MOV MOV MOV ADD
CODE END
AX, DS, AL, AL,
DATA AX NUM1 NUM2
MOV RESULT, AL MOV AH, 4CH INT 21H ENDS START
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to subtract two BCD numbers ; ASSUME CS:CODE, DS:DATA
Computer Department, Jamia Polytechnic, Akkalkuwa
6
Microprocessor and Programming
NUM1 NUM2 RESULT DATA
DB 06H DB 04H DB ? ENDS
START:
MOV MOV MOV SUB
AX, DS, AL, AL,
The art of Assembly Language Programming
DATA AX NUM1 NUM2
MOV RESULT, AL MOV AH, 4CH INT 21H ENDS START
CODE END
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to multiply two BCD numbers ; ASSUME CS:CODE, DS:DATA NUM1 NUM2 RESULT DATA
DB 06H DB 04H DB ? ENDS
START:
UP:
MOV MOV MOV MOV ADD
CODE END
DEC BL JNZ UP MOV RESULT, AL MOV AH, 4CH INT 21H ENDS START
AX, DS, AL, BL, AL,
DATA AX 00 NUM2 NUM1
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to divide two BCD numbers ; ASSUME CS:CODE, DS:DATA NUM1 DB NUM2 DB RESULT REMAIN TEMP DB DATA
24H 04H DB ? DB ? ? ENDS
START:
MOV MOV MOV MOV CMP
UP:
AX, DS, AH, AL, AL,
DATA AX 00H NUM1 NUM2
; To store the result ;
Computer Department, Jamia Polytechnic, Akkalkuwa
7
Microprocessor and Programming
JB SUB
DOWN AL, NUM2
MOV ADD MOV
TEMP, AL AH, 01 AL, AH
The art of Assembly Language Programming
; If AL is less then stop ; Adjust remainder ; Adjust result
MOV AH, AL MOV AL, TEMP JMP UP MOV RESULT, AH MOV REMAIN, AL MOV AH, 4CH INT 21H ENDS START
DOWN:
CODE END
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to find smallest of an array of 8-bit unsigned numbers ; ASSUME DS:DATA, CS:CODE ARRAY RESULT DATA
DB 52H, 42H, 05H, 63H, 09H DB ? ENDS
START:
MOV AX, DATA MOV DS, AX MOV CX, 04H LEA BX, ARRAY MOV AH, [BX] INC BX CMP AH, [BX] JB GO MOV AH, [BX] LOOP BACK MOV RESULT, AH MOV AH, 4CH INT 21H ENDS START
BACK:
GO:
CODE END
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to find largest of an array of 8 -bit unsigned numbers ; ASSUME DS:DATA, CS:CODE ARRAY RESULT DATA
DB 52H, 42H, 05H, 63H, 09H DB ? ENDS
START:
MOV MOV MOV LEA MOV INC
BACK:
AX, DS, CX, BX, AH, BX
DATA AX 04H ARRAY [BX]
Computer Department, Jamia Polytechnic, Akkalkuwa
8
Microprocessor and Programming
The art of Assembly Language Programming
CMP AH, [BX] JA GO MOV AH, [BX] LOOP BACK MOV RESULT, AH MOV AH, 4CH INT 21H ENDS START
GO:
CODE END
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to find positive and negative numbers of an array of 8-bit ;signed numbers ; ASSUME DS:DATA, CS:CODE ARRAY POS_C NEG_C DATA
DB 52H,42H,05H,63H,89H,0ACH, 52H,42H,05H,63H,89H,0ACH,5FH,37H,07AH,99H 5FH,37H,07AH,99H DB 00H ; positive number counter DB 00H ; negative number counter ENDS
START:
MOV AX, DATA MOV DS, AX MOV CX, 0AH LEA BX, ARRAY MOV AL, [BX] SHL AL, 1 JC DOWN INC POS_C JMP SKIP INC NEG_C INC BX LOOP BACK
BACK:
DOWN: SKIP:
MOV AH, 4CH INT 21H ENDS START
CODE END
; counter
; if CF=1, no.is -ve ; else if CF=0, no. is +ve
; decrement CX by 1 and goto label BACK ; if CX != 0
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to find even and odd numbers of an array of 8-bit unsigned ;numbers ; ASSUME DS:DATA, CS:CODE ARRAY EVEN_C ODD_C DATA
DB 52H,42H,05H,63H,09H,0ACH, 52H,42H,05H,63H,09H,0ACH,5FH,37H,07AH,99H 5FH,37H,07AH,99H DB 00H ; even number counter DB 00H ; odd number counter ENDS
START:
MOV AX, MOV DS, MOV CX, LEA BX, MOV AL, SHR AL, JC DOWN
BACK:
DATA AX 0AH ARRAY [BX] 1
; counter
; if CF=1, no.is odd
Computer Department, Jamia Polytechnic, Akkalkuwa
9
Microprocessor and Programming
INC EVEN_C JMP SKIP INC ODD_C INC BX LOOP BACK
DOWN: SKIP:
MOV AH, 4CH INT 21H ENDS START
CODE END
The art of Assembly Language Programming
; else if CF=0, no. is even
; decrement CX by 1 and goto label BACK ; if CX != 0
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to arrange numbers in array in ascending order ; ASSUME DS:DATA, CS:CODE ARRAY DATA
DB 52H,42H,05H,63H,09H,0ACH, 52H,42H,05H,63H,09H,0ACH,5FH,37H,07AH,99H 5FH,37H,07AH,99H ENDS
START:
MOV MOV MOV LEA MOV MOV INC CMP
OUTER: INNER:
DOWN:
CODE END
AX, DATA DS, AX CL, 0AH BX, ARRAY CH, 09H AL, [BX] BX AL, [BX] DOWN MOV DL, [BX] MOV [BX], AL DEC BX MOV [BX], DL INC BX DEC CH JNZ INNER DEC CL JNZ OUTER MOV AH, 4CH INT 21H ENDS START
; pass counter ; comparison counter ; compare current and next number ; if current no. is smaller no exchange ; else exchange numbers
; decrement comparison counter ; decrement pass counter
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to arrange numbers in array in descending order ; ASSUME DS:DATA, CS:CODE ARRAY DATA
DB 52H,42H,05H,63H,09H,0ACH, 52H,42H,05H,63H,09H,0ACH,5FH,37H,07AH,99H 5FH,37H,07AH,99H ENDS
START:
MOV MOV MOV LEA MOV MOV INC
OUTER: INNER:
AX, DS, CL, BX, CH, AL, BX
DATA AX 0AH ARRAY 09H [BX]
; pass counter ; comparison counter
Computer Department, Jamia Polytechnic, Akkalkuwa
10
Microprocessor and Programming
CMP AL, [BX] DOWN MOV DL, [BX] MOV [BX], AL DEC BX MOV [BX], DL INC BX DEC CH JNZ INNER DEC CL JNZ OUTER MOV AH, 4CH INT 21H ENDS START
DOWN:
CODE END
The art of Assembly Language Programming
; compare current and next number ; if current no. is larger no exchange ; else exchange numbers
; decrement comparison counter ; decrement pass counter
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to transfer block of data using string instruction ; ASSUME DS:DATA, ,ES: EXTRA, CS:CODE BLOCK1 BLOCK2 DATA
DB 52H,42H,05H,63H,09H,0ACH, 52H,42H,05H,63H,09H,0ACH,5FH,37H,07AH,99H 5FH,37H,07AH,99H DB 10 DUP(00H) ENDS
START:
MOV AX, DATA MOV DS, AX MOV ES, AX LEA SI, BLOCK1 LEA DI, BLOCK2 MOV CX, 000AH CLD REP MOVSB MOV AH, 4CH INT 21H ENDS START
CODE END
; initialize datasegment ; initialize extra segment ; counter ; set auto increment mode
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to find sum of numbers in an array ; ASSUME CS:CODE, DS:DATA ARRAY DB 10H, 20H, 30H, 40H, 50H RESULT DB 0H CARRY DB 0H ENDS
DATA START:
UP:
MOV MOV MOV MOV MOV ADD JNC INC
DX, DATA DS, DX CL, 05H SI, OFFSET ARRAY AL, [SI] RESULT, AL NEXT CARRY
;Initialize data segment ;No. of elements in array ;Pointer to ARRAY ;Copy current element in AL ;Add current element to RESULT ;Store Carry
Computer Department, Jamia Polytechnic, Akkalkuwa
11
Microprocessor and Programming
NEXT:
INC SI
CODE END
LOOP UP MOV AH, 4CH INT 21H ENDS START
The art of Assembly Language Programming
;Increment pointer to next ;element ;Terminate program
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to find sum of series 1+2+3+ … +9+10 ; ASSUME CS:CODE, DS:DATA RESULT DB 0H CARRY DB 0H ENDS
DATA START:
MOV DX, DATA MOV DS, DX MOV CL, 0AH
;Initialize data segment ;No. of elements in series
MOV AL, 01H ADD RESULT, AL JNC NEXT INC CARRY INC AL LOOP UP MOV AH, 4CH INT 21H ENDS START
UP: NEXT:
CODE END
;First number of series ;Add current element to RESULT ;Store Carry ;Next element of series ;Terminate program
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to reverse the string ; ASSUME CS:CODE, DS:DATA STRING DB 'Good Morning' REV DB 12 DUP(0) ENDS
DATA START:
MOV MOV LEA MOV LEA ADD
DX, DS, SI, CX, DI, DI,
DATA DX STRING 0CH REV 0BH
UP:
MOV AL, [SI] MOV [DI], AL INC SI DEC DI LOOP UP
;Initialize data segment ;Pointer to STRING ;Length of String ;Pointer to REV ;Place pointer at the last ;location in REV ;Transfer current character of ;STRING to AL ;Tansfer character in AL to REV ;Update pointers
Computer Department, Jamia Polytechnic, Akkalkuwa
12
Microprocessor and Programming
MOV AH, 4CH INT 21H ENDS START
CODE END
The art of Assembly Language Programming
;Terminate program
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to find length string ; ASSUME CS:CODE, DS:DATA STRING DB 'Good Morning$' LEN DB ? ENDS
DATA START:
NEXT:
EXIT: CODE END
MOV DX, DATA MOV DS, DX LEA SI, STRING MOV CL, 00H MOV AL, '$' CMP AL, [SI] JZ EXIT ADD CL, 01H INC SI JMP NEXT MOV LEN, CL MOV AH, 4CH INT 21H ENDS START
;Initialize data segment ;Pointer to STRING ;Counter for length ;String termination character ;Check end of is reached ;If 'yes', exit ;If 'no', increment counter ;Update pointer ;Terminate program
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to concatenate two strings ; ASSUME CS:CODE, DS:DATA STR1 DB 'Good$' STR2 DB 'Morning$' STR3 DB 11 DUP(0) ENDS
DATA START:
NEXT1:
DOWN: NEXT2:
MOV DX, DATA MOV DS, DX LEA SI, STR1 LEA DI, STR3 MOV AL, '$' CMP AL, [SI] JZ DOWN MOV AH, [SI] MOV [DI], AH INC SI INC DI JMP NEXT1 LEA SI, STR2 CMP AL, [SI]
;First String ;Second String ;Concatenated string
;Initialize data segment ;Pointer to STR1 ;Pointer to STR3 ;String termination character ;Check if end of STR1 is reached ;If 'yes', start copying second STR2 ;If 'no', move current character from ;STR1 to STR3 ;Update pointers ;Pointer to STR2 ;Check if end of STR2 is reached
Computer Department, Jamia Polytechnic, Akkalkuwa
13
Microprocessor and Programming
DOWN2: CODE END
JZ DOWN2 MOV AH, [SI] MOV [DI], AH INC SI INC DI JMP NEXT2 MOV AH, 4CH INT 21H ENDS START
The art of Assembly Language Programming
;If 'yes', exit ;If 'no', move current character from ;STR2 to STR3 ;Update pointers ;Terminate program
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to convert decimal number to hexadecimal ; ASSUME CS:CODE, DS:DATA DECI DB 55H HEX DB ? ENDS
DATA START:
CODE END
MOV DX, DATA MOV DS, DX MOV AL, DECI AND AL, 0FH MOV DL, AL MOV AL, DECI AND AL, 0F0H MOV CL, 04H ROL AL, CL MOV DH, 0AH MUL DH ADD AL, DL MOV HEX, AL MOV AH, 4CH INT 21H ENDS START
;Initialize data segment ;Move decimal no. to AL ;Separate the lower nibble ;store lower nibble to DL ;Move decimal no. to AL ;Separate upper nibble ;Move upper nibble to ;lower 4 bit position ; ;Multiply shifted nibble by 10 ;Add lower nibble to above result ;Store result ;Terminate program
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to count number of zeros in 8 bit number ; ASSUME CS:CODE, DS:DATA NUM DB 73H ZEROS DB 00H ENDS
DATA START:
UP:
MOV MOV MOV MOV
DX, DS, AL, CX,
DATA DX NUM 08H
MOV BL, 00H ROR AL, 1 JC DOWN
;Initialize data segment ;Move NUM to AL ;Setup a counter with no. of bits ;in NUM ;Rotate AL to right ;If CF=1, the LSB was 1
Computer Department, Jamia Polytechnic, Akkalkuwa
14
Microprocessor and Programming
INC BL LOOP UP MOV ZEROS, BL MOV AH, 4CH INT 21H ENDS START
DOWN:
CODE END
The art of Assembly Language Programming
;If CF=0, the LSB was 0 ;Terminate program
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to count number of ones in 8 bit number ; ASSUME CS:CODE, DS:DATA NUM DB 55H ONES DB 00H ENDS
DATA START:
MOV MOV MOV MOV
DX, DS, AL, CX,
DATA DX NUM 08H
MOV BL, 00H ROR AL, 1 JNC DOWN INC BL LOOP UP MOV NUM, BL MOV AH, 4CH INT 21H ENDS START
UP: DOWN:
CODE END
;Initialize data segment ;Move NUM to AL ;Setup a counter with no. of bits ;in NUM ;Rotate AL to right ;If CF=0, the LSB was 0 ;If CF=1, the LSB was 1 ;Terminate program
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; ;Program to convert 8 bit hexadecimal number to decimal number ; ASSUME CS:CODE, DS:DATA HEX DB 0FFH DECI DW ? ENDS
DATA START:
MOV MOV MOV AND MOV
DX, DS, AL, AL, DL,
DATA DX HEX 0FH AL
;Initialize data segment ;Move decimal no. to AL ;Separate the lower nibble ;store lower nibble to DL
MOV AND MOV ROL
AL, AL, CL, AL,
HEX 0F0H 04H CL
;Move decimal no. to AL ;Separate upper nibble ;Move upper nibble to ;lower 4 bit position
MOV BL, AL MOV AL, 00H MOV AH, 00H Computer Department, Jamia Polytechnic, Akkalkuwa
15
Microprocessor and Programming
UP: DOWN1: DOWN2:
DOWN3: DOWN4: CODE END
ADD JNC INC DAA JNC INC DEC JNZ
AL, 16H DOWN1 AH DOWN2 AH BL UP
ADD AL, DL JNC DOWN3 INC AH DAA JNC DOWN4 INC AH MOV DECI, AX MOV AH, 4CH INT 21H ENDS START
The art of Assembly Language Programming
;Multiplication by successive ;add operation and adjust ;current sum according to ;decimal addition
;Add lower nibble to above result ;and adjust it
;Store result ;Terminate program
Computer Department, Jamia Polytechnic, Akkalkuwa
16
View more...
Comments