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

lab4

The document explains variable declaration in EMU8086, detailing what a variable is, its types (BYTE, WORD, DWORD), and how to declare them with examples. It covers the basic structure of a program, including the data and code segments, and provides instructions for displaying a string using DOS functions. Additionally, it includes an assignment to write a program that performs arithmetic operations using declared variables.

Uploaded by

konew90663
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

lab4

The document explains variable declaration in EMU8086, detailing what a variable is, its types (BYTE, WORD, DWORD), and how to declare them with examples. It covers the basic structure of a program, including the data and code segments, and provides instructions for displaying a string using DOS functions. Additionally, it includes an assignment to write a program that performs arithmetic operations using declared variables.

Uploaded by

konew90663
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Title: Variable Declaration

in EMU8086
What is a Variable?
A variable is a storage location in a program that holds data. It allows programmers to
store, modify, and retrieve values during program execution.

Key Points:

Name: Each variable has a unique identifier (name) that allows you to reference it in
your code.

Data Type: Variables can hold different types of data, such as integers, characters, or
floating-point numbers.

Initialization: Variables can be initialized with a value at the time of declaration or


assigned a value later in the program.

3/1/20XX SAMPLE FOOTER TEXT 2


Types of Variables in EMU8086
Data types: BYTE, WORD, DWORD.

BYTE:
. DB (define byte)
. 8 bits
. used to store single byte value

WORD:
. DW (define word)
. 16 bits
. used to store 16bit value

3/1/20XX SAMPLE FOOTER TEXT 3


Double WORD:
. DD (define double)
. 32 bits
. used to store 32 bit (4 bytes) value

Declaring variable:
Syntax:

VARIABLE_NAME DATA_TYPE INITIAL_VALUE

Example:
myByte DB 10;
myWord DW 1234h;
myDword DD 1234567h
3/1/20XX SAMPLE FOOTER TEXT 4
Write a simple program
Step 1: Basic structure

3/1/20XX SAMPLE FOOTER TEXT 5


model small
. Define memory model
. Program uses single code and data segment , program that fits in
64kb segment

stack 100h
. Define stack size
data
. Start of data segment
code
. Start of code segment
itle
 MOV AX, 4C00h
 . 4C Terminates the process
 . 00 Return code/ exit code
 . DOS function to exit program (disk operting system)
 INT 21h

 int instruction to generate interrupt


 21h DOS interrupt 21h is used to interrupt the program
 Call DOS interrupt
 Basic purpose of these two is to terminate the program and return
the control to the operating system
3/1/20XX SAMPLE FOOTER TEXT 7
 Step 2 : Declaring variables in a program

3/1/20XX SAMPLE FOOTER TEXT 8


Data Segment:
•Var1 DB 10: Declares a variable var1 initialized to 10.
•Var2 dw 1234: Declares a variable var2 initialized to 1234.
•Var3 dd 1345678: Declares a variable var3 initialized 1345678.

•Code segment
mov ax, @data
mov ds, ax
. loads the address of data segment in AX register
. 00720  DS address
. We load the data in DS so that we can know where our data is located

3/1/20XX SAMPLE FOOTER TEXT 9


Add to Variables Program

3/1/20XX SAMPLE FOOTER TEXT 10


Hello World Program

3/1/20XX SAMPLE FOOTER TEXT 11


• $ is used to indicate the end of the string
• MOV AH, 09h Sets up the DOS function for displaying/ printing a string
• By placing 09h into the AH register, you're telling DOS that you want to call the
"print string" function. This function will read a string from memory and display it
on the screen until it encounters a $ character (which is the expected string
terminator for this function).
• LEA DX, message
LEA: This stands for "Load Effective Address." It is used to load the address
of a variable (or the offset of a string) into a register.
DX: This is another register, used for data storage
message: This is the label for the string you declared in the .DATA segment
(e.g., message DB 'Hello, World!', 0).

3/1/20XX SAMPLE FOOTER TEXT 12


This instruction loads the address (or offset) of the message string into the DX
register. This address tells DOS where to find the string that needs to be displayed.

Actual working :
MOV AH, 09h sets up the function,
LEA DX, message loads the address of the string, and
INT 21h triggers the display action.

3/1/20XX SAMPLE FOOTER TEXT 13


Ass#1
Write a program which performs all
Arithmetic operations by declaring
variables

3/1/20XX SAMPLE FOOTER TEXT 14

You might also like