Amp Experiments
Amp Experiments
#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;
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;
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;
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
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int n;
cout<<"\nEnter a number:";
cin>>n;
asm jl neg;
asm jg pos;
neg:cout<<"\nNegative";
pos:cout<<"\nPositive";
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
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
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'
PAL DB 00H
DATA ENDS
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
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.
0 Warning Errors
0 Severe Errors
C:\TASM>link nilbin2bcd.obj
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
mov ds,ax
mov ch,04h
lea si,string1
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
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
MOV DL,[BX+DI]
INT 21H
DEC DI
JNZ BACK
INT 3
CODE ENDS
END START
OUTPUT: