Assembly Language Programs
March 19, 2017 | Author: Parminder Ghai | Category: N/A
Short Description
Download Assembly Language Programs...
Description
Assembly Language Programming
Submitted by : Parminder Ghai Class: B.tech (C.S.E) 4th Semester
1. Program for finding Fibonacci Series. INCLUDE 'EMU8086.INC' ORG 100H
LEA SI, MSG1 CALL PRINT_STRING CALL SCAN_NUM GOTOXY 0,2 PRINTN 'THE FIBONACCI SERIES IS' MOV AX,A MOV BX,B L1: CALL PRINT_NUM ADD AX,BX PRINT ' ' XCHG AX,BX LOOP L1 RET
MSG1 DB 'HOW MANY NUMBERS?:',0 A DW 0 B DW 1 DEFINE_PRINT_STRING DEFINE_SCAN_NUM DEFINE_PRINT_NUM DEFINE_PRINT_NUM_UNS END OUTPUT:
2. Program for finding Factorial. INCLUDE 'EMU8086.INC' ORG 100H
LEA SI,LABEL CALL PRINT_STRING CALL SCAN_NUM
MOV AX,1 GOTOXY 0,2 PRINT 'FACTORIAL OF NUMBER|=' CMP CX,0 JE PRINT_RESULT L1: MUL CX LOOP L1
PRINT_RESULT: CALL PRINT_NUM RET
LABEL DB 'ENTER NUMBER=',0 DEFINE_SCAN_NUM DEFINE_PRINT_NUM DEFINE_PRINT_NUM_UNS DEFINE_PRINT_STRING END
OUTPUT:
3. Program to find Largest Number in the list. INCLUDE 'EMU8086.INC' ORG 100H
LEA SI,MSG1 CALL PRINT_STRING CALL SCAN_NUM
GOTOXY 0,2 PRINTN 'ENTER LIST' MOV BX,CX CALL SCAN_NUM MOV AX,BX DEC BX MOV CX,BX L1: MOV BX,CX ADD X,4 GOTOXY X,3 CALL SCAN_NUM CMP CX,AX JA GREATER JMP BACK GREATER: MOV AX,CX BACK: MOV CX,BX
LOOP L1
GOTOXY 0,5 PRINT 'LARGEST ' CALL PRINT_NUM
RET MSG1 DB 'HOW MANY NOS? :',0 X DB 0 DEFINE_SCAN_NUM
DEFINE_PRINT_NUM DEFINE_PRINT_NUM_UNS DEFINE_PRINT_STRING END
OUTPUT:
4. Program to add Positive numbers while rejecting Negative numbers. INCLUDE 'EMU8086.INC' ORG 100H
LEA SI,MSG1 CALL PRINT_STRING CALL SCAN_NUM MOV DX,0 MOV AX,0
GOTOXY 0,2 PRINTN 'ENTER LIST' L1: MOV BX,CX CALL SCAN_NUM ADD X,4 GOTOXY X,3 CMP DX,CX JG NEGATIVE
ADD AX,CX NEGATIVE: MOV CX,BX LOOP L1
GOTOXY 0,5 PRINT 'SUM= ' CALL PRINT_NUM
RET MSG1 DB 'HOW MANY NOS?:',0 X DB 0 DEFINE_SCAN_NUM DEFINE_PRINT_NUM DEFINE_PRINT_NUM_UNS
DEFINE_PRINT_STRING END
OUTPUT:
5. Program to find Smallest number in the list. INCLUDE 'EMU8086.INC' ORG 100H
LEA SI,MSG1 CALL PRINT_STRING CALL SCAN_NUM
GOTOXY 0,2 PRINTN 'ENTER LIST' MOV BX,CX CALL SCAN_NUM MOV AX,BX DEC BX MOV CX,BX L1: MOV BX,CX ADD X,4 GOTOXY X,3 CALL SCAN_NUM CMP CX,AX JB SMALL JMP BACK SMALL: MOV AX,CX BACK: MOV CX,BX LOOP L1
GOTOXY 0,5 PRINT 'SMALLEST:' CALL PRINT_NUM RET
MSG1 DB 'HOW MANY NOS?:',0 X DB 0 DEFINE_SCAN_NUM
DEFINE_PRINT_NUM DEFINE_PRINT_NUM_UNS DEFINE_PRINT_STRING END
OUTPUT:
6. Program to search an Element in the list. INCLUDE 'EMU8086.INC' ORG 100H
LEA SI,MSG1 CALL PRINT_STRING CALL SCAN_NUM MOV AL,CL MOV CX,6 MOV BX,0 GOTOXY 0,2 L1: CMP LIST[BX],AL JE EQUAL INC BX LOOP L1
CALL PRINT_NUM PRINT 'NOT FOUND' JMP STOP
EQUAL: CALL PRINT_NUM MOV AX,BX PRINT ' FOUND AT LOCATION ' CALL PRINT_NUM STOP: RET
MSG1 DB 'ENTER NUMBER TO BE SEARCHED =',0 LIST DB 4,10,20,15,8,25 DEFINE_SCAN_NUM DEFINE_PRINT_NUM DEFINE_PRINT_NUM_UNS DEFINE_PRINT_STRING END
OUTPUT: CASE 1:
CASE 2:
7. Program to check whether a number is Prime or not. INCLUDE 'EMU8086.INC' ORG 100H
LEA SI,MSG1 CALL PRINT_STRING CALL SCAN_NUM MOV BX,CX MOV AX,CX MOV SI,2 DIV SI MOV CX,AX GOTOXY 0,2 L1: MOV AX,BX MOV DX,0 DIV CX
CMP DX,0 JE NOTPRIME LOOP L1 NOTPRIME: CMP CX,1 JE PRIME
MOV AX,BX CALL PRINT_NUM PRINT ' IS NOT A PRIME NUMBER.' JMP STOP PRIME: MOV AX,BX CALL PRINT_NUM PRINT ' IS A PRIME NUMBER' JMP STOP STOP: RET
MSG1 DB 'ENTER ANY NO.=',0 DEFINE_SCAN_NUM DEFINE_PRINT_NUM DEFINE_PRINT_NUM_UNS DEFINE_PRINT_STRING
END
OUTPUT: CASE 1:
CASE 2:
8. Program to update an Array and Display Both. INCLUDE 'EMU8086.INC' ORG 100H
MOV CX,6 MOV SI,0 PRINTN 'ORIGINAL ARRAY:' L1: MOV AL,LIST1[SI] CALL PRINT_NUM PRINT ' ' INC SI LOOP L1
GOTOXY 0,3 MOV CX,6 MOV SI,0
L2: MOV AL,LIST1[SI] ADD AL,2 MOV LIST2[SI],AL INC SI
LOOP L2
MOV CX,6 MOV SI,0 PRINTN 'UPDATED ARRAY (AFTER ADDING 2): ' L3: MOV AL,LIST2[SI] CALL PRINT_NUM PRINT ' ' INC SI
LOOP L3 RET
LIST1 DB 4,10,20,15,8,25 LIST2 DB 6 DUP(0) DEFINE_SCAN_NUM DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS END
OUTPUT:
9. Arrange the list of numbers in Ascending order. INCLUDE 'EMU8086.INC' ORG 100H
MOV CX,6 MOV SI,0 PRINTN 'ORIGINAL LIST:' L1: MOV AL,LIST1[SI] CALL PRINT_NUM PRINT ' ' INC SI LOOP L1
MOV CX,5 MOV SI,0
L2: MOV DX,CX MOV AL,LIST1[SI] CALL SMALLEST
MOV BL,LIST1[SI] MOV LIST1[SI],AL MOV LIST1[BP],BL INC SI MOV CX,DX
LOOP L2
GOTOXY 0,3 MOV CX,6 MOV SI,0 PRINTN 'LIST IN ASCENDING ORDER: ' L3: MOV AL,LIST1[SI] CALL PRINT_NUM PRINT ' ' INC SI LOOP L3 RET
LIST1 DB 4,10,20,15,8,25 SMALLEST PROC MOV DI,SI MOV BP,DI INC DI
L4: CMP LIST1[DI],AL JB SMALL JMP BACK
SMALL: MOV AL,LIST1[DI] MOV BP,DI
BACK: INC DI
LOOP L4 RET SMALLEST ENDP DEFINE_PRINT_NUM DEFINE_PRINT_NUM_UNS END
OUTPUT:
10. Program for finding 2’s complement of a Hexadecimal number. INCLUDE 'EMU8086.INC' ORG 100H
MOV AL,6BH PRINT '2S COMPLEMENT OF HEXADECIMAL NO,06BH=' NOT AL ADD AL,1 CALL PRINT_HEXDIGIT RET
PRINT_HEXDIGIT PROC MOV DL,AL LEA BX,TABLE MOV AL,DL SHR AL,4 XLAT MOV AH,0EH INT 10H MOV AL,DL AND AL,0FH XLAT MOV AH,0EH INT 10H
RET PRINT_HEXDIGIT ENDP TABLE DB '0123456789ABCDEF' DEFINE_SCAN_NUM DEFINE_PRINT_NUM DEFINE_PRINT_NUM_UNS END
OUTPUT:
View more...
Comments