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

Amp Experiments

The document contains code to count the number of 1's and 0's in a binary number. It initializes variables to store the input number, counters for 1's and 0's, and the result. It then uses a loop to rotate the bits of the input number, incrementing the appropriate counter and storing the results.

Uploaded by

Ashish Mathew
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Amp Experiments

The document contains code to count the number of 1's and 0's in a binary number. It initializes variables to store the input number, counters for 1's and 0's, and the result. It then uses a loop to rotate the bits of the input number, incrementing the appropriate counter and storing the results.

Uploaded by

Ashish Mathew
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 32

EXP 1 -Addition

#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c,result;
clrscr();
cout<<"\n\n\t\t 1.8 bit addition ";
cout<<"\n\t\t 2.16 bit addition ";
cout<<"\n\t\t 3.BCD addition ";
cout<<"Enter the choice : ";
cin>>c;

switch(c)
{
case 1:
cout<<"\n\tEnter value of a :: ";
cin>>a;
cout<<"\tEnter value of b :: ";
cin>>b;
asm{
mov ax,a;
mov bx,b;
add ax,bx;
mov result,ax;
}
cout <<"\tAddition of 8 bit :: "<<result;
break;

case 2:
cout<<"\n\tEnter value of a :: ";
cin>>a;
cout<<"\tEnter value of b :: ";
cin>>b;
asm{
mov ax,a;
mov bx,b;
add ax,bx;
mov result,ax;
}
cout <<"\tAddition of 16 bit :: "<<result;
break;

case 3:
cout<<"\n\tEnter value of a :: ";
cin>>a;
cout<<"\tEnter value of b :: ";
cin>>b;
asm{
mov ax,a;
mov bx,b;
add ax,bx;
daa
mov result,ax;
}
cout <<"\tAddition of BDC:: "<<result;
break;

default:cout<<"\n\n You entered a wrong choice.";


}
getch();
}
EXP 2 - Subtraction
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c,result;
clrscr();
cout<<"\n\n\t\t 1.8 bit subtraction";
cout<<"\n\t\t 2.16 bit subtraction ";
cout<<"\n\t\t 3.BCD subtraction ";
cout<<"\n\tEnter the choice : ";
cin>>c;

switch(c)
{
case 1:
cout<<"\n\tEnter value of a :: ";
cin>>a;
cout<<"\tEnter value of b :: ";
cin>>b;
asm{
mov ax,a;
mov bx,b;
sub ax,bx;
mov result,ax;
}
cout<<"\tSubtraction of 8 bit :: "<<result;
break;

case 2:
cout<<"\n\tEnter value of a :: ";
cin>>a;
cout<<"\tEnter value of b :: ";
cin>>b;
asm{
mov ax,a;
mov bx,b;
sub ax,bx;
mov result,ax;
}
cout <<"\tSubtraction of 16 bit :: "<<result;
break;

case 3:
cout<<"\n\tEnter value of a :: ";
cin>>a;
cout<<"\tEnter value of b :: ";
cin>>b;
asm{
mov ax,a;
mov bx,b;
sub ax,bx;
das
mov result,ax;
}
cout<<"\tSubtraction of BCD: "<<result;
break;

default:cout<<"\n\n You entered a wrong choice.";


}
getch();
}
EXP 3 – Mul & Div
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c,result;
//clrscr();
cout<<"\n\nSelect: 1.For Singned Multiplication\n 2.For Unsigned Multiplication\n 3.Division of
number";
cout<<"\n\t Enter the choice: ";
cin>>c;

switch(c)
{
case 1:
cout<<"\n\tEnter value of a :: ";
cin>>a;
cout<<"\tEnter value of b :: ";
cin>>b;
asm{
mov ax,a;
mov bx,b;
mul bx;
mov result,ax;
}
cout<<"\tMultiplication of Signed no :: "<<result;
break;

case 2:
cout<<"\n\tEnter value of a :: ";
cin>>a;
cout<<"\tEnter value of b :: ";
cin>>b;
asm{
mov ax,a;
mov bx,b;
imul bx;
mov result,ax;
}
cout <<"\tMultiplication of Unsigned no :: "<<result;
break;
case 3:
cout<<"\n\tEnter value of a :: ";
cin>>a;
cout<<"\tEnter value of b :: ";
cin>>b;
asm{
mov ax,a;
mov bx,b;
div bx;
mov result,ax;
}
cout<<"\tDivision of no :: "<<result;
break;

default:cout<<"\n\n You entered a wrong choice.";


}
getch();
}
EXP 4 – Square Cube Fact
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int a,c,d,b,n,s;
cout<<"\n Enter the number:";
cin>>a;
cout<<"1.square \n2.cube \n3.factorial";
cin>>b;
switch(b)
{
case 1:
asm mov ax,a
asm mov bx,a
asm mul bx
asm mov c,ax
cout<<"the square is:"<<c;
break;
case 2:
asm mov ax,a
asm mov bx,a
for(int i=1;i<=2;i++)
{
asm mul bx
asm mov c,ax
}
cout<<"cube is:"<<c;
break;
case 3:
//asm mov ax,a
//asm mov bx,a
cout<<"enter the num:";
cin>>n ;
a=n-1;
asm mov ax,n;
for(a;a>0;a--)
{
asm mov bx,a;
asm mul bx;
}
asm mov s,ax;
cout<< "fact is:"<<s;
break;
}
getch();
}

