Masm Programs
Masm Programs
Largest of n numbers
AIM:
To write an assembly language program to find largest number in an array using 8086
assembler MASM.
APPARATUS REQUIRED:
1. PC installed with MASM software.
ALGORITHM:
1. Initialize the starting address using ORG directive.
2. Load the count of an input array in register CL.
3. Compare the first two values in the array.Swap the values if the result produces no carry
else need not.Decrement the count value in register CL.
4. Repeat step 3 for the consecutive array values until the count becomes zero in register CL.
5. The largest number will be stored in memory locations addressed by register DI.
PROGRAM:
ASSUME CS: CODE
CODE SEGMENT
ORG 1000H
MOV SI, 2000H
MOV CL, [SI]
DEC CL
INC SI
MOV AX, [SI]
AG: CMP AX, [SI+2]
JNC NEXT
MOV AX, [SI+2]
NEXT: ADD SI, 02H
DEC CL
JNZ AG
MOV DI, 3000H
MOV [DI], AX
HLT
MOV AH, 4CH
INT 21H
CODE ENDS
END
OUTPUT:
-E 2000
2000 00.04 00.00 00.06 00.00 00.03 00.00
00.04 00.00 00.08
-G=1000
Program terminated normally
-E 3000
3000 00.00 00.08
RESULT:
Thus the program for finding largest and smallest of n numbers using MASM was
executed and verified successfully.
AIM:
To write an assembly language program to find smallest number in an array using 8086
assembler MASM.
APPARATUS REQUIRED:
1. PC installed with MASM software.
ALGORITHM:
1. Initialize the starting address using ORG directive.
2. Load the count of an input array in register CL.
3. Compare the first two values in the array. Swap the values if the result produces carry else
need not. Decrement the count value in register CL.
4. Repeat step 3 for the consecutive array values until the count becomes zero in register CL.
5. The smallest number will be stored in memory locations addressed by register DI.
PROGRAM:
ASSUME CS: CODE
CODE SEGMENT
ORG 1000H
MOV SI, 2000H
MOV CL, [SI]
DEC CL
INC SI
MOV AX, [SI]
AG: CMP AX, [SI+2]
JC NEXT
MOV AX, [SI+2]
NEXT: ADD SI, 02H
DEC CL
JNZ AG
MOV DI, 3000H
MOV [DI], AX
HLT
MOV AH, 4CH
INT 21H
CODE ENDS
END
OUTPUT:
-E 2000
2000 00.04 00.00 00.06 00.00 00.03 00.00
00.04 00.00 00.08
-G=1000
Program terminated normally
-E 3000
3000 00.00 00.03
RESULT:
Thus the program for finding largest and smallest of n numbers using MASM was
executed and verified successfully.
11. Copy a String
AIM:
To write an assembly language program to copy a string byte from one block of memory
locations to another using 8086 assembler MASM.
APPARATUS REQUIRED:
1. PC installed with MASM software.
ALGORITHM:
1. Initialize the starting address using ORG directive.
2. Load the count value in register CX for the number of strings to be copied.
3. Initialize registers SI and DI with source and destination data address respectively.
4. Store the strings one by one from source to destination address and simultaneously
decrement the count value after each string byte is copied.
5. When the count value is non-zero, repeat step 4 else terminate the program.
PROGRAM:
ASSUME CS: CODE
CODE SEGMENT
ORG 1000H
MOV CX, 0005H
MOV SI, 2000H
MOV DI, 3000H
CLD
REP MOVSB
MOV AH,4CH
INT 21H
CODE ENDS
END
OUTPUT:
-E 2000
2000 00.04 00.0A 00.06 00.23 00.18
-G=1000
Program terminated normally
-E 3000
3000 00.04 00.0A 00.06 00.23 00.18
RESULT:
Thus the assembly language program for copying a string byte using MASM was
executed and verified successfully.
RESULT:
Thus the assembly language program for comparing two string bytes using MASM
was executed and verified successfully.
ALGORITHM:
1. Initialize the starting address using ORG directive.
2. Load the count of an input array in register CL.
3. Compare the first two values in the array. Swap the values if the result produces carry else
need not. Decrement the count value in register CL.
4. Repeat step 3 for the consecutive array values until the count becomes zero in register CL.
5. The sorted order will be stored in memory locations addressed by register SI.
PROGRAM:
ASSUME CS:CODE
CODE SEGMENT
ORG 1000H
MOV SI,2000H
MOV CL,[SI]
DEC CL
L3:MOV DL,CL
MOV SI,2001H
L2:MOV AX,[SI]
CMP AX,[SI+2]
JNC L1
XCHG[SI+2],AX
XCHG[SI],AX
L1:ADD SI,02H
DEC DL
JNZ L2
DEC CL
JNZ L3
HLT
MOV AH,4CH
INT 21H
CODE ENDS
END
OUTPUT:
-E 2000
2000 00.04 00.00 00.06 00.00 00.03 00.00
00.04 00.00 00.08
-G=1000
Program terminated normally
-E 2001
2001 00.00 00.08 00.00 00.06 00.00 00.04
00.00 00.03
RESULT:
Thus the assembly language program for sorting n numbers in ascending and
descending order using MASM was executed and verified successfully .
15. Searching a String
AIM:
To write an assembly language program to search an element in an array using 8086
assembler MASM.
APPARATUS REQUIRED:
1. PC installed with MASM software.
ALGORITHM:
1. Initialize the starting address using ORG directive.
2. Load the count value in register CX for the number of string bytes to be searched.
3. Initialize registers SI and DI with source and destination data address respectively.
4. Initialize register BX with base address to store the search results.
5. Search for the string bytes. If found store “FF” else “00” in memory addressed by register
BX.
PROGRAM:
ASSUME CS: CODE, DS: CODE
CODE SEGMENT
ORG 1000H
MOV CX, 0002H
MOV SI, 2000H
MOV DI, 3000H
MOV BX, 3500H
MOV AL, [SI]
CLD
REP SCASB
JNZ LOOP
MOV AH, FFH
MOV [BX], AH
JMP LAST
LOOP: MOV AH, 00H
MOV [BX], AX
LAST: MOV AH, 4CH
INT 21H
CODE ENDS
END
OUTPUT:
-E 2000
2000 00.0A 00.06
-G=1000
Program terminated normally
-E 3000
3000 00.0A 00.06
-E 3500
3500 FF.
RESULT:
Thus the assembly language program for searching an element using MASM was
executed and verified successfully.
AIM:
To write an assembly language program in order to validate password of a system using
8086 assembler MASM.
APPARATUS REQUIRED:
1. PC installed with MASM software.
ALGORITHM:
1. Initialize the starting address using ORG directive.
2. Initialize data segment for appropriate strings to be displayed.
3. Initialize code segment to read the input string in “*” notation for validation.
4. Compare the string entered for password and saved password in data segment. If equal,
display as “PASSWORD IS CORRECT” else “INCORRECT PASSWORD”
5. Store the result in memory location.
PROGRAM:
DATA SEGMENT
PASSWORD DB 'MASM1234'
LEN EQU ($-PASSWORD)
MSG1 DB 10,13,'ENTER YOUR PASSWORD: $'
MSG2 DB 10,13,'WELCOME TO ELECTRONICS WORLD!!$'
MSG3 DB 10,13,'INCORRECT PASSWORD!$'
NEW DB 10,13,'$'
INST DB 10 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,09H
INT 21H
MOV SI,00
UP1:
MOV AH,08H
INT 21H
CMP AL,0DH
JE DOWN
MOV [INST+SI],AL
MOV DL,'*'
MOV AH,02H
INT 21H
INC SI
JMP UP1
DOWN:
MOV BX,00
MOV CX,LEN
CHECK:
MOV AL,[INST+BX]
MOV DL,[PASSWORD+BX]
CMP AL,DL
JNE FAIL
INC BX
LOOP CHECK
LEA DX,MSG2
MOV AH,09H
INT 21H
JMP FINISH
FAIL:
LEA DX,MSG3
MOV AH,009H
INT 21H
FINISH:
INT 3
CODE ENDS
END START
END
OUTPUT:
ENTER THE PASSWORD
MASM1234
PASSWORD IS CORRECT
RESULT:
Thus the program for validating system passwordusing MASM was executed and
verified successfully.
AIM:
To write an assembly language program to display system time using 8086 assembler
MASM.
APPARATUS REQUIRED:
1. PC installed with MASM software.
ALGORITHM:
1. Initialize the register AH with BIOS function to get system date and time.
2. Store the contents of CX (Year), DX (Month/Date), AL (weekday) in memory using any index
or pointer registers.
3. Store thecontents of CX and DX for time in memory locations.
PROGRAM:
.MODEL SMALL
.STACK 100H
.DATA
PROMPT DB 'Current System Time is : $'
TIME DB '00:00:00$' ; time format hr:min:sec
.CODE
MAIN PROC
MOV AX, @DATA ; initialize DS
MOV DS, AX
;**************************************************************************;
;**************************************************************************;
;------------------------- Procedure Definitions ------------------------;
;**************************************************************************;
;**************************************************************************;
;**************************************************************************;
;------------------------------ GET_TIME --------------------------------;
;**************************************************************************;
GET_TIME PROC
; this procedure will get the current system time
; input : BX=offset address of the string TIME
; output : BX=current time
;**************************************************************************;
;------------------------------- CONVERT --------------------------------;
;**************************************************************************;
CONVERT PROC
; this procedure will convert the given binary code into ASCII code
; input : AL=binary code
; output : AX=ASCII code
END MAIN
RESULT:
Thus the assembly language program to display system date and time using MASM was
executed and verified successfully.
18.Addition of 16-bit numbers
AIM:
To write an assembly language program to add two 16-bit numbers using 8086 and store
the result in memory.
ALGORITHM:
Initialize the address register.
Get the two numbers to be added from memory and store it in a register pair.
Add the contents of the register pair.
Store the sum and carry in memory locations.
PROGRAM:
data segment
a dw 0202h
b dw 0408h
c dw ?
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ax,a
mov bx,b
add ax,bx
mov c,ax
int 3
code ends
end start
Output
C:\TASM>masm an16add.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.
Object filename [an16add.OBJ]:
Source listing [NUL.LST]:
Cross-reference [NUL.CRF]:
C:\TASM>debug an16add.exe
-g
C:\TASM>
RESULT:
Thus the assembly language program for 16-bit addition using masm was executed
and verified successfully.
ALGORITHM:
Initialize the address register.
Get the subtrahend and minuend numbers from memory with carry and store it in a register
pair.
Subtract the contents of the register pair.
Store the difference and borrow in memory locations.
PROGRAM:
data segment
a dw 9A88h
b dw 8765h
c dw ?
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ax,a
mov bx,b
sub ax,bx
mov c,ax
int 3
code ends
end start
Output
C:\TASM>masm an16sub.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.
Object filename [an16sub.OBJ]:
Source listing [NUL.LST]:
Cross-reference [NUL.CRF]:
0 Warning Errors
0 Severe Errors
C:\TASM>link an16sub.obj
C:\TASM>debug an16sub.exe
-g
C:\TASM>
RESULT:
Thus the assembly language program for 16-bit subtraction using masm was
executed and verified successfully.
20.Multiplication of 16-bit numbers
AIM:
To write an assembly language program to multiply two 16-bit numbers using masm.
ALGORITHM:
Initialize the address register.
Load the contents of AX and BX register from SI index register.
Multiply the values of AX and BX.
Store the result in memory location using DI register.
PROGRAM:
data segment
a dw 1234h
b dw 5678h
c dd ?
data ends
code segment
assume ds:data, cs:code
start:
mov ax,data
mov ds,ax
mov ax,a
mov bx,b
mul bx
mov word ptr c,ax
mov word ptr c+2,dx
int 3
code ends
end start
Output
C:\TASM>masm an16mul.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.
0 Warning Errors
0 Severe Errors
C:\TASM>link an16mul.obj
C:\TASM>debug an16mul.exe
-g
RESULT:
Thus the assembly language program for 16-bit multiplication using masm was
executed and verified successfully.
21.Division of 16-bit numbers
AIM:
To write an assembly language program to divide two 16-bit numbers using 8086 and store
the result in memory.
ALGORITHM:
Initialize the address register.
Load the contents of AX and CX register from SI index register.
Divide the values of AX and CX.
Store the result in memory location.
PROGRAM:
data segment
a dw 4444h
b dw 0002h
c dw ?
data ends
code segment
assume ds:data, cs:code
start:
mov ax,data
mov ds,ax
mov ax,a
mov bx,b
div bx
mov c,ax
int 3
code ends
end start
Output
C:\TASM>masm an16div.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.
0 Warning Errors
0 Severe Errors
C:\TASM>link an16div.obj
C:\TASM>debug an16div.exe
-g
C:\TASM>
RESULT:
Thus the assembly language program for 16-bit division using masm was executed
and verified successfully.