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

Manual Masm

The document discusses Microsoft Macro Assembler (MASM), an x86 assembler that supports macros and structured programming. It describes how MASM converts assembly code to machine code. The key steps are: 1) writing assembly code, 2) assembling the code using MASM to generate an object file, 3) linking the object file to create an executable, and 4) debugging the executable using the DEBUG program to step through it. MASM provides many features and directives to make assembly language programming more productive.

Uploaded by

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

Manual Masm

The document discusses Microsoft Macro Assembler (MASM), an x86 assembler that supports macros and structured programming. It describes how MASM converts assembly code to machine code. The key steps are: 1) writing assembly code, 2) assembling the code using MASM to generate an object file, 3) linking the object file to create an executable, and 4) debugging the executable using the DEBUG program to step through it. MASM provides many features and directives to make assembly language programming more productive.

Uploaded by

Ashok Rachapalli
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

MUFFAKHAM JAH COLLEGE OF ENGINEERING & TECHNOLOGY

INTRODUCTION TO MASM

The Microsoft macro assembler is an x86 high level assembler for DOS and Microsoft
windows. It supports wide varieties of macro facilities and structured programming
idioms including high level functions for looping and procedures

A program called assembler used to convert the mnemonics of instructions along with
the data into the equivalent object code modules, these object code may further
converted into executable code using linked and loader programs. This type of program
is called as ASSEMBLY LANGUAGE PROGRAMMING. The assembler converts and
Assembly language source file to machine code the binary equivalent of the assembly
language program. In this respect, the assembler reads an ASCII source file from the
disk and program as output. The major different between compilers for a high level
language like PASCAL and an Assembler is that the compiler usually emits several
machine instructions for each PASCAL statement. The assembler generally emits a
single machine instruction for each assembler language statement.

Attempting to write a program in machine language is not particularly bright. This


process is very tedious, mistakes, and offers almost no advantages over programming in
assembly language. The major disadvantages over programming in assembly language
over pure machine code are that you must first assemble and link a program before you
can execute it. However attempting to assemble the code by hand would take for longer
than the small amount of time that the assembler takes the perform conversion for you.
An assembler like Microsoft Macro Assembler (MASM) provides a large number of
features for assembly language programmers. Although learning about these features
take a fair amount of time. They are so useful that it is well worth the effort.

Microsoft MASM version 6.11 contains updated software capable of processing


printing instructions. Machine codes and instruction cycle counts are generated by
MASM for all instructions on each processor beginning with 8086. To assemble the
file PROG.ASM use this command: (better to use DOS command line)

MASM PROG.ASM
The MASM program will assemble the PROG.ASM file. (To create PROG.OBJ
from PROG.ASM)

To create PROG.EXE from PROG.OBJ, use this LINK command:


LINK PROG.OBJ
It converts the contents of PROG.OBJ into PROG.EXE.

To link more than one object file use + signs between their file names as in:

MICROPROCESSORS & MICROCONTROLERS LAB


MUFFAKHAM JAH COLLEGE OF ENGINEERING & TECHNOLOGY

LINK PROGA+PROGB+PROGC

The following is a list of MASM reserved words:


ASSUME assume definition
CODE begin code segment
DATA begin data segment DB define byte
DD define double word
DQ define quad word
DS define storage
DUP duplicate
DW define word
ELSE else statement
END end program
ENDM end macro
ENDIF end if statement
ENDP end procedure
ENDS end segment
EQU equate
IF if statement
FAR far reference
MACRO define macro
.MODEL model type
NEAR near reference
OFFSET offset
ORQ origin
PARA paragraph
PROC define procedure
.EXIT generate exit code
PUBLIC public reference
SEG locate segment
SEGMENT define segment
PTR pointer

USING DEBUG TO EXECUTE THE 80x86 PROGRAM:

DEBUG is a utility program that allows a user to load an 80x 86 programs into
memory and execute it step by step. DEBUG displays the contents of all processor
registers after each instruction execute, allowing the user to determine if the code is
performing the desired task. DEBUG only displays the 16-bit portion of the general
purpose registers. Code view is capable of displaying the entire 32 bits. DEBUG is a
very useful debugging tool. We will use DEBUG to step through a number of simple
programs, gaining familiarity with Debug’s commands as we do so. DEBUG
contains commands that can display and modify memory, assemble instructions,

MICROPROCESSORS & MICROCONTROLERS LAB


MUFFAKHAM JAH COLLEGE OF ENGINEERING & TECHNOLOGY

disassemble code already placed into memory, trace single or multiple instructions,
load registers with data and do much more.

DEBUG loads into memory like any other program, in the first available slot.
The memory space used by DEBUG for the user program begins after the end of
Debug’s code. If an .EXE or .COM file were specified, DEBUG would load the
program according to accepted DOS conventions.

To execute the program file PROG.EXE use this command

DEBUG PROG.EXE

DEBUG uses a minus sign as its command prompt, so should see a “-“ appear on
display.

To get a list of some commands available with DEBUG is :

T trace (step by step execution)


U un assemble
D dump
G go (complete execution)
H Hex

To execute the program file PROG.ASM use the following procedure:


.MASM PROG.ASM
.LINK PROG.OBJ
.DEBUG PROG.EXE

ASSEMBLER DIRECTIVES: The limits are given to the assembler using some pre
defined alphabetical strings called Assembler Directives which help assembler to
correctly understand. The assembly language programs to prepare the codes.
DB GROUP EXTRN
DW LABEL TYPE
DQ LENGTH EVEN
DT LOCAL SEGMENT
ASSUME NAME
END OFFSET
ENDP ORG
ENDS PROC
EQU PTR

DB-Define Byte: The DB drive is used to reserve byte of memory locations in the available
on memory.

MICROPROCESSORS & MICROCONTROLERS LAB


MUFFAKHAM JAH COLLEGE OF ENGINEERING & TECHNOLOGY

DW-Define Word: The DW drive is used to reserve 16 byte of memory location available
on memory.

DQ-Define Quad Word (4 words): The DB directives is used to reserve 8 bytes of memory
locations in the memory available.

DT-Define Ten Byte: The DT directive is used to reserve 10 byte of memory locations in
the available memory.

ASSUME: Assume local segment name the Assume directive is used to inform the
assembler. The name of the logical segments to be assumed for different segment used in
programs.

END: End of the program the END directive marks the end of an ALP.

ENDP: End of the procedure.


ENDS: End of the segment.
EQU: The directive is used to assign a label with a variable or symbol. The directive is just
to reduce recurrence of the numerical values or constants in the program.

OFFSET: Specifies offset address.


SEGMENT: The segment directive marks the starting of the logical segment.

EXECUTION OF ASSEMBLY LANGUAGE PROGRAMMING IN MASM SOFTWARE:


Assembly language programming has 4 steps.
1. Entering Program
2. Compile Program
3. Linking a Program
4. Debugging a Program

PROCEDURE:
1. Entering Program:-
Start Menu
Run
Cmd
C:\cd MASM
C:\ MASM> edit filename.asm

C:\MASM\filename.asm
This is editor
Enter program here

After entering program save & exit (ALT F & Press S or ALT F &Press X)
C:\MASM>
2. Compile the Program:-
C:\MASM> MASM filename.asm

MICROPROCESSORS & MICROCONTROLERS LAB


MUFFAKHAM JAH COLLEGE OF ENGINEERING & TECHNOLOGY

Microsoft @macro assembler version 5.10


Copy rights reserved© Microsoft
Corp 1981 All rights reserved
Object filename [OBJ];
List filename [NUL, LIST];
Cross Reference [NUL, CRF];
Press enter the screen shows c>

3. Linking a Program:-

c> link filename.obj


Microsoft @ overlay linker version 3.64
Copy rights reserved© Microsoft corp.
1983-88. All rights reserved
Object module [.OBJ];
Run file [.EXE];
List [NUL MAP];
Libraries [LIB];
Press enter till screen chows c>

4. Debug a Program:-
C> debug filename.exe
- (Screen shows only dash)
-t
‘t’ for trace the program execution by single stepping starting from the address
SEG.OFFSET. ‘q’ for Quit from Debug & return to DOS.

MICROPROCESSORS & MICROCONTROLERS LAB

You might also like