SQUARE OF NUMBERS………………..
Enter the number:2
1.square
2.cube
3.factorial
1
the square is:4

CUBE OF NUMBERS…………..
Enter the number:2
1.square
2.cube
3.factorial
2
cube is: 8
FACTORIAL NO IS ……
enter the num:4
1.square
2.cube
3.factorial
3
fact is:24
//HCF LCM

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,i,LCM,HCF;
cout<<"Program to calculated LCM and HCF:\n";
cout<<"Enter the first number:";
cin>>a;
cout<<"Enter the second number:";
cin>>b;
for(i=1;i<=a;i++)
{
if(a%i==0 && b%i==0)
{
HCF=i;

}
}
cout<<"\nThe HCF of given number is"<<HCF;
LCM=(a*b)/HCF;
cout<<"\nThe LCM of given number is"<<LCM;
getch();
}

/*
OUTPUT:
Program to calculated LCM and HCF:
Enter the first number:2
Enter the second number:20

The HCF of given number is2


The LCM of given number is20
*/
// Even Odd
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"enter the number:";
cin>>a;
asm mov ax,a;
asm ror ax,1;
asm jnc even;
asm jc odd;
odd:cout<<"the number is odd";
asm jmp x:
even:cout<<"the number is even";
x:
getch();
}
// Positive Negative

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int n;

cout<<"\nEnter a number:";

cin>>n;

asm mov ax,n;

asm cmp ax,00h;

asm jl neg;

asm jg pos;

neg:cout<<"\nNegative";

asm jmp halt;

pos:cout<<"\nPositive";

halt: asm hlt;

getch();

}
Block Transfer:---

Data Segment

str1 db 01H,02H,03H,04H,05H

str2 db 5 dup(0)

Data Ends

Code Segment

Assume cs:code,ds:data

START:MOV AX,data

MOV DS,AX

MOV ES,AX

LEA SI,str1

LEA DI,str2

MOV CX,05H

REP MOVSB

INT 3

Code Ends

End START

Output:
//PROGRAM FOR REVERSE THE STRING

DATA SEGMENT

STRING1 DB 10H

STRING2 DB 00H

STRING3 DB 10 DUP(0)

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE,DS: DATA

START:MOV AX,DATA

MOV DS,AX

MOV AH,0AH

LEA DX,STRING1

INT 21H

MOV CH,00

MOV CL,STRING1+1

LEA BX,STRING1

INC BX

MOV DI,CX

BACK: MOV AH,02H

MOV DL,[BX+DI]

INT 21H

DEC DI

JNZ BACK

INT 3
CODE ENDS

END START

OUTPUT:
//PROGRAM TO FIND STRING IS PALINDROME OR NOT.

DATA SEGMENT

BLOCK1 DB 'MALAYALAM'

MSG1 DB "IT IS PALINDROM $"

MSG2 DB "IT IS NOT PALINDROM $"

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

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
OUTPUT:
/* Number Conversion - BCD to Binary */
DATA SEGMENT
BCD DB "FD97"
BINARY DB 01H
COUNT DB 04H
DATA ENDS

EXTRA SEGMENT
MESSAGE DB 16 DUP(0)
EXTRA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:EXTRA

START:MOV AX,DATA
MOV DS,AX
MOV AX,EXTRA
MOV ES,AX
LEA SI,BCD
LEA DI,MESSAGE+16
MOV DX,0004H
UP: MOV CX,0004H
MOV AL,[SI]
MOV AH,00H
CMP AX,40H
JNG UP2
JG UP1
UP1: SUB AX,37H
JMP BACK
UP2: SUB AX,30H
BACK: MOV BL,02H
CMP AX,0000H
JE BACK1
BACK1:DIV BL
MOV [DI],AH
MOV AH,00H
INC DI
LOOPNZ BACK
INC SI
DEC DX
LOOPNZ UP
MOV DX,04H
LEA SI,BCD
LEA DI,MESSAGE+11
A3: ADD DI,08
MOV CX,04H
A2: MOV AL,[DI]
MOV [SI],AL
INC SI
DEC DI
LOOPNZ A2
DEC DX
LOOPNZ A3
INT 3H
CODE ENDS
END START
/* Number Conversion – Binary to BCD */
DATA SEGMENT
BINARY DB "1111110110010011$"
BCD DB 00H
COUNT DB 04H
DATA ENDS
EXTRA SEGMENT
MESSAGE DB 10 DUP(0)
EXTRA ENDS
PRINT MACRO MSG
MOV AH,09H
LEA DX,MSG
INT 21H
ENDM
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:EXTRA
START:MOV AX,DATA
MOV DS,AX
MOV AX,EXTRA
MOV ES,AX
PRINT BINARY
LEA SI,BINARY
LEA DI,MESSAGE
UP1: MOV DX,0004H
UP: MOV AL,01H
MOV AH,00H
MOV BL,02H
MOV CX,DX
DEC CX
BACK: CMP CX,0000H
JE BACK1
MUL BL
LOOPNZ BACK
BACK1:MOV BL,[SI]
MOV CL,30H
SUB BL,CL
MUL BL
ADD BCD,AL
INC SI
DEC DX
LOOPNZ UP
MOV AL,BCD
MOV [DI],AL
INC DI
MOV BCD,00H
DEC COUNT
JNZ UP1
INT 3H
CODE ENDS
END START

OUTPUT:
C:\TASM>masm nilbin2bcd.asm
Microsoft (R) Macro Assembler Version 5.10
Copyright (C) Microsoft Corp 1981, 1988. All rights reserved.

Object filename [nilbin2bcd.OBJ]:


Source listing [NUL.LST]:
Cross-reference [NUL.CRF]:

48676 + 445815 Bytes symbol space free

0 Warning Errors
0 Severe Errors

C:\TASM>link nilbin2bcd.obj

Microsoft (R) Overlay Linker Version 3.64


Copyright (C) Microsoft Corp 1983-1988. All rights reserved.

Run File [NILBIN2BCD.EXE]:


List File [NUL.MAP]:
Libraries [.LIB]:
LINK : warning L4021: no stack segment

C:\TASM>debug nilbin2bcd.exe
-g
1111110110010011
AX=0003 BX=0001 CX=002F DX=0000 SP=0000 BP=0000 SI=0010 DI=0004
DS=0BD6 ES=0BD8 SS=0BD6 CS=0BD9 IP=0050 NV UP EI PL ZR NA PE NC
0BD9:0050 CC INT 3
-d 0BD6:0000
0BD6:0000 0F 0D 09 03 31 31 30 31-31 30 30 31 30 30 31 31 ....110110010011
0BD6:0010 24 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 $...............
0BD6:0020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0BD6:0030 B8 D6 0B 8E D8 B8 D8 0B-8E C0 B4 09 8D 16 00 00 ................
0BD6:0040 CD 21 8D 36 00 00 8D 3E-00 00 BA 04 00 B0 01 B4 .!.6...>........
0BD6:0050 00 B3 02 8B CA 49 83 F9-00 74 04 F6 E3 E0 F7 8A .....I...t......
0BD6:0060 1C B1 30 2A D9 F6 E3 00-06 11 00 46 4A E0 DE A0 ..0*.......FJ...
0BD6:0070 11 00 88 05 47 C6 06 11-00 00 FE 0E 12 00 75 CA ....G.........u.
-q
Program to find 0’s 1’s.
data segment
n db 0Ah
one_c db 0
zero_c db 0
result db ?
data ends
code segment
assume cs: code , ds:data
mov ax , data
mov ds , ax
mov al,n
mov cx,08
mov bx,0000h
back: rol al,1
jnc incz
inc bh
jmp next
incz: inc bl
next: loop back
int 3
code ends
end
Ascending

data segment

string1 db 99h,12h,56h,46h,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

Output:-
//PROGRAM TO FIND 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
OUTPUT:
//PROGRAM FOR REVERSE THE STRING

DATA SEGMENT

STRING1 DB 10H

STRING2 DB 00H

STRING3 DB 10 DUP(0)

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE,DS: DATA

START:MOV AX,DATA

MOV DS,AX

MOV AH,0AH

LEA DX,STRING1

INT 21H

MOV CH,00

MOV CL,STRING1+1

LEA BX,STRING1

INC BX

MOV DI,CX

BACK: MOV AH,02H

MOV DL,[BX+DI]

INT 21H

DEC DI

JNZ BACK

INT 3
CODE ENDS

END START

OUTPUT:

You might also like