0% found this document useful (0 votes)
230 views

Micro

The program renames an existing file named "hello.txt" by: 1. Prompts the user to enter data into a buffer 2. Opens the existing file "hello.txt" for reading and writing 3. Writes the buffered data to the opened file 4. Closes the file

Uploaded by

jagan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
230 views

Micro

The program renames an existing file named "hello.txt" by: 1. Prompts the user to enter data into a buffer 2. Opens the existing file "hello.txt" for reading and writing 3. Writes the buffered data to the opened file 4. Closes the file

Uploaded by

jagan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 43

1.

Write an 8086 ALP to perform multiplication of two 8-bit


hexadecimal numbers. Use successive addition and add & shift
method.

I) USING SUCCESSIVE ADDITION:

CODE:
.model small

.data

a db 14H

b db 10H

.code

mov ax, @data ; Initialize data section mov

ds, ax

mov al, a ; Load number1 in al mov

bl, b ; Load number2 in bl mov ah, 0

mov dx, 0 ; intialize result

ad: add dx, ax ; add numbers. Result in dx

dec bl ; dec number

cmp bl, 0; Flowchart 11

jnz ad
mov ch, 04h ; Count of digits to be displayed

mov cl, 04h ; Count to roll by 4 bits

mov bx, dx ; Result in reg bx

l2: rol bx, cl ; roll bl so that msb comes to lsb

mov dl, bl ; load dl with data to be displayed

and dl, 0fH ; get only lsb

cmp dl, 09 ; check if digit is 0-9 or letter A-F

jbe l4

add dl, 07 ; if letter add 37H else only add 30H

l4: add dl, 30H

mov ah, 02 ; Function 2 under INT 21H (Display character)

int 21H

dec ch ; Decrement Count

jnz l2

mov ah, 4cH ; Terminate Program

int 21H

end
USING ADD AND SHIFT METHOD:

CODE:

.model small
.data

a db 12H

b db 10H

.code

mov ax, @data ; Initialize data section mov

ds, ax

mov al, a ; Load number1 in al mov

bl, b ; Load number2 in bl mov ah, 0

mov dl, 04h ; initialize counter

ad: add ax, ax ; add numbers. Result in dx

rcl bl, 01

jnc skip

add ax, bx

skip: dec dl ; dec number

jnz ad
mov ch, 04h ; Count of digits to be

; displayed

mov cl, 04h ; Count to roll by 4 bits

mov bx, ax ; Result in reg bx

l2: rol bx, cl ; roll bl so that msb

; comes to lsb

mov dl, bl ; load dl with data to be

; displayed

and dl, 0fH ; get only lsb

cmp dl, 09 ; check if digit is 0-9 or

; letter A-F

jbe l4

add dl, 07 ; if letter add 37H else only

; add 30H

l4: add dl, 30H

mov ah, 02 ; Function 2 under INT 21H

; (Display character)

int 21H

dec ch ; Decrement Count


jnz l2

mov ah, 4cH ; Terminate Program

int 21H

end
1.Write an alp to sort in ascending order using bubble sort algorithm that
lets the user type a given set of byte sized unsigned numbers in memory.
The sorted elements should replace the original unsorted elements in
memory.

CODE :

org 100h
.data
str db 10,13,"Enter Values: $"
str1 db 0dh,0ah,"Bubble Sorted: $" array db
10dup(0)
.code mov
ah,9 lea
dx,str int
21h
mov cx,10
mov bx,offset array
mov ah,1
inputs: int
21h
mov [bx],al
inc bx Loop
inputs mov
cx,10 dec cx
nextscan:
mov bx,cx
mov si,0
nextcomp:
mov al,array[si] mov
dl,array[si+1] cmp al,dl
jc noswap
mov array[si],dl mov
array[si+1],al noswap:
inc si
dec bx
jnz nextcomp

loop nextscan
mov ah,9
lea dx,str1 int
21h mov
cx,10
mov bx,offset array
; this loop to display elements on the screen print:
mov ah,2 mov
dl,[bx] int 21h
inc bx
loop print
ret

1.Write an 8086 alp to search for a given 16 bit value using binary search in an
array of 16 bit numbers, which are in sorted. Display the status in any one of the
registers (found or not). If the element is found the position of the element in
the array is to be displayed.

