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

8086 Microprocessor And Assembly Language Program

8086 Microprocessor and Assembly Language


Programming

AH AL
BH BL
CH CL
DH DL

Registers

Category Bits Register Names


General 16 AX, BX, CX, DX
8 AH, AL, BH, BL, CH, CL, DH, DL
Pointer 16 SP (stack pointer), BP (base pointer)
Index 16 SI (source index), DI (destination index)
Segment 16 CS (code segment), DS (data segment)
SS (stack segment), ES (extra segment)
Instruction 16 IP (instruction pointer)
Flag 16 FR (flag register)

Gotam Sanyal, Astt.Prof, YSM,Ranchi Page 1


8086 Microprocessor And Assembly Language Program

Data transfer instructions


Transfer information between registers and memory locations or I/O ports.
MOV, XCHG, LEA, PUSH, POP, PUSHF, POPF, IN, OUT.
Arithmetic instructions
Perform arithmetic operations on binary or binary-coded-decimal (BCD) numbers.
ADD, SUB, INC, DEC, ADC, SBB, NEG, CMP, MUL, IMUL, DIV, IDIV, CBW, CWD.
Bit manipulation instructions
Perform shift, rotate, and logical operations on memory locations and registers.
SHL, SHR, SAR, ROL, ROR, RCL, RCR, NOT, AND, OR, XOR, TEST.
Flow Control Instructions
Signed jumps
• JG/JNLE jump if greater than, or jump if not less than or equal
• JGE/JNL jump if greater than or equal, or jump if not less than
• JL/JNGE jump if less than, or jump if not greater than or equal
• JLE/JNG jump if less than or equal, or jump if not greater than
Unsigned jumps
• JA/JNBE jump if above, or jump if not below or equal
• JAE/JNB jump if above or equal, or jump if not below
• JB/JNAE jump if below, or jump if not above or equal
• JBE/JNA jump if below or equal, or jump if not above
�Single-Flag jumps
• JE/JZ jump if equal, or jump if equal to zero
• JNE/JNZ jump if not equal, or jump if not equal to zero
• JC jump of carry
• JNC jump if no carry
• JO jump if overflow
• JNO jump if no overflow

PROGRAM 1
// ASSSEMBLY LANGUAGE PROGRAM ARITHMATICAL OPERATION
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
asm MOV AX, 10
asm MOV BX, 2
asm ADD AX ,BX

Gotam Sanyal, Astt.Prof, YSM,Ranchi Page 2


8086 Microprocessor And Assembly Language Program

printf("%d',_AX);
asm MOV AX, 10
asm MOV BX, 2
asm SUB AX ,BX
printf("%d',_AX);
asm MOV AX, 10
asm MOV BX, 2
asm MUL BX
printf("%d',_AX)
asm MOV AX, 10
asm MOV BX, 2
asm DIV BX
printf("%d',_AX);
getch();
return 0;
}

PROGRAM-2
// ASSSEMBLY LANGUAGE PROGRAM FOR LOGICAL OPERATION
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
asm MOV AX, 10
asm MOV BX, 2
asm OR AX ,BX
printf("VALUE OF OR OF 10 , 2 IS %d\n",_AX);
asm MOV AX, 10
asm MOV BX, 2
asm AND AX ,BX
printf"VALUE OF AND OF 10 , 2 IS %d\n",_AX);
asm MOV AX, 10
asm MOV BX, 2
asm XOR AX ,BX
printf("VALUE OF XOR OF 10 , 2 IS %d\n",_AX);
getch();
return 0;
}
PROGRAM-3
//PROGRAM TO IMPLEMENT IF STATEMENT
// THE PROGRAM WILL NEGATE THE INTEGER IF IT IS NEGEATIVE
//THE ALGORITHM IS
//If AX < 0 Then

Gotam Sanyal, Astt.Prof, YSM,Ranchi Page 3


8086 Microprocessor And Assembly Language Program

//Replace AX by -AX
#include<stdio.h>
#include<conio.h>
int main()
{
int z;
clrscr();
printf("Enter a number");
scanf("%d",&z);
//ENDIF
// if AX < 0
asm mov AX,z; // to move the value of z to ax
asm CMP AX, 0 // compare the value in ax with zero
asm JNL END_IF //jump to label END_IF if it is not less than zero
//then
asm NEG AX; // negate the value in ax
END_IF:
printf("%d",_AX);
return 0;
}

PROGRAM-4
//PROGRAM TO IMPLEMENT IF-ELSE STSATEMENT
//EXAMPLE
//asemmpbly language program to find maximum of two numbers
//ALGORITHM IS
//Example:
//If AX <= BX Then
//Display character in AX
//Else
//Display character in BX
//ENDIF

#include<stdio.h>
#include<conio.h>
int main()
{
int X,Y;
clrscr();
printf("Enter two n umber");
scanf("%d%d",&X,&Y);
asm MOV AX,X;
asm MOV BX,Y;
// if AL<=BL
asm CMP AX, BX; //compare AX with BX
asm JG ELSE_ //jump to ELSE_ if AX>BX
//then
asm MOV DX, BX //move valiue of Ax to DX

Gotam Sanyal, Astt.Prof, YSM,Ranchi Page 4


8086 Microprocessor And Assembly Language Program

asm JMP DISPLAY // jump to display


ELSE_:
asm MOV DX, AX; // otherwise move BX to DX
DISPLAY:
printf("%d",_DX); // DX store the maximum value
END_IF:
getch();
return 0;
}

PROGRAM-5
/ PROGRAM TO IMPLEMENT WHILE STATEMENT
//EXAMPLE:
// print the sum of first 10 natural number (while statement implementation in assembly)
//ALGORITHM
//Initialize count to 1( DX=1)
//Initialize term to 1(BX=2)
// initialize sum to 0 (AX =0)
//While Count<=10
//sum=sum+term
//term=term+1
//Count = Count + 1
//END_While
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();

asm MOV DX, 1


asm MOV BX, 1
asm MOV AX ,0
asm INT 21H
While_:
asm CMP DX, 10 // COMPARE DX WITH 10
asm JG End_While // JUMP TO End_While LABEL IF IT IS GREATER
asm ADD AX,BX // ADD AX WITH BX (SUM=SUM+TERM)
asm ADD BX,1 // ADD 1 TO BX (TERM=TERM+1)
asm INC DX // INCREMENT DX
asm JMP While_
End_While:
printf("Sum of 1st 10 natural number=%d",_AX);
getch();
return 0
}

PROGRAM-6

Gotam Sanyal, Astt.Prof, YSM,Ranchi Page 5


8086 Microprocessor And Assembly Language Program

//IMPLEMENTATION OF FOR
// display of * 80 times
#include<stdio.h>
#include<conio.h>
int main()
{
int z;
clrscr();
//Example: For 80 times DO Display *
//END_IF
asm MOV CX, 80 //INITIALIZE CX TO 80
asm MOV AH, 2 //INITIALIZE AH TO 2 TO DISPLAY A CHARACHTER IF IT FOLLOWED BY INT 21H
INTERRRUPT
asm MOV DL, '*'; //INITIALIZE DL WITH '*"
Next:
asm INT 21H // CALL INTERRUPT TO DISPLAY THE CHARACHTER IN DOS
asm Loop Next
getch();
return 0;
}

Gotam Sanyal, Astt.Prof, YSM,Ranchi Page 6

You might also like