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

Implementation of Masm (Microsoft Macro Assembler) Assembler

MASM assembler programs are written as collections of segments belonging to classes like CODE, DATA, and STACK. Segments are addressed using registers like CS, DS, ES, FS, and GS that are set by the system loader. Jumps can be near within the same code segment or far to another segment, requiring the programmer to specify. MASM assembles jumps correctly whether forward references or to other segments. Segment code can be written in multiple parts that are gathered together, with references between assembled modules handled by a linker.

Uploaded by

Anila Johnson
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)
1K views

Implementation of Masm (Microsoft Macro Assembler) Assembler

MASM assembler programs are written as collections of segments belonging to classes like CODE, DATA, and STACK. Segments are addressed using registers like CS, DS, ES, FS, and GS that are set by the system loader. Jumps can be near within the same code segment or far to another segment, requiring the programmer to specify. MASM assembles jumps correctly whether forward references or to other segments. Segment code can be written in multiple parts that are gathered together, with references between assembled modules handled by a linker.

Uploaded by

Anila Johnson
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/ 2

IMPLEMENTATION OF MASM(MICROSOFT Macro Assembler) ASSEMBLER

 A MASM assembler language program is written as a collection of segments.


 Each segment is defined as belonging to a particular class, corresponding to its contents.
 Commonly used classes are CODE, DATA,CONST,STACK.
 Code segments are addressed using register CS.
 Stack segments are addressed using register SS.
 These segment registers are automatically set by the system loader for execution.
 Register CS is set to indicate the last stack segment processed by the loader.
 Data segments (including constant segments) are normally addressed using. DS, ES, FS,
or GS.
 The segment register to be used can be specified explicitely by the programmer (by
writing it as part of the assembler language instruction).
 If the programmer does not specify a segment register, one is selected by the assembler.
 By default the assembler assumes that all references to data segments use register DS.
 This assumption can be changed by the assembler directive ASSUME.
ASSUME ES : DATASEG2
 Registers DS,ES,FS and GS must be loaded by the program before they can be used to
address data segments.
 ASSUME tells MASM the contents of a segment register.
 The programmer must provide instructions to load this register when the program is
executed.
 Jump instructions are assembled in 2 different ways, depending on wheather the target of
the jump is in the same code segment as the jump instruction.
 A near jump is a jump to a target in the same code segment.
 A far jump is a jump to a target in a different code segment.

JMP TARGET
 If the definition of the label TARGET occurs in the program before the jump instruction,
the assembler can tell wheather this is a near jump or a far jump.
 If this is a forward reference to TARGET, the assembler does not know how many bytes
to reserve for the instruction.
 By default MASM assumes that a forward jump is a near jump.
 If the target of the jump is in another code segment, the programmer must warn the
assembler by writing
JMP FAR PTR TARGET
 If the jump address is within 128 bytes of the current instruction the programmer can
specify the shorter near jump by writing
JMP SHORT TARGET

 If the JMP to TARGET is a far jump the programmer specifies FAR PTR.
 During pass 1 , the assembler reserves 3 bytes for jump instruction.
 The actual assembled instruction requires 5 bytes.
 In the earlier versions of MASM, this caused an assembler error,called a phase error.
 In later version of MASM , the assembler can repeat pass 1 to generate the correct
location counter values.
 Segment is an MASM source program can be written in more than one part.
 If a segment directive specifies the same name as a previously defined segment, it is
considered to be a continuation of that segment.
 All of the parts of a segment are gathered together by the assembly process.
 References between segments that are assembled together are automatically handled by
the assembler.
 External references between separately assembled modules must be handles by a linker.
 The object program from MASM may be in several different formats , to allow easy and
efficient execution of the program in a veriety of operating environments.

You might also like