CODE:
DATA SEGMENT
ARR DW
0000H,1111H,2222H,3333H,4444H,5555H,6666H,7777H,8888H,9999H
LEN DW ($-ARR)/2
KEY EQU 7777H
MSG1 DB "KEY IS FOUND
AT " RES DB "
POSITION",13,10," $" MSG2
DB 'KEY NOT FOUND!!!.$'
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA
CS:CODE START:
MOV
AX,DATA
MOV DS,AX

MOV BX,00
MOV DX,LEN
MOV CX,KEY
AGAIN: CMP
BX,DX JA FAIL
MOV
AX,BX
ADD
AX,DX
SHR AX,1
MOV
SI,AX
ADD SI,SI
CMP
CX,ARR[SI]
JAE BIG
DEC AX
MOV
DX,AX
JMP
AGAIN
BIG: JE
SUCCESS INC
AX
MOV
BX,AX
JMP
AGAIN
SUCCESS: ADD
AL,01 ADD AL,'0'
MOV RES,AL
LEA
DX,MSG1
JMP DISP
FAIL: LEA
DX,MSG2 DISP:
MOV AH,09H
INT 21H

MOV AH,
4CH INT 21H
CODE ENDS
END START
Write an ALP to convert the given hexadecimal number to binary and perform 2’s complement of the
resultant. a) 9CH b) 8BE2H

Sol).

a). 9CH
CODE :

DATA SEGMENT

STR1 DB "BINARY NUMBER IS : $"


STR2 DB "DECIMAL NUMBER IS : $"
BSTR DB 20 DUP("$")

RSTR DB 20 DUP("$")
NEWLINE DB 13,10,"$"
CNT DB 0
N DB 2

H DB 16
D DB 10H
NUM DB ?
SNUM DB ?
HNUM DB 9CH

DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:

MOV
AX,DATA
MOV DS,AX
;CONVERT HEXA TO DECIMAL

MOV CX,00
MOV DX,00

L6:MOV AX,00
MOV AL,HNUM
DIV D

MOV HNUM,AL

MOV BX,AX
MOV CL,CNT
MOV AX,1

L5: CMP CL,00


JE L7
MUL H
SUB CL,1
JMP L5

L7: MUL BH
ADD
DX,AX
ADD CNT,1
CMP HNUM,0
JG L6

MOV NUM,DL

;CONVERT DECIMAL TO
BINARY LEA SI,BSTR
LEA DI,RSTR
L1: MOV AX,00

MOV AL,NUM
DIV N
ADD AH,30H

MOV BYTE
PTR[SI],AH INC SI
MOV NUM,AL
CMP AL,0

JG L1

DEC SI

L2:MOV BL,BYTE
PTR[SI] MOV BYTE
PTR[DI],BL
DEC SI
INC DI
CMP SI,0
JNE L2

MOV AH,09H
LEA DX,STR1
INT 21H

MOV AH,09H
LEA DX,RSTR
INT 21H

MOV AH,4CH
INT 21H

CODE ENDS

END START
a). 8BE2H
dosseg

.model small

.stack 100h

.data

msgstar db
0dh,0ah,0dh,0ah,"***************************",0dh,0ah,"$" msgintro
db " PROGRAM FUNCTION",0dh,0ah,
" TO CONVERT HEXADECIMAL
NUMBER INTO BINARY NUMBER","$"

msginput db 0dh,0ah,"Your HEXADECIMAL INPUT (MAXIMUM FF)


:",0dh,0ah,"$"

msgafter db 0dh,0ah,"Your INPUT AFTER CONVERT INTO BINARY :


",0dh,0ah,"$"

msgagain db 0dh,0ah,0dh,0ah,"DO YOU WANT TO TRY AGAIN


?",0dh,0ah,"PRESS (y OR Y) TO TRY AGAIN,PRESS OTHER KEY TO
TERMINATE:",0dh,0ah,"$"

msgmax db 0dh,0ah,0dh,0ah,"YOUR INPUT HAD REACH


MAXIMUM 8 DIGITS / BIT , CALCULATION WILL START NOW",0dh,0ah,"$"

blank db 0dh,0ah,"$"

error db 0dh,0ah,"INVALID INPUT, ONLY 1 AND 0 IS ALLOW. PROGRAM


WILL TERMINATE NOW.",0dh,0ah,"$"

print dw 0

count dw 0

num dw 0

.code
main proc

mov ax,@data
mov ds,ax

mov ax,0
mov bx,0
mov cx,0
mov dx,0

mov print,0 ; reset evrything used in program to makesure the calculation


