MP Lab

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 54

1.

Assembly language program to Addition


Program Name of two 16 bit numbers
Author
Software TASM
Platform
Microprocessor 8086

Assume cs:code,ds:data

Data segment
Org 50h
n1 dw 1234h
n2 dw 1234h
res dw ?
Data ends
Code segment
Start: mov ax,data
mov ds,ax
mov ax,0000h
mov ax,n1
mov bx,n2
add ax, bx
MOV RES, AX
hlt
code ends
end start
MICROPROCESSOR LAB
Result:
Input Output
Memory data Memory Data
location
2000 34h location
2004 68h
2001 12h 2005 24h
2002 34h
2003 12h

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB

2.Assembly language program to Addition


Program Name of two 8 bit numbers
Author
Software TASM
Platform
Microprocessor 8086

Assume cs:code,ds:data
Data segment
Org 2000h
n1 db 34h
n2 db 23h
res db ?
Data ends
Code segment
Start: mov ax,data
mov ds,ax
mov ax,0000h
mov al,n1
mov bl,n2
add al,bl
mov res,al
hlt
code ends
end start

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
Result:

Input Output
Memory data Memory Data
location
2000 34h location
2002 57h
2001 23h

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB

3.Assembly language program to


Program Name subtraction of two 16 bit numbers
Author
Software TASM
Platform
Microprocessor 8086

Assume cs:code,ds:data
Data segment
Org 2000h
n1 dw 1234h
n2 dw 1234h
res dw ?
Data ends
Code segment
Start: mov ax,data
mov ds,ax
mov ax,0000h
mov ax,n1
mov bx,n2
sub ax,bx
mov res,ax
hlt
code ends
end start

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
Result:
Input Output
Memory data Memory Data
location
2000 34h location
2004 00h
2001 12h 2005 00h
2002 34h
2003 12h

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB

4.Assembly language program to


Program Name subtraction of two 8 bit numbers
Author
Software TASM
Platform
Microprocessor 8086

Assume cs:code,ds:data
Data segment
Org 2000h
n1 db 34h
n2 db 23h
res db ?
Data ends
Code segment
Start: mov ax,data
mov ds,ax
mov ax,0000h
mov al,n1
mov bl,n2
sub al,bl
mov res,al
hlt
code ends
end start

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
Result:
Input Output
Memory data Memory Data
location
2000 34h location
2002 22h
2001 12h

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
5.Assembly language program to
Program Name multiplication of two 16 bit numbers
Author
Software TASM
Platform
Microprocessor 8086

Assume cs:code,ds:data
Data segment
Org 2000h
n1 dw 1111h
n2 dw 1111h
res dw ?
Data ends
Code segment
Start: mov ax,data
mov ds,ax
mov ax,0000h
mov dx,0000h
mov ax,n1
mov bx,n2
mul bx
mov res,ax
mov [res+2],dx
hlt
code ends
end start

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
Result:
Input Output
Memory data Memory Data
location
2000 11h location
2004 21h
2001 11h 2005 43h
2002 11h 2006 23h
2003 11h 2007 01h

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB

6.Assembly language program to


Program Name multiplication of two 8 bit numbers
Author
Software TASM
Platform
Microprocessor 8086

Assume cs:code,ds:data
Data segment
Org 2000h
n1 db 11h
n2 db 11h
res dw ?
Data ends
Code segment
Start: mov ax,data
mov ds,ax
mov ax,0000h
mov al,n1
mov bl,n2
mul bl
mov res,ax
hlt
code ends
end start

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
Result:

Input Output
Memory data Memory Data
location
2000 11h location
2002 21h
2001 11h 2003 01h

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
7.Assembly language program to division
Program Name of two 16 bit numbers
Author
Software TASM
Platform
Microprocessor 8086

Assume cs:code,ds:data
Data segment
Org 2000h
n1 dw 0042h
n2 dw 0007h
res dw ?
Data ends
Code segment
Start: mov ax,data
mov ds,ax
mov ax,0000h
mov ax,n1
mov bx,n2
div bx
mov res,ax
hlt
code ends
end start

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
Result:
Input Output
Memory data Memory Data
location
2000 42h location
2004 06h
2001 00h 2005 00h
2002 07h
2003 00h

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB

8.Assembly language program to division


Program Name of two 8 bit numbers
Author
Software TASM
Platform
Microprocessor 8086

Assume cs:code,ds:data
Data segment
Org 2000h
n1 db 04h
n2 db 02h
res db ?
Data ends
Code segment
Start: mov ax,data
mov ds,ax
mov ax,0000h
mov al,n1
mov bl,n2
div bl
mov res,al
hlt
code ends
end start

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
Result:

Input Output
Memory data Memory Data
location
2000 04h location
2002 02h
2001 02h

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB

9.Assembly language program to addition


Program Name of two 32 bit numbers
Author
Software TASM
Platform
Microprocessor 8086

assume cs:code,ds:data
data segment
Org 2000h
no1 dd 12344321h
no2 dd 42224444h
result dd ?
data ends
code segment
start: mov ax,data
mov ds,ax
xor ax,ax
mov ax,word ptr no1
add ax,word ptr no2
mov dx,ax
mov ax,word ptr[no1+2]
adc ax,word ptr[no2+2]
mov word ptr result,ax
mov word ptr [result+2],dx
hlt
code ends
end start

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
Result:

Input Output
Memory Data Memory Data
location
2000 21h location
2008 65h
2001 43h 2009 87h
2002 34h 200A 56h
2003 12h 200B 54h
2004 44h
2005 44h
2006 22h
2007 42h

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB

10.Assembly language program to


Program Name subtraction of two 32 bit numbers
Author
Software TASM
Platform
Microprocessor 8086

assume cs:code,ds:data
data segment
Org 2000h
no1 dd 84326444h
no2 dd 42224444h
result dd ?
data ends
code segment
start: mov ax,data
mov ds,ax
xor ax,ax
mov ax,word ptr no1
sub ax,word ptr no2
mov dx,ax
mov ax,word ptr[no1+2]
sbb ax,word ptr[no2+2]
mov word ptr result,ax
mov word ptr [result+2],dx
hlt
code ends
end start

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
Result:

Input Output
Memory Data Memory Data
location
2000 44h location
2008 00h
2001 64h 2009 20h
2002 32h 200A 10h
2003 84h 200B 42h
2004 44h
2005 44h
2006 22h
2007 42h

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB

11.Assembly language program to


Program Name multiplication of two 32 bit numbers
Author
Software TASM
Platform
Microprocessor 8086

assume cs:code,ds:data
data segment
org 2000h
no1 dd 11111111h
no2 dd 11111111h
result dd ?
data ends
code segment
start:mov ax,data
mov ds,ax
xor ax,ax
mov ax,word ptr no1
mul word ptr no2
mov word ptr result,ax
mov word ptr [result+2],dx
xor ax,ax
xor dx,dx
mov ax,word ptr no1
mul word ptr[no2+2]
add ax,word ptr[result+2]
mov word ptr[result+2],ax
mov word ptr[result+4],dx
xor ax,ax
xor dx,dx
mov ax,word ptr[no1+2]
mul word ptr no2
add ax,word ptr[result+2]
mov word ptr[result+2],ax

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
mov cx,dx
xor ax,ax
xor dx,dx
mov ax,cx
add ax,word ptr[result+4]
mov word ptr[result+4],ax
xor ax,ax
xor bx,bx
mov ax,word ptr[no1+2]
mul word ptr[no2+2]
add ax,word ptr[result+4]
mov word ptr[result+4],ax
mov word ptr[result+6],dx
hlt
code ends
end start

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
Result:

Input Output
Memory Data Memory Data
location
2000 11h location
2008 21H
2001 11h 2009 43H
2002 11h 200A 65H
2003 11h 200B 87H
2004 11h 200C 67H
2005 11h 200D 45H
2006 11h 200E 23H

2007 11h 200F 01H

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB

12. Assembly language program to move 5


Program Name bytes of data using indirect addressing.
Author
Software TASM
Platform
Microprocessor 8086

assume cs:code,ds:data
data segment
org 2000h
list db 05h,12h,99h,68h,50h
result db 05h dup(0)
data ends
code segment
start: mov ax,data
mov ds,ax
mov cx,05h
mov si,offset list
mov di,offset result
back:mov al,[si]
mov [di],al
inc si
inc di
loop back
hlt
code ends
end start

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
Result:
Input Output
Memory Data Memory Data
location
2000 05h location
2005 05h
2001 12h 2006 12h
2002 99h 2007 99h
2003 68h 2008 68h
2004 50h 2009 50h

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB

13.Assembly language program to packing


Program Name of three BCD numbers.
Author
Software TASM
Platform
Microprocessor 8086

assume cs:code,ds:data
data segment
org 2000h
n1 dw 0305h,0901h,0102h
n2 db ?
data ends
code segment
start:mov ax,data
mov ds,ax
mov cx,03
mov si,offset n1
mov di,offset n2
back:mov ax,[si]
rol ah,1
rol ah,1
rol ah,1
rol ah,1
add al,ah
mov [di],al
inc si
inc si
inc di
loop back
hlt
code ends
end start

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB

Result:

Input Output
Memory Data Memory Data
location
2000 05h location
2006 35h
2001 03h 2007 91h
2002 01h 2008 12h
2003 09h
2004 02h
2005 01h

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB

14.Assembly language program to factorial


Program Name of given number
Author
Software TASM
Platform
Microprocessor 8086

assume cs:code,ds:data
data segment
org 0000h
n1 db 05h
res db ?
data ends
code segment
start: mov ax,data
mov ds,ax
mov ax,0000
mov cl,05
mov al,01h
mov bl,n1
back:mul bl
dec bl
loop back
mov res,al
hlt
code ends
end start

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
Result:

Input Output
Memory Data Memory Data
location
2000 05h location
2001 78h

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB

15.Assembly language program to next


Program Name number in a fobinacci series
Author
Software TASM
Platform
Microprocessor 8086

assume cs:code,ds:data
data segment
org 2000h
n1 db 05h
res db ?
data ends
code segment
start: mov ax,data
mov ds,ax
mov al,01h
mov bl,01h
mov si,offset res
mov [si],al
inc si
mov [si],bl
mov cl,n1
l1:inc si
mov dl,bl
add bl,al
mov al,dl
mov [si],bl
loop l1
hlt
code ends
end start

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB

Result:

Input Output
Memory 2000 2001 2002 2003 2004 2005 2006
location
Data 01h 01h 02h 03h 05h 08h 0Dh

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB

16.Assembly language program to square


Program Name root of a given number
Author
Software TASM
Platform
Microprocessor 8086
assume cs:code,ds:data
data segment
org 1000h
n1 dw 0025h
res dw ?
data ends
code segment
start:mov ax,data
mov ds,ax
mov bx,01h
mov cl,04h
l1:mov ax,bx
mul bx
mov dx,n1
cmp ax,dx
je l2
inc bx
loop l1
l2:mov res,bx
hlt
code ends
end start

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
Result:
Input Output
Memory Data Memory Data
location
1000 25h location
1001 05h

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB

17.Assembly language program to find the


Program Name largest number in array
Author
Software TASM
Platform
Microprocessor 8086

ASSUME CS: CODE, DS: DATA


DATA SEGMENT
COUNT EQU 2000H
NUM EQU 2050H
RESULT EQU 3000H
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV SI, COUNT
MOV DL, [SI]
DEC DL
MOV SI, NUM
YY: MOV AL, [SI]
CMP AL, [SI+1]
JB ZZ
XCHG AL, [SI+1]
MOV [SI], AL
ZZ: INC SI
DEC DL
JNZ YY
MOV BL, [SI]
MOV SI, RESULT
MOV [SI], BL
INT 03H
CODE ENDS
END START

GPT MASABTANK, TELANGANA STATE


RESULT:
18.Assembly language program to sort the
Program Name numbers in ascending order
Author
Software TASM
Platform
Microprocessor 8086

ASSUME DS:DATA,CS:CODE
DATA SEGMENT
STRING1 DB 99H,12H,56H,45H,36H
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV CH,04H
UP2: MOV CL,04H
LEA SI,STRING1
UP1: MOV AL,[SI]
MOV BL,[SI+1]
CMP AL,BL
JC DOWN
MOV DL,[SI+1]
XCHG [SI],DL
MOV [SI+1],DL

DOWN: INC SI
DEC CL
JNZ UP1
DEC CH
JNZ UP2

INT 3
CODE ENDS

END START
RESULT
19. 8086 ASSEMBLY
PROGRAM TO PRINT ‘HELLO’
USING 09H
data segment
msg1 db 'hello$'
data ends

code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov sp,0d00h
mov ah,09h
int 21h
mov ax,4c00h
int 21h
int 3
code ends
end start
RESULT:
20. 8086 ASSEMBLY
PROGRAM TO SEARCH AN
ELEMENT IN AN ARRAY
DATA SEGMENT
STRING1 DB 11H,22H,33H,44H,55H
MSG1 DB "FOUND$"
MSG2 DB "NOT FOUND$"
SE DB 33H
DATA ENDS

PRINT MACRO MSG


MOV AH, 09H
LEA DX, MSG
INT 21H
INT 3
ENDM

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AL, SE
LEA SI, STRING1
MOV CX, 04H

UP:
MOV BL,[SI]
CMP AL, BL
JZ FO
INC SI
DEC CX
MICROPROCESSOR LAB
JNZ UP
PRINT MSG2
JMP END1

FO:
PRINT MSG1

END1:
INT 3
CODE ENDS
END START

GPT MASABTANK, TELANGANA STATE


RESULT:
21. 8086 ASSEMBLY
PROGRAM TO FIND REVERSE
OF AN ARRAY
DATA SEGMENT
STR1 DB 01H,02H,05H,03H,04H
STR2 DB 5 DUP(?)
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
LEA SI, STR1
LEA DI, STR2+4
MOV CX, 05H

BACK: CLD
MOV AL, [SI]
MOV [DI], AL
INC SI
DEC DI
DEC CX
JNZ BACK

INT 3
CODE ENDS
END START
RESULT:
22. 8086 ASSEMBLY
PROGRAM TO FIND LARGEST
NUMBER FROM GIVEN
NUMBERS
data segment
STRING1 DB 08h,14h,05h,0Fh,09h
res db ?
data ends

code segment
assume cs:code, ds:data
start: mov ax, data
mov ds, ax
mov cx, 04h

mov bl, 00h


LEA SI, STRING1
up:
mov al, [SI]
cmp al, bl
jl nxt
mov bl, al
nxt:
inc si
dec cx
jnz up

mov res,bl
int 3
code ends
end start
RESULT:
RE23. 8086 ASSEMBLY
PROGRAM TO COUNT NUMBER
OF 0’S AND 1’S FROM A
NUMBER
DATA SEGMENT
NO DW 5648H
Z DW ?
O DW ?
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AX, NO
MOV BX, 00H
MOV CX, 10H
MOV DX, 00H

UP:
ROL AX,1
JC ONE
INC BX
JMP NXT

ONE:
INC DX

NXT:
DEC CX
JNZ UP
MICROPROCESSOR LAB
MOV Z, BX
MOV O, DX

INT 3
CODE ENDS
END START

GPT MASABTANK, TELANGANA STATE


RESULT:
24. 8086 ASSEMBLY
PROGRAM TO SORT NUMBERS
IN DESCENDING ORDER
DATA SEGMENT
STRING1 DB 99H,12H,56H,45H,36H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV CH,04H
UP2: MOV CL,04H
LEA SI,STRING1

UP1:MOV AL,[SI]
MOV BL,[SI+1]
CMP AL,BL
JNC DOWN
MOV DL,[SI+1]
XCHG [SI],DL
MOV [SI+1],DL

DOWN: INC SI
DEC CL
JNZ UP1
DEC CH
JNZ UP2
INT 3
CODE ENDS
END START
25. 8086 ASSEMBLY
PROGRAM TO CHECK IF
STRING IS PALINDROME OR
NOT
DATA SEGMENT

BLOCK1 DB 'MALAYALAM'
MSG1 DB "IT IS PALINDROME $"
MSG2 DB "IT IS NOT PALINDROME $"
PAL DB 00H

DATA ENDS

PRINT MACRO MSG

MOV AH,09H
LEA DX,MSG
INT 21H
INT 3H

ENDM

EXTRA SEGMENT

BLOCK2 DB 9 DUP(?)
EXTRA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:EXTRA
START: MOV AX,DATA
MOV DS,AX
MICROPROCESSOR LAB
MOV AX,EXTRA
MOV ES,AX
LEA SI,BLOCK1
LEA DI,BLOCK2+8
MOV CX,00009H
BACK: CLD
LODSB
STD
STOSB
LOOP BACK
LEA SI,BLOCK1
LEA DI,BLOCK2
MOV CX,0009H
CLD
REPZ CMPSB
JNZ SKIP
PRINT MSG1
SKIP: PRINT MSG2
CODE ENDS
END START

GPT MASABTANK, TELANGANA STATE


MICROPROCESSOR LAB
RESULT:

GPT MASABTANK, TELANGANA STATE

You might also like