0% found this document useful (0 votes)
12 views7 pages

COAL Lab 6

Uploaded by

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

COAL Lab 6

Uploaded by

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

CS-2202 Computer Organization and Assembly Language

Lab 6: Microsoft Macro-Assembler MASM, MS-dos function calls INT21h


and call of procedure DUMPREGS of Irvine library in programs.

Objectives
• To understand physical and logical memory segments used in 80x86
architecture
• To study the basic elements of assembly language
Basic Information
Understanding segments is an essential part of programming in assembly language. In the
family of 8086-based processors, the term segment has two meanings:
• A block of memory of discrete size, called a “physical segment.” The number
of bytes in a physical memory segment is 64K for 16-bit processors or 4
gigabytes for 32-bit processors.
• A variable-sized block of memory, called a “logical segment,” occupied by a
program’s code or data.

MASM programs consist of modules made up of segments. Every program written only
in MASM has one main module, where program execution begins. This main module can
contain code, data, or stack segments defined with all of the simplified segment
directives. Any additional modules should contain only code and data segments.
The .DATA and .CODE statements do not require any separate statements to define the
end of a segment. They close the preceding segment and then open a new segment. The
END statement closes the last segment and marks the end of the source code. It must be
at the end of every module
Directives are part of the assembler syntax, but are not related to the Intel instruction set
architecture. Various assemblers may generate identical machine code for the Intel
processor, but their sets of directives need not to be the same.

Program template and introduction of assembler program:


An assembler is a program designed to take an assembly language source program
(*.asm)file as input and generate an object program (*.obj) as output. The assembler also
creates a list file (*.lst) which lists both the source statements. An object program (.obj) is
a machine language interpretation of original source program.

Link step:
The linker supplies with the macro assembler reads an object program (*.obj) and
generates an executable (*.exe) program. The executable program can be executed just by
typing its name.

Category Command/Directive Description Example

CASE Institute Page 1 of 7


CS-2202 Computer Organization and Assembly Language
Lab 6: Microsoft Macro-Assembler MASM, MS-dos function calls INT21h
and call of procedure DUMPREGS of Irvine library in programs.

Libraries INCLUDE irvine16.inc Copies definitions 1.Simplified I/O


and processor Operations
information from 2.Memory and Register
irvine16.inc in the Management
3.Error Checking etc.
assembler’s
INCLUDE directory.

Directives .DATA Defines the area variable_name type


containing variables. initialized_value
e.g., var1 DWORD
1000h

.CODE Marks the start of the .CODE The .CODE segment


code segment for program holds all the
instructions. executable
instructions, which
helps the assembler
organize and manage
the program's
structure.
TITLE Adds comments about the TITLE Program
program; text to the right Information
of ; is ignored.
PROC Marks the start of a MAIN PROC
procedure (similar to
functions in C/C++).
ENDP Marks the end of a main endp
procedure.
END Marks the end of the End main
source code.
.MODEL SMALL Sets up the memory .MODEL SMALL (64 KB each)
model for the program.
Initialization mov ax, @data Loads the starting mov ax, @data
address of the data
segment into AX.
mov ds, ax Sets up DS to point to the mov ds, ax
start of the data segment.

MS-DOS Function int 21h Executes a DOS int 21h


Calls function call, with the
function number
specified in the AH
register.

CASE Institute Page 2 of 7


CS-2202 Computer Organization and Assembly Language
Lab 6: Microsoft Macro-Assembler MASM, MS-dos function calls INT21h
and call of procedure DUMPREGS of Irvine library in programs.

mov ah, 6 Loads the function mov ah, 6


number for displaying a
character (Function 6)
into AH.
mov dl, '*' Loads a character (e.g., *) mov dl, '*'; int 21h
to be displayed into the
DL register.
mov ah, 9 Loads the function mov ah, 9
number for displaying a
string (Function 9) into
AH.
String Handling string byte 'NAME','$' Declares a string string byte 'Hello','$'
ending with $ to be
used with DOS string
output function.

Running Programs make16 <filename> Assembles the make16 filename


program and creates
executable files using
the specified
filename.
Templates#01 Standard program layout It is more
with TITLE, INCLUDE, comprehensive and
.DATA, .CODE, and suited for more
MAIN PROC. complex programs
with multiple
procedures.
Template #2 Uses .MODEL SMALL, Itis streamlined for
.DATA, .CODE, simpler programs.
.STARTUP, and .EXIT
for smaller programs.

1. TEMPLATE #1
Following is the program template for creating new programs.
TITLE (The TITLE directive marks the entire line as a comment. You can put
any ;information you want on this line e.g.
;this program is to make you understand the program template
;All the text to right of semicolon is ignored by the assembler, so we use it for
comments.)
INCLUDE irvine16.inc

CASE Institute Page 3 of 7


CS-2202 Computer Organization and Assembly Language
Lab 6: Microsoft Macro-Assembler MASM, MS-dos function calls INT21h
and call of procedure DUMPREGS of Irvine library in programs.

(The INCLUDE directive copies necessary definitions and set microprocessor


information from a text file named irvine16.inc, located in the assembler’s INCLUDE
directory)
.DATA (The .DATA directive identifies the area of a program that contains variables)
variable_name type initialized_value e.g., var1 DWORD 1000h
.CODE
(.code directive marks the beginning of the code segment, where all executable
statements in a program are located) The .CODE directive identifies the area of a
program that contains instructions)
MAIN PROC ;(The PROC directive identifies the
beginning of a procedure. The
PROC directive identifies the beginning of
a procedure (known as functions in
C/C++).

mov ax,@data ;initialize the DS register


mov ds, ax ;(These two instructions are required to
initialize the data
register (DS) to the
starting location of
the data segment,
identified by the
predefined MASM
constant @data)

mov ax, 4c00h ;end program


int 21h ; an also be used to end program instead of
Exit mov ax,4c00 etc
(The EXIT statement (indirectly) calls a
predefined MS windows function that halts
the program)

TEMPLATE #2

. MODEL SMALL
. DATA
.CODE
.STARTUP

; your code here

.EXIT
END

CASE Institute Page 4 of 7


CS-2202 Computer Organization and Assembly Language
Lab 6: Microsoft Macro-Assembler MASM, MS-dos function calls INT21h
and call of procedure DUMPREGS of Irvine library in programs.

Directives:
A directive is a command that is recognized and acted upon by the assembler as the
program’s source code is being assembled. Directives are part of assembler’s syntax but
are not related to the intel instruction set Following directives have been used in the
above program template

TITLE
.CODE
INCLUDE
PROC
ENDP
END

Use of MS-DOS function calls (INT 21h):


There are some 90 different functions supported by this interrupt identified by a function
number placed in AH register. The data that has to be passed to int 21h should be in dx
register.

Characters
We can call MS DOS INT 21h function 6 by loading 6 into the ah register and loading into dl, the
character to be displayed
e.g.
mov ah,6 ; call DOS function 06
mov dl,”*” ; character to be displayed
int 21h

Strings
A string is declared in this way in the .DATA portion of your assembly.
string byte 'NAME ','$'

For writing string on output


We can call MS DOS INT 21h function 9 by loading 9 into the ah register and loading the offset
of the string in to dx.
i.e.
mov ah, 09
mov dx, offset string
INT 21h
For this the string must be ending with $ sign character ($).
How to run program:
Given the filename as “regsum” which saving after editing the program,
Go into dos prompt e.g. C:>

CASE Institute Page 5 of 7


CS-2202 Computer Organization and Assembly Language
Lab 6: Microsoft Macro-Assembler MASM, MS-dos function calls INT21h
and call of procedure DUMPREGS of Irvine library in programs.

Change directory to MASM615 by typing


C:\> cd masm615
C:\MASM615>
Type make16 and filename
C:\MASM615> make16 regsum
The program will be assembled and all relavent files will be created
To run the program type the filename
C:\ MASM615>regsum

Lab Tasks

Lab Task No.1:


Use MS-DOS function calls int 21h to display a character on the screen. Assemble this
program using MASM615 and run it. Note: Use template 2 for this problem.

Lab TaskNo:2
Write a program using call DOS function 06 to display your name on the screen (Each
character one by one). Note: Use template 2 for this problem.

Lab TaskNo:3
Write a program using call DOS function 09 to display your name on the screen. You can
use any template.

Lab Task No.4:


Write a program that adds and displays two register values. Take one number in ax
register and the other in register bx. Store sum result in ax and display the register value.
Display necessary statements along with the output (Use template 1)

CASE Institute Page 6 of 7


CS-2202 Computer Organization and Assembly Language
Lab 6: Microsoft Macro-Assembler MASM, MS-dos function calls INT21h
and call of procedure DUMPREGS of Irvine library in programs.

Lab #06 Marks Distribution


ER1 ER6 ER8
4 Points 3 Points 3 Points

Lab#06 Rubrics Evaluation Guideline:

# Qualities & 0 < Poor <=1 1 < Satisfactory <= 2 2.5 < Excellent <= 4
Criteria
Task Minimal or Some tasks were All tasks were completed,
ER1 Completion no program completed, but the and the program runs
functionality program has errors or without errors.
was incomplete functionalities.
achieved.
# Qualities & 0 < Poor <=1 1 < Satisfactory <= 2 2.5 < Excellent <= 3
Criteria
ER6 Program Output is Output is mostly accurate Output is clear, accurate,
Output inaccurate or but may lack labels, and well presented with
poorly captions, or formatting. labels, captions, and proper
presented. formatting.
# Qualities & 0 < Poor <=1 1 < Satisfactory <= 2 2.5 < Excellent <= 3
Criteria
ER8 Question & Answers Answers most questions Answers all questions
Answer some confidently and based on confidently and
questions but lab task knowledge. demonstrates a deep
not understanding of the given
confidently lab task.
or based on
lab task
knowledge.

CASE Institute Page 7 of 7

You might also like