will be correct

mov count,0; after user request repeat mov


num,0

mov dx,offset msgstar ;display start (decoration) mov ah,9


int 21h

mov dx,offset msgintro ;display intro message mov ah,9


int 21h

mov dx,offset msgstar ;display start (decoration) mov ah,9

int 21h
mov dx,offset msginput ;display input message mov
ah,9

int 21h

mov cx,-1 ; assign -1 into cx to act as counter

input: mov ah, 00h

int 16h

cmp ah, 1ch


je exit

number: cmp al, '0'

jb input cmp
al, '9'
ja uppercase sub
al, 30h call
process jmp
input

uppercase: cmp al, 'A'

jb input
cmp al, 'F'
ja lowercase
sub al, 37h
call process
jmp input

lowercase: cmp al, 'a'

jb input cmp
al, 'f' ja input
sub al, 57h
call process
jmp input
loop input

process: mov ch, 4

mov cl, 3
mov bl, al

convert: mov al, bl

ror al, cl and


al, 01 add al,
30h mov ah,
02h mov dl, al
int 21h

dec cl
dec ch

jnz convert
mov dl, 20h
int 21h
ret exit:

int 20h

main EndP
end main

2s complement code for 9CH:

Data Segment
num db B Data
Ends

Code Segment

Assume cs:code, ds:data

Begin:

mov ax, data


mov ds, ax mov
es, ax mov ah,
0000h mov al,
num NOT al

mov bl, al

adc al, 00000001B


mov bl, al

Exit:

mov ax, 4c00h


int 21h

Code End

End Begin

2s complement code for 8BE2H:

Data Segment
num db B Data
Ends

Code Segment
Assume cs:code, ds:data

Begin:

mov ax, data


mov ds, ax mov
es, ax mov ah,
0000h mov al,
num NOT al

mov bl, al

adc al, 00000001B


mov bl, al

Exit:

mov ax, 4c00h


int 21h

Code Ends
End Begin
A.Write an ALP to rename an existing file named “hello.txt”. CODE:
DATA SEGMENT
MES DB 10,13,'ENTER SOME DATA IN THE FILE$' FILENAME DB
'HELLO.TXT'
BUFFER DB 22 DUP(0)
MES1 DB 10,13, 'ERROR IN FILE HANDLING$' DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
MOV AH,09H
LEA DX,MES
INT 21H
MOV BUFFER,20
MOV AH,0AH
MOV DX,OFFSET BUFFER INT
21H
MOV AH,3CH
MOV CX,0
MOV DX,OFFSET FILENAME INT
21H
MOV BX,AX
MOV AH,40H
MOV CX,20
MOV DX, OFFSET BUFFER INT
21H
JC ERROR JMP
EXIT
ERROR:MOV DX,OFFSET MES1 MOV
AH,09
INT 21H EXIT:MOV
AH,4CH
INT 21H CODE ENDS END START
b. Write an 8086 ALP which will input the organization name from the
keyboard. If the name is ‘VIT’ it will output “Permission granted” else it
will display the message “Wrong details” using DOS Interrupt.
CODE:
DATA SEGMENT
MSG1 DB 10,13,"INPUT ORGANISATION : $" MSG2
DB 10,13,"WRONG DETAILS $"
MSG3 DB 10,13,"PERMISSION GRANTED $" STR1

DB "VIT"

P1 LABEL BYTE
M1 DB 0FFH L1
DB ?
P11 DB 0FFH DUP ('$')
DATA ENDS

DISPLAY MACRO MSG


MOV AH,9
LEA DX,MSG
INT 21H
ENDM

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX

DISPLAY MSG1

LEA DX,P1
MOV AH,0AH
INT 21H

LEA SI,STR1
LEA DI,P11

MOV CX,3
CHECK: MOV
AL,[SI] CMP
[DI],AL
JNE NOPASWD
INC SI
INC DI
LOOP CHECK

DISPLAY MSG3
JMP EXIT

NOTEQUAL:
DISPLAY MSG4

NOPASWD:
DISPLAY MSG2
JMP EXIT

EXIT: MOV AH,4CH INT


21H
CODE ENDS
END START
a. Write an ALP to perform the Transpose of a 3 * 3 Matrix
TRANSPOSE OF THE MATRIX

DATA SEGMENT
M1 DB 'ENTER THE ORDER OF THE MATRIX:','$'
M2 DB 0AH,0DH,0AH,'ENTER THE CONTENT OF THE
MATRIX:','$' M3 DB 0AH,0DH,0AH,'TRANSPOSE
MATRIX:',0AH,0DH,'$'
MAT1 DB 10
DUP(0) MAT2
DB 10 DUP(0)
ROW DB 00H
COL DB
00H DATA
ENDS
MESSAGE MACRO
MESS LEA
DX,MESS
MOV
AH,09H INT
21H ENDM
BSPCE MACRO
ASC MOV
DL,ASC MOV
AH,06H INT
21H
ENDM
CODE SEGMENT
ASSUME
CS:CODE,DS:DATA
START:MOV
AX,DATA
MOV DS,AX
MESSAGE
M1 CALL
READO
MOV BX,DX
MOV
ROW,DH
MOV
COL,DL
MESSAGE
M2 LEA
SI,MAT1
CALL
READ1 LEA
DI,MAT1
LEA
SI,MAT2
MOV
DH,00H
MOV
DL,COL
MOV
AH,COL
L3:MOV
AL,ROW MOV
BX,DI L1:MOV
CL,[BX] MOV
[SI],CL ADD
BX,DX
INC SI
DEC
AL JNZ
L1 INC
DI DEC
AH
JNZ L3
LEA
SI,MAT2
CALL DISP
MOV
AH,4CH INT
21H
READO PROC
NEAR MOV
AH,01H INT
21H
MOV
DH,AL
SUB
DH,30H
BSPCE ' '
MOV
AH,01H
INT 21H
MOV
DL,AL
SUB
DL,30H
RET
READO ENDP
READ1 PROC
NEAR
BSPCE 0AH
MOV
CH,ROW
N2:MOV
BH,COL
N1:CALL
READ
MOV
[SI],DL
INC SI
BSPCE ' '
DEC BH
JNZ
N1
DEC
CH JZ
N3
BSPCE
0AH
BSPCE
0DH JMP
N2
N3:RET
READ1
ENDP
READ PROC
NEAR MOV
AH,01H
INT 21H
MOV
CL,04H
MOV
DL,AL SUB
DL,30H
CMP
DL,0AH JC
R1
SUB
DL,07H
AND
DL,0FH
R1:SHL
DL,CL MOV
AH,01H INT
21H
SUB
AL,30H
CMP AL,
0AH JC R2
SUB
AL,07H
AND
AL,0FH
R2:OR
DL,AL RET
READ ENDP
DISP PROC
NEAR
MESSAGE M3
BSPCE 0AH
MOV DH,COL
D4:MOV
BH,ROW
LOP:MOV
CL,04H MOV
DL,[SI]
SHR DL,CL
CMP
DL,0AH JC
D1
ADD DL,07H
D1: ADD
DL,30H MOV
AH,06H INT
21H
MOV
DL,[SI]
AND
DL,0FH
CMP
DL,0AH JC
D2
ADD DL,07H
D2: ADD DL,30H
MOV
AH,06H INT
21H
INC SI
BSPCE '
' DEC
BH JNZ
LOP
DEC DH
JZ D3
BSPCE
0AH
BSPCE
0DH JMP
D4
D3:
RET DISP
ENDP CODE
ENDS
END START

b. Write an ALP (Using Interrupt)


1. To read a character from the keyboard in module X(any different
file)
2. To display a character in module Y(from different file)
3. Use the above module X & module Y to read a string of characters
from the keyboard and display the string in the next line.

2a2.Display macro
disp macro
mov ah,02h
int 21h
endm

2a.Main program
Title String read and display using macros stored in different files

include 2a1.asm
include 2a2.asm

.model small

.data
loc db 100 dup(0)
st0 db 13,10,"Enter a string",13,10,'$'
st1 db 13,10,"Entered string is $"

.code
start: mov ax,@data
mov ds,ax
mov cl,00h
lea bx,loc
lea dx,st0
mov ah,09h
int 21h
lea si,loc
rd: read
cmp al,08h
je new
cmp al,0dh
je print
mov [si],al
inc si
jmp rd
new: mov dl,' '
disp
mov dl,08h
disp
cmp si,bx
je rd
dec si
jmp rd
print: mov al,'$'
mov [si],al
lea dx,st1
mov ah,09h
int 21h
lea si,loc
pri: mov
dl,[si]
cmp
dl,'$' je
ter
disp
inc
si
jmp
pri
ter: mov
ah,4ch
int 21h
end start

You might also like