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

Programming With 8086

The document provides an overview of programming with the 8086 microprocessor, detailing the use of assembly language and various development tools such as editors, assemblers, linkers, locators, and debuggers. It covers assembler directives, data transfer, arithmetic and logical instructions, conditional and loop statements, subroutines, and examples of simple assembly language programs. The importance of modularization through subroutines and the use of CALL and RETURN instructions are also emphasized.

Uploaded by

chaitanyapc411
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Programming With 8086

The document provides an overview of programming with the 8086 microprocessor, detailing the use of assembly language and various development tools such as editors, assemblers, linkers, locators, and debuggers. It covers assembler directives, data transfer, arithmetic and logical instructions, conditional and loop statements, subroutines, and examples of simple assembly language programs. The importance of modularization through subroutines and the use of CALL and RETURN instructions are also emphasized.

Uploaded by

chaitanyapc411
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

UNIT:4:Programming with 8086

4.0 Programming with 8086


Programming in 8086 assembly language involves writing low-level
programs that are directly executed by the 8086 microprocessor. These
programs allow you to manipulate data, perform operations, and control
the flow of execution. The language provides control over hardware and
facilitates efficient system-level programming.

4.1 Describe the Use of Various Assembly Language


Development Tools
In the 8086 assembly language programming environment, several
tools are used to develop, compile, link, and debug programs:

1. Editor: A text editor is used to write and modify assembly


language source code. Examples include Notepad++ or more
specialized editors like TASM (Turbo Assembler) or MASM
(Microsoft Assembler).
2. Assembler: The assembler converts assembly language code into
machine code (binary). The assembler generates an object code file
which contains machine-readable instructions. Examples include
MASM and TASM.
3. Linker: The linker combines object files (generated by the
assembler) into an executable program. It resolves external
references and links the various modules or functions into one
executable. The output is usually a .exe file.
4. Locator: The locator assigns physical addresses to variables and
functions during the linking process. It ensures that all memory
addresses are correctly mapped for the final program to run
properly in memory.
5. Debugger: The debugger is used to test and troubleshoot assembly
language programs by running them step by step. It allows the
programmer to examine the contents of registers and memory, set
breakpoints, and trace the execution of the program. Examples
include Debug in DOS and other third-party debugging tools.

4.2 Describe Assembler Directives


Assembler directives are commands that provide instructions to the
assembler but do not generate machine code directly. They guide the
assembly process and help in organizing the code. Common directives
include:

1. SEGMENT: Defines a memory segment for code or data.


o Example: DATA SEGMENT begins a data segment, and
CODE SEGMENT begins a code segment.
2. ENDS: Marks the end of a segment.
o Example: DATA ENDS
3. DB (Define Byte): Allocates a byte in memory.
o Example: NUM DB 10h (Defines a byte with the value 10h)
4. DW (Define Word): Allocates a word (2 bytes) in memory.
o Example: NUM DW 1234h
5. EQU: Defines a constant value.
o Example: PI EQU 3.14
6. ORG: Specifies the starting address for the program or data.
o Example: ORG 100h
4.3 Write Simple Assembly Language Programs Using Data
Transfer Instructions
i) To Transfer Data Between Registers

The MOV instruction is used to transfer data from one register to another.

Example:
MOV AX, BX ; Move data from BX to AX

ii) To Transfer Data Between Register and Memory Location

To transfer data between a register and a memory location, we can use


MOV.

Example:
MOV AX, [5000h] ; Move data from memory address
5000h into AX
MOV [6000h], AX ; Move data from AX into memory
address 6000h

iii) To Transfer Data From One Memory Location to Another

Example:
MOV AX, [5000h] ; Load data from address
5000h into AX
MOV [6000h], AX ; Store data from AX into
address 6000h

4.4 Write Simple Assembly Language Programs Using


Arithmetic Instructions
i) To Perform Addition/Subtraction/Multiplication/Division of Two
8/16 Bit Numbers
Example: Addition of Two 16-bit Numbers
MOV AX, 1234h ; Load AX with the first number
MOV BX, 5678h ; Load BX with the second
number
ADD AX, BX ; Add BX to AX

ii) To Perform 1’s Complement Subtraction

1’s complement subtraction can be done by inverting the bits and adding
1.

Example:
MOV AX, 0001h ; Load AX with 1
NOT AX ; Invert the bits (1's
complement)
ADD AX, 1 ; Add 1 to complete the
subtraction

iii) To Perform Addition of a Series of 'n' Numbers

Example:
MOV CX, n ; Set CX as the counter for 'n'
numbers
MOV AX, 0 ; Initialize AX to 0
(accumulator)
LOOP_ADD:
ADD AX, [SI] ; Add number at memory address
SI to AX
INC SI ; Increment SI to point to the
next number
LOOP LOOP_ADD ; Repeat the loop for 'n'
times
4.5 Write Simple Assembly Language Programs Using
Logical Instructions
i) To Perform AND/OR/XOR Operations on Two 8/16 Bit Numbers

Example: AND Operation


MOV AX, 0F0Fh ; Load AX with the first number
MOV BX, 0FF0h ; Load BX with the second
number
AND AX, BX ; Perform AX = AX AND BX

ii) To Perform Conversion of 4-bit Binary Code to Gray Code

The formula to convert binary to gray code is:


Gray[i] = Binary[i] XOR Binary[i+1]

Example:
MOV AL, 0Ah ; Load AL with binary number
(1010)
XOR AL, 0Ah ; Convert to Gray Code by
XORing with the next bit

4.6 Explain Conditional and Loop Statements


In 8086 assembly, conditional and looping instructions control the flow
of execution based on flags or specified conditions.

1. Conditional Statements: These allow the program to take


different paths based on certain conditions.
o Example: JZ (Jump if Zero), JNZ (Jump if Not Zero), JC
(Jump if Carry)
2. Loop Statements: These allow the program to execute a block of
code multiple times.
o Example:
o MOV CX, 5 ; Loop 5 times
o LOOP_START:
o ; Code block here
o LOOP LOOP_START ; Decrement CX and loop
if CX != 0

4.7 Write Simple Assembly Language Program to Find the


Biggest/Smallest of the Given Series of Numbers
To find the biggest number from a series:
MOV CX, n ; Set CX as the counter
MOV AX, [SI] ; Load the first number into AX
LOOP_COMPARE:
INC SI ; Increment SI to the next
number
CMP AX, [SI] ; Compare AX with the current
number
JGE SKIP ; If AX >= current number,
skip
MOV AX, [SI] ; Otherwise, move the new
number to AX
SKIP:
LOOP LOOP_COMPARE ; Repeat until all numbers
are checked

4.8 State the Need of Subroutine


A subroutine is used to modularize code into smaller, reusable chunks.
It allows for code reuse, easier debugging, and better structure.
Subroutines can be called multiple times from different parts of the
program, saving memory and reducing redundancy.

4.9 Explain CALL, RETURN Instructions


1. CALL: This instruction calls a subroutine, saving the return
address on the stack.
o Example: CALL SUBROUTINE_NAME
2. RETURN: This instruction returns control to the calling program
by popping the return address from the stack.
o Example: RET

4.10 Explain Subroutine Programming in 8086


Subroutines allow you to call a set of instructions from another part of
the program. This is especially useful for performing repetitive tasks.
Subroutines are typically called using the CALL instruction, and
execution returns with the RET instruction.

Example of a subroutine:
MAIN:
CALL FACTORIAL
; Continue execution here

FACTORIAL:
; Subroutine to calculate factorial
RET

4.11 Write Simple Assembly Language Program Using


Subroutine to Find the Factorial of the Given Number
Example:
MOV AX, 5 ; Load number 5 into AX
CALL FACTORIAL ; Call the subroutine
; Factorial result is in AX

FACTORIAL:
MOV BX, AX ; Copy number to BX
DEC AX ; Decrement number
MUL BX ; Multiply AX by BX (AX = AX *
BX)
RET

-o0o-

You might also like