Co Programs For Lab

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 36

Programs

MASM filenam.asm; = MASM add1.asm;

LINK filename.obj; = LINK add1.obj;

DEBUG filename.exe; = DEBUG add1.exe;


U = unassemble
T = trace (single step execution)

G = go ( total program execution)

D ds:0000
8 - bit Addition

Assume cs : code, ds :data


data segment
num1 db 05H
num2 db 02H
res db ?
data ends
code segment
start: MOV AX, data
MOV DS ,AX
MOV AX, 0000H
MOV AL ,num1
MOV BL,num2
ADD AL,BL
MOV res,AL
INT 3H
code ends
end start
8 – bit Subtraction
Assume cs : code, ds :data
data segment
num1 db 05H
num2 db 02H
res db ?
data ends
code segment
start: MOV AX, data
MOV DS ,AX
MOV AX, 0000H
MOV AL ,num1
MOV BL,num2
SUB AL,BL
MOV res,AL
INT 3H
code ends
end start
8 - bit Multiplication

Assume cs : code, ds :data


data segment
num1 db 04H
num2 db 02H
res dw ?
data ends
code segment
start: MOV AX, data
MOV DS ,AX
MOV AX, 0000H
MOV AL ,num1
MOV BL,num2
MUL BL
MOV res,AX
INT 3H
code ends
end start
8 - bit Division
Assume cs : code, ds :data
data segment
num1 db 05H
num2 db 02H
quo db ?
rem db ?
data ends
code segment
start: MOV AX, data
MOV DS ,AX
MOV AX, 0000H
MOV AL ,num1
MOV BL,num2
DIV BL
MOV quo ,AL
MOV rem, AH
INT 3H
code ends
end start
16 - bit Addition

Assume cs : code, ds :data


data segment
num1 dw 4215H
num2 dw 3202H
res dw ?
data ends
code segment
start: MOV AX, data
MOV DS ,AX
MOV AX, 0000H
MOV AX ,num1
MOV BX,num2
ADD AX,BX
MOV res,AX
INT 3H
code ends
end start
16– bit Subtraction
Assume cs : code, ds :data
data segment
num1 dw 7505H
num2 dw 4602H
res dw ?
data ends
code segment
start: MOV AX, data
MOV DS ,AX
MOV AX, 0000H
MOV AX ,num1
MOV BX,num2
SUB AX,BX
MOV res,AX
INT 3H
code ends
end start
16 - bit Multiplication
Assume cs : code, ds :data
data segment
num1 dw 2205H
num2 dw 1102H
res1 dw ?
res2 dw ?
data ends
code segment
start: MOV AX, data
MOV DS ,AX
MOV AX, 0000H
MOV AX ,num1
MOV BX,num2
MUL BX
MOV res1,AX
MOV res2, DX
INT 3H
code ends
end start
16 - bit Division
Assume cs : code, ds :data
data segment
num1 dw 6666H
num2 dw 3332H
quo dw ?
rem dw ?
data ends
code segment
start: MOV AX, data
MOV DS ,AX
MOV AX, 0000H
MOV AX ,num1
MOV BX,num2
DIV BX
MOV quo ,AX
MOV rem, DX
INT 3H
code ends
end start
Square of a number

Assume cs : code, ds :data


data segment
num1 db 04H
res db ?
data ends
code segment
start: MOV AX, data
MOV DS ,AX
MOV AX, 0000H
MOV AL ,num1
MUL AL
MOV res,AX
INT 3H
code ends
end start
Cube of Number
Assume cs : code, ds :data
data segment
num1 db 04H
res db ?
data ends
code segment
start: MOV AX, data
MOV DS ,AX
MOV AX, 0000H
MOV AL ,num1
MOV BL,num1
MUL AL
MUL BL
MOV res,AX
INT 3H
code ends
end start
Exchange of a Number
Assume cs : code, ds :data
data segment
num1 db 05H
num2 db 02H
data ends
code segment
start: MOV AX, data
MOV DS ,AX
MOV AX, 0000H
MOV AL ,num1
MOV BL,num2
XCHG AL,BL
INT 3H
code ends
end start
Addition of Series of numbers

Assume cs : code, ds: data


data segment
List db 12h,34h,56h,78h,89h
RES dw ?
data ends
code segment
start:
MOV AX, data
MOV DS,AX
MOV AX,0000h
MOV BX, 0000h
MOVCL,5
MOV SI, offset List
again: MOV BL,[SI]
ADD AL,BL
INC SI
DEC CL
JNZ again
MOV RES ,AX
INT 3h
code ends
end start
Average of Series of numbers

Assume cs : code, ds: data


data segment
List db 12h,34h,56h,78h,89h
RES dw ?
data ends
code segment
start:
MOV AX, data
MOV DS,AX
MOV AX,0000h
MOV BX, 0000h
MOVCL,5
MOV SI, offset List
again: MOV BL,[SI]
ADD AL,BL
INC SI
DEC CL
JNZ again
MOV BL,05 H
DIV BL
MOV RES ,AX
INT 3h
code ends
end start
Sum of squares of given series of numbers
assume cs: code, ds: data
data segment
List db 01h,02h,03h,04h,05h
SUM dw ?
data ends
code segment
start:
MOV AX,data
MOV DS,AX
MOV SI, offset List
MOV Cl , 05H
l1: MOV AX,0000H
MOV AL,[SI]
MUL AL
ADD BX,AX
INC SI
loop l1
MOV SUM ,BX
INT 3H
code ends
end start
Sum of CUBES of given series of numbers
assume cs: code, ds: data
data segment
List db 01h,02h,03h,04h,05h
SUM dw ?
data ends
code segment
start:
MOV AX,data
MOV DS,AX
MOV SI, offset List
MOV Cl , 05H
l1: MOV AX,0000H
MOV AL,[SI]
MOV DL,[SI]
MUL AL
MUL DL
ADD BX,AX
INC SI
loop l1
MOV SUM,BX
INT 3H
code ends
end start
Number of even and odd numbers in list
assume cs:code,ds:data
data segment
list db 01h,02h,03h,04h,05h,06h,07h,08h,09h
od dw ?
eve dw ?
data ends
code segment
start : MOV AX, data
MOV DS,AX
XOR AX,AX
XOR BX,BX
XOR DX,DX
MOV CL,09H
MOV SI, offset list
again: MOV AL,[SI]
ROR AL,01H
JC odd
INC BX
JMP next
odd: INC DX
next: INC SI

DEC CL
JNZ again
MOV od, DX
MOV eve , BX
INT 3H
code ends
end start
Greatest number in list
assume cs: code ,ds: data
data segment
list db 10h,20h,30h,40h,50h
res db ?
data ends
code segment
start:
MOV AX, data
MOV DS,AX
XOR AX,AX
MOV Cl,04H
MOV SI, offset list
MOV AL,[SI]
again: CMP AL,[SI+1]
JNC next
MOV AL, [SI+1]
next: INC SI
DEC CL
JNZ again
MOV res,AL
INT 3h
code ends
end start
Smallest number in list
assume cs: code ,ds: data
data segment
list db 10h,20h,30h,40h,50h
res db ?
data ends
code segment
start:
MOV AX, data
MOV DS,AX
XOR AX,AX
MOV Cl,04H
MOV SI, offset list
MOV AL,[SI]
again: CMP AL,[SI+1]
JC next
MOV AL, [SI+1]
next: INC SI
DEC CL
JNZ again
MOV res,AL
INT 3h
code ends
end start
Factorial of a given number
assume cs: code, ds: data
data segment
n1 db 04H
Fact dw ?
data ends
code segment
start:
MOV AX,data
MOVDS,AX
MOV AL,0000H
MOV AL,n1
MOV CL,03H
L1:
MUL CL
DEC CL
JNZ L1
MOV fact,AX
INT 3H
Code ends
end start
Move string from one location to other
Assume cs:code, ds:data, es: data
data segment
Str1 db ‘sreenidhi'
Str2 db ?
data ends
code segment
start:
MOV AX,data
MOV DS,AX
MOV ES,AX
MOV CX,09H
LEA SI,str1
LEA DI,str2
CLD
REP MOVSB
INT 3
code ends
end start
Compare two strings
assume cs:code,ds:data,es:data
data segment
str1db 'CSE'
str2db 'CSE'
Res db ?
data ends
code segment
Start: MOV AX, data
MOV DS,AX
MOV ES,AX
LEA SI,str1
LEA DI,str2
MOV CX,03H
CLD
REPE CMPSB
JZ ok
MOV res,'n'
MOV res+1,'o'
JMP go
ok:MOV res,'y'
MOV res+1,'e'
MOV res+2,'s'
go: INT 03H
code ends
end start
Reverse a Given String

assume cs:code, ds:data, es:data


data segment
Str1 db 'snist'
Str2 db 25 dup(00)
data ends
code segment
START: MOV AX,data
MOV DS,AX
MOV ES,AX
MOV CX,05H

You might also like