SlideShare ist ein Scribd-Unternehmen logo
1 von 13
1


                                        UNIT III – MASM86

The Microsoft Macro Assembler (MASM) is an x86 assembler that uses the Intel syntax for MS-
DOS and Microsoft Windows. The earlier versions were released in the year 1981 .Turbo
Assembler (TASM) is also         an assembler package developed by Borland which runs on and
produces code for 16- or 32-bit x86 MS-DOS or Microsoft Windows. These softwares provide
the assembly language tools to program the 8086 processor based systems.

To program the x86 processors using in MASM , certain concepts are very important. They are
reserved words, identifiers, predefined symbols, constants, expressions, operators, data types, registers,
and statements.

Reserved Words : A reserved word has a special meaning fixed by the language. This must be
used under certain special conditions. These reserved words are
        Instructions, which correspond to operations the processor can execute.
        Directives, which give commands to the assembler.
        Attributes, which provide a value for a field, such as segment alignment.
        Operators, which are used in expressions.

MASM reserved words are not case sensitive except for predefined symbols. The assembler
generates an error if you use a reserved word as a variable.

For Ex: The following operands are reserved words. Reserved words are not case sensitive.

        $                 DWORD                PASCAL                       SWORD
         ?                  FAR                QWORD                       SYSCALL
       @B                  FAR16                REAL4                        TBYTE
       @F               FORTRAN                 REAL8                      VARARG
     ADDR                 FWORD                 REAL10                       WORD
     BASIC                 NEAR                 SBYTE                        ZERO?
      BYTE                NEAR16               SDWORD
        C              OVERFLOW?                 SIGN?
    CARRY?               PARITY?              STDCALL
2


Predefined Symbols :Unlike most MASM reserved words, predefined symbols are case
sensitive.

             @CatStr*                      @Environ*                         @Model*
              @code                         @fardata                         @SizeStr*
             @CodeSize                      @fardata?                         @stack*
               @Cpu                        @FileCur*                         @SubStr*
             @CurSeg                       @FileName                         @Time*
               @data                        @InStr*                          @Version
             @DataSize                     @Interface*                      @WordSize
              @Date*                         @Line*                          @Model*



Registers :

             AH                      CS                        DX                         SI

             AL                     CX                        EAX                         SP
             AX                     DH                        EBP                         SS

             BH                      DI                       EBX                        ST
             BL                      DL                       ECX                        TR3*
             BP                     DR0                       EDI                        TR4*
             BX                     DR1                       EDX                        TR5*
             CH                     DR2                        ES                        TR6
             CL                     DR3                        ESI                       TR7



Identifiers : An identifier is a name that you invent and attach to a definition. Identifiers can be
symbols representing variables, constants, procedure names, code labels, segment names, and
user-defined data types such as structures, unions, records, and types defined with TYPEDEF.
Identifiers longer than 247 characters generate an error.


        The first character of the identifier can be an alphabetic character (A–Z) or any of these
        four characters : @ , _ , $ , ?
3


        The other characters in the identifier can be any of the characters listed above or a
       decimal digit (0–9).


Predefined Symbols : The assembler includes a number of predefined symbols (also called
predefined equates). These symbols can be used at any point in the code to represent the equate
value. For example, the predefined equate @ FileName represents the base name of the current
file. If the current source file is TASK.ASM , the value of @File Name is TASK.
Integer Constants and Constant Expressions : An integer constant is a series of one or more
numerals followed by an optional radix specifier. For example, in the following statements

       mov ax, 25
       mov bx, 0B3h

the numbers 25 and 0B3h are integer constants.


Operators : Operators are used in expressions. The assembler evaluates expressions that contain
more than one operator according to the following rules.

        Operations in parentheses are performed before adjacent operations.
        Binary operations of highest precedence are performed first.
        Operations of equal precedence are performed from left to right.
        Unary operations of equal precedence are performed right to left.

Examples of the operators are : + ,– (unary) , &, *, /, MOD, SHL, SHR , +, – (binary) , EQ,
NE, LT, LE, GT, GE NOT , AND , OR, XOR , OPATTR, SHORT, .TYPE

Data Types : A “data type” describes a set of values.For example ,BYTE, SBYTE, WORD,
SWORD, DWORD, SDWORD, FWORD, QWORD, and TBYTE.

Registers : The 8086 family of processors have a           set of 16-bit registers. They are AX,
BX,CX,DX (General purpose registers)         segment registers like ,SS.CS.DS.ES        and pointer
registers like SP,BP and Index registers like DI and SI etc…

Statements : Statements are the line-by-line components of source files. Each MASM statement
specifies an instruction or directive for the assembler. Statements have up to four fields,
[[name:]] [[operation]] [[operands]] [[;comment]]
4


Assembly Language Development Tools :

       To develop an assembly language program we need certain program development tools .
The various development tools required for 8086 programming are explained below.

1. Editor : An Editor is a program which allows us to create a file containing the assembly
language statements for the program. Examples of some editors are PC write, Word-star. As we
type the program the    editor stores the ACSII codes for the letters and numbers in successive
RAM locations. If any typing mistake is done editor will alert us to correct it. If we leave out a
program statement an editor will let you move everything down and insert a line. After typing all
the program we have to save the program for a hard disk. This we call it as source file. The next
step is to process the source file with an assembler. While using TASM or MASM we should
give a file name and extension .ASM.

Ex: Sample. asm

2.Assembler : An Assembler is used to translate the assembly language mnemonics into
machine language( i.e binary codes). When you run the assembler it reads the source file of your
program from where you have saved it. The assembler generates two files . The first file is the
Object file with the extension     .OBJ. The object file consists of the binary codes for the
instructions and information about the addresses of the instructions. After further processing,
the contents of the file will be loaded in to memory and run. The second file is the assembler list
file with the extension .LST.

3. Linker : A linker is a program used to connect several object files into one large object file.
While writing large programs it is better to divide the large program into smaller modules. Each
module can be individually written, tested and debugged. Then all the object modules are linked
together to form one, functioning program. These object modules can also be kept in library file
and linked into other programs as needed. A linker produces a link file which contains the binary
codes for all the combined modules. The linker also produces a link map file which contains the
address information about the linked files. The linkers which comes with TASM or MASM
assemblers produce link files with the .EXE extension.
5


4. Locator : A locator is a program used to assign the specific addresses of where the segments
of object code are to be loaded into memory. A locator program called EXE2BIN comes with the
IBM PC Disk Operating System (DOS). EXE2BIN converts a .EXE file to a .BIN file which has
physical addresses.

5. Debugger: A debugger is a program which allows          to load your object code program into
system memory, execute      the program, and troubleshoot or debug it. The debugger allows to
look into the contents of registers and memory locations after the program runs. We can also
change the contents of registers and memory locations and rerun the program. Some debuggers
allows    to stop the program after each instruction so that you can check or alter memory and
register contents. This is called single step debug. A debugger also allows to set a breakpoint at
any point in the program. If we insert a break point , the debugger will run the program up to the
instruction where the breakpoint is put and then stop the execution.

6. Emulator: An emulator is a mixture of hard ware and software. It is usually used to test and
debug the hardware and software of an external system such as the prototype of a microprocessor
based instrument.

ASSEMBLER DIRECTIVES:

         Assembler directives are the directions to the assembler which indicate how an operand
or section of the program is to be processed. These are also called pseudo operations which are
not executable by the microprocessor. The various directives are explained below.

1. ASSUME : The ASSUME directive is used to inform the assembler the name of the logical
segment it should use for a specified segment.

Ex: ASSUME DS : DATA tells the assembler that for any program instruction which refers to
the data segment ,it should use the logical segment called DATA.

2.DB : Define byte. It is used to declare a byte variable or set aside one or more storage locations
of type byte in memory.

For example, CURRENT_VALUE DB 36H tells the assembler to reserve 1 byte of memory for
a variable named CURRENT_ VALUE and to put the value 36 H in that memory location when
the program is loaded into RAM .
6


3. DW : Define word. It tells the assembler to define a variable of type word or to reserve
storage locations of type word in memory.

4. DD(define double word) :This directive is used to declare a variable of type double word or
restore memory locations which can be accessed as type double word.

5.DQ (define quadword) :This directive is used to tell the assembler to declare a variable 4
words in length or to reserve 4 words of storage in memory .

6.DT (define ten bytes):It is used to inform the assembler to define a variable which is 10 bytes
in length or to reserve 10 bytes of storage in memory.

7. EQU : Equate It is used to give a name to some value or symbol. Every time the assembler
finds the given name in the program, it will replace the name with the value or symbol we have
equated with that name

8.ORG : Originate : The ORG statement changes the starting offset address of the data.

It allows to set the location counter to a desired value at any point in the program. For example
the statement ORG 3000H tells the assembler to set the location counter to 3000H.

9 .PROC- Procedures: It is used to identify the start of a procedure. Or subroutine.

10. END- End program .This directive indicates the assembler that this is the end of the program
module. The assembler ignores any statements after an END directive.

11. ENDP- End procedure: It indicates the end of the procedure (subroutine) to the assembler.

12.ENDS-End Segment: This directive is used with the name of the segment to indicate the end
of that logical segment.

Ex: CODE SEGMENT : Start of logical segment containing code

    CODE ENDS            : End of the segment named CODE.
7


SIMPLE EXAMPLES :

Program: Multiplication

code segment assume cs : code
start: mov ax,10h
       mov bx,2h
       mul bx
       mov cx,ax
       int 21h
 code ends
  end.

Program : Display Data

data segment
  datas db 'I am an Indian $'
data ends
code segment         assume cs:code,ds:data
 start : mov ax,data
         mov ds,ax
        lea dx,datas
        mov ah,09h
         int 21h
code ends
end start

Program : Addition

code segment assume cs: code
 start : mov ax,3h
         mov bx,3h
        add ax,bx
        mov ah,4ch
        code ends
  end

Program : Seven segment

data ends
code segment
      assume cs: code,ds:data
loop2: mov ax,data
        mov ds,ax
        mov dx,0d803h
        mov al,80h
        out dx,al
        lea bx,datas
8


        mov cl,10h
 loop1: mov al, [bx]
         mov dx,0d800h
         out dx,al
         call delay
         inc bx
         dec cl
         jnz loop1
         jmp loop2
delay proc near
         push cx
         push bx
         mov cx, 07feh
back2 : mov bx,0ffffh
back1: dec bx
         jnz back1
         loop back2
         pop bx
         pop cx
         ret
delay endp

Program : Seven-segment
data segment
 datas db 3fh,06h,5bh,4fh,66h,6dh,7dh,07h
            db 7fh,6fh,77h,7ch,39h,5eh,79h,71h
data ends
code segment
      assume cs:code,ds:data
 loop2 : mov ax,data
         mov ds,ax
         mov dx,0d803h
         mov al,80h
         out dx,al
         lea bx,datas
         mov cl,10h
  loop1: mov al,[bx]
         mov dx,0d800h
         out dx,al
        call delay
        inc bx
        dec cl
        jnz loop1
        jmp loop2
 delay proc near
        push cx
        push bx
        mov cx,07feh
9


back2: mov bx,0ffffh
 back1: dec bx
 jnz back1
         loop back2
          pop bx
         pop cx
         ret
 delay endp

program:Factorial

code segment
     assume cs:code
     mov ax,200
     mov ss,ax
     mov sp,2000
     sub sp,0004h
     mov ax,6
     push ax
     call facto
     pop ax
     nop
     nop
     nop
  facto proc near
      pushf
      push ax
      push dx
      push bp
      mov bp,sp
      mov ax,[bp+10]
      cmp ax,0001h
      jne go_on
      mov word ptr [bp+12],0001h
      mov word ptr [bp+14],0000h
      jmp exit
  go_on : sub sp,0004h
      dec ax
      push ax
      call facto
      mov bp,sp
      mov ax,[bp+2]
      mul word ptr [bp+16]
      mov [bp+18],ax
      mov [bp+20],dx
      add sp,0006h
   exit : pop bp
      pop dx
10


     pop ax
     popf
     ret
             facto endp
       code ends
       end

Program :Message Display

assume cs:code,ds:data
data     segment
message db 0dh,0ah,"mallika is the student of m.sc",0dh,0ah,"$"
              ;preparing string of the message
data ends
code segment
start: mov ax,data ; initializes ds
       mov ds,ax
       mov ah,09 ; set function value for display
       mov dx, offset message
       int 21h ; point to message and run
       mov ah,4ch ; the interrupt
       int 21h ; return to dos
code      ends
 end start

Program : Read Numbes Macro
MOV AH,01H
INT 21H
SUB AL,'0'
MOV BH,0AH
MUL BH
MOV NUM,AL
MOV AH,01H
INT 21H
SUB AL,'0'
ADD NUM,AL
ENDM

PRINTSTRING MACRO MSG
MOV AH,09H
MOV DX,OFFSET MSG
INT 21H
ENDM

DATA SEGMENT
CR EQU 0DH
LF EQU 0AH
MSG DB CR,LF,'ENTER NUMBER','$'
11


MSG1 DB CR,LF,'RESULT: ','$'
NUM1 DB ?
NUM2 DB ?
RES DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
PRINTSTRING MSG
READNUM NUM1
PRINTSTRING MSG
READNUM NUM2
MOV AH,00H
MOV AL,NUM1
ADD AL,NUM2
MOV RES,AL
MOV SI,OFFSET RES
CALL HEX2ASC
PRINTSTRING MSG1
PRINTSTRING RES
MOV AH,4CH
MOV AL,00H
INT 21H

HEX2ASC PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH SI
MOV CX,00H
MOV BX,0AH
RPT1:
MOV DX,00
DIV BX
ADD DL,'0'
PUSH DX
INC CX
CMP AX,0AH
JGE RPT1
ADD AL,'0'
MOV [SI],AL
RPT2:
POP AX
INC SI
MOV [SI],AL
12


LOOP RPT2
INC SI
MOV AL,'$'
MOV [SI],AL
POP SI
POP DX
POP CX
POP BX
POP AX
RET
HEX2ASC ENDP
CODE ENDS
END START

Program: Multibyte addition
DATA SEGMENT
N1 DB 11H, 22H, 33H
N2 DB 22 H, 33H, 44H
RESULT DB 3H DUP (00)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV SI, OFFSET N1
MOV DI, OFFSET N2
MOV BX, OFFSET RESULT
CLC
MOV CX, 0003H
MOV AX, 0000H
BACK: MOV AL, [SI]
MOV DL, [DI]
ADC AL, DL
MOV [BX], AL
INC SI
INC DI
INC BX
DEC CX
JNZ BACK
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START

RESULT: 11H 22H 33H
        22H 33H 44H
        33H 55 H 77H



Program: Multi byte Multiplication
13


DATA SEGMENT
N1 DB 03H, 05 H, 07 H
N2 DB 05 H, 03H, 02H
RESULT DB 4H DUP (00)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV SI, OFFSET N1
MOV DI, OFFSET N2
MOV BX, OFFSET RESULT
MOV CL, 03H
MOV AX, 0000H
MOV DX, 0000H
BACK: MOV AL, [SI]
MOV CH, [DI]
MUL DH
MOV [BX], AL
INC SI
INC DI
INC BX
LOOP BACK
MOV AH, 4CH
INT 21H
INT 3H
CODE ENDS
END START

RESULT: 03H 05H 07H
        05H 03H 02H
        0FH 0FH 0EH

References :
1. Programmer’s Guide, Microsoft MASM, Micro soft Corporation.
2.Microprocessor and Interfacing –D.V.Hall,TMH

Weitere ähnliche Inhalte

Was ist angesagt?

Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphsTilakpoudel2
 
Minimum Modes and Maximum Modes of 8086 Microprocessor
Minimum Modes and Maximum Modes of 8086 MicroprocessorMinimum Modes and Maximum Modes of 8086 Microprocessor
Minimum Modes and Maximum Modes of 8086 MicroprocessorNikhil Kumar
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
8237 dma controller
8237 dma controller8237 dma controller
8237 dma controllerTech_MX
 
Control structures in java
Control structures in javaControl structures in java
Control structures in javaVINOTH R
 
Programmable Logic Array(PLA) & Programmable Array Logic(PAL)
Programmable Logic Array(PLA) & Programmable Array Logic(PAL)Programmable Logic Array(PLA) & Programmable Array Logic(PAL)
Programmable Logic Array(PLA) & Programmable Array Logic(PAL)Revathi Subramaniam
 
Data transfer and manipulation
Data transfer and manipulationData transfer and manipulation
Data transfer and manipulationSanjeev Patel
 
flag register of 8086
flag register of 8086flag register of 8086
flag register of 8086asrithak
 
System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit IIManoj Patil
 
OPERATING OVERLOADING IN VHDL
OPERATING OVERLOADING IN VHDLOPERATING OVERLOADING IN VHDL
OPERATING OVERLOADING IN VHDLBLESSYDAISE PAUL
 
Difference b/w 8085 & 8086
Difference b/w 8085 & 8086Difference b/w 8085 & 8086
Difference b/w 8085 & 8086j4jiet
 
Polymorphism In c++
Polymorphism In c++Polymorphism In c++
Polymorphism In c++Vishesh Jha
 
Visibility control in java
Visibility control in javaVisibility control in java
Visibility control in javaTech_MX
 
Timing and control
Timing and controlTiming and control
Timing and controlchauhankapil
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programmingKamal Acharya
 

Was ist angesagt? (20)

Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphs
 
Minimum Modes and Maximum Modes of 8086 Microprocessor
Minimum Modes and Maximum Modes of 8086 MicroprocessorMinimum Modes and Maximum Modes of 8086 Microprocessor
Minimum Modes and Maximum Modes of 8086 Microprocessor
 
Shell programming
Shell programmingShell programming
Shell programming
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
8237 dma controller
8237 dma controller8237 dma controller
8237 dma controller
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Encapsulation C++
Encapsulation C++Encapsulation C++
Encapsulation C++
 
Programmable Logic Array(PLA) & Programmable Array Logic(PAL)
Programmable Logic Array(PLA) & Programmable Array Logic(PAL)Programmable Logic Array(PLA) & Programmable Array Logic(PAL)
Programmable Logic Array(PLA) & Programmable Array Logic(PAL)
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
Data transfer and manipulation
Data transfer and manipulationData transfer and manipulation
Data transfer and manipulation
 
flag register of 8086
flag register of 8086flag register of 8086
flag register of 8086
 
System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit II
 
OPERATING OVERLOADING IN VHDL
OPERATING OVERLOADING IN VHDLOPERATING OVERLOADING IN VHDL
OPERATING OVERLOADING IN VHDL
 
Difference b/w 8085 & 8086
Difference b/w 8085 & 8086Difference b/w 8085 & 8086
Difference b/w 8085 & 8086
 
Arithmetic and logical instructions
Arithmetic and logical instructionsArithmetic and logical instructions
Arithmetic and logical instructions
 
Polymorphism In c++
Polymorphism In c++Polymorphism In c++
Polymorphism In c++
 
Visibility control in java
Visibility control in javaVisibility control in java
Visibility control in java
 
Timing and control
Timing and controlTiming and control
Timing and control
 
Interrupts and types of interrupts
Interrupts and types of interruptsInterrupts and types of interrupts
Interrupts and types of interrupts
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 

Andere mochten auch (20)

Masm tutorial
Masm tutorialMasm tutorial
Masm tutorial
 
Linking in MS-Dos System
Linking in MS-Dos SystemLinking in MS-Dos System
Linking in MS-Dos System
 
System software
System softwareSystem software
System software
 
Micro Assembler
Micro AssemblerMicro Assembler
Micro Assembler
 
Mp &mc programs
Mp &mc programsMp &mc programs
Mp &mc programs
 
Two pass Assembler
Two pass AssemblerTwo pass Assembler
Two pass Assembler
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architecture
 
Step to program in tasm
Step to program in tasmStep to program in tasm
Step to program in tasm
 
Assembler design options
Assembler design optionsAssembler design options
Assembler design options
 
Linkers
LinkersLinkers
Linkers
 
8086 class notes-Y.N.M
8086 class notes-Y.N.M8086 class notes-Y.N.M
8086 class notes-Y.N.M
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loaders
 
Macros...presentation
Macros...presentationMacros...presentation
Macros...presentation
 
X86 assembly nasm syntax
X86 assembly nasm syntaxX86 assembly nasm syntax
X86 assembly nasm syntax
 
It322 intro 4
It322 intro 4It322 intro 4
It322 intro 4
 
TASM PROFILE
TASM PROFILETASM PROFILE
TASM PROFILE
 
Assembly
AssemblyAssembly
Assembly
 
Language 8086
Language 8086Language 8086
Language 8086
 
Assembly final 2
Assembly final 2Assembly final 2
Assembly final 2
 
Unit 5
Unit 5Unit 5
Unit 5
 

Ähnlich wie MASM -UNIT-III

Lab 5 - String Manipulation usingTASM Environment-1.docx
Lab 5 - String Manipulation usingTASM Environment-1.docxLab 5 - String Manipulation usingTASM Environment-1.docx
Lab 5 - String Manipulation usingTASM Environment-1.docxCCSSenatorAbogadoAj
 
Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assemblyAbdul Khan
 
Chapter 2 programming concepts - I
Chapter 2  programming concepts - IChapter 2  programming concepts - I
Chapter 2 programming concepts - ISHREEHARI WADAWADAGI
 
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming BasicsReversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basicssecurityxploded
 
DATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMDATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMSonia Pahuja
 
intro to assembly language.pptx
intro to assembly language.pptxintro to assembly language.pptx
intro to assembly language.pptxEdFeranil
 
Introduction to debugging linux applications
Introduction to debugging linux applicationsIntroduction to debugging linux applications
Introduction to debugging linux applicationscommiebstrd
 
Introduction to Assembly Language
Introduction to Assembly Language Introduction to Assembly Language
Introduction to Assembly Language ApekshaShinde6
 
Convention-Based Syntactic Descriptions
Convention-Based Syntactic DescriptionsConvention-Based Syntactic Descriptions
Convention-Based Syntactic DescriptionsRay Toal
 
Plsql quick guide
Plsql quick guidePlsql quick guide
Plsql quick guide1bi08me024
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolMashaelQ
 
Variables: names, bindings, type, scope
Variables: names, bindings, type, scopeVariables: names, bindings, type, scope
Variables: names, bindings, type, scopesuthi
 
Unit 3 assembler and processor
Unit 3   assembler and processorUnit 3   assembler and processor
Unit 3 assembler and processorAbha Damani
 
Mainframe refresher-part-1
Mainframe refresher-part-1Mainframe refresher-part-1
Mainframe refresher-part-1vishwas17
 

Ähnlich wie MASM -UNIT-III (20)

7986-lect 7.pdf
7986-lect 7.pdf7986-lect 7.pdf
7986-lect 7.pdf
 
Lab 5 - String Manipulation usingTASM Environment-1.docx
Lab 5 - String Manipulation usingTASM Environment-1.docxLab 5 - String Manipulation usingTASM Environment-1.docx
Lab 5 - String Manipulation usingTASM Environment-1.docx
 
Wk1to4
Wk1to4Wk1to4
Wk1to4
 
Linker scripts
Linker scriptsLinker scripts
Linker scripts
 
Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assembly
 
Chapter 2 programming concepts - I
Chapter 2  programming concepts - IChapter 2  programming concepts - I
Chapter 2 programming concepts - I
 
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming BasicsReversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
 
DATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMDATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEM
 
intro to assembly language.pptx
intro to assembly language.pptxintro to assembly language.pptx
intro to assembly language.pptx
 
Introduction to debugging linux applications
Introduction to debugging linux applicationsIntroduction to debugging linux applications
Introduction to debugging linux applications
 
Introduction to Assembly Language
Introduction to Assembly Language Introduction to Assembly Language
Introduction to Assembly Language
 
Convention-Based Syntactic Descriptions
Convention-Based Syntactic DescriptionsConvention-Based Syntactic Descriptions
Convention-Based Syntactic Descriptions
 
Plsql quick guide
Plsql quick guidePlsql quick guide
Plsql quick guide
 
Lecture 01 2017
Lecture 01 2017Lecture 01 2017
Lecture 01 2017
 
MIPS Architecture
MIPS ArchitectureMIPS Architecture
MIPS Architecture
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
 
Variables: names, bindings, type, scope
Variables: names, bindings, type, scopeVariables: names, bindings, type, scope
Variables: names, bindings, type, scope
 
Perl Reference.ppt
Perl Reference.pptPerl Reference.ppt
Perl Reference.ppt
 
Unit 3 assembler and processor
Unit 3   assembler and processorUnit 3   assembler and processor
Unit 3 assembler and processor
 
Mainframe refresher-part-1
Mainframe refresher-part-1Mainframe refresher-part-1
Mainframe refresher-part-1
 

Mehr von Dr.YNM

Introduction to DSP.ppt
Introduction to DSP.pptIntroduction to DSP.ppt
Introduction to DSP.pptDr.YNM
 
Atmel.ppt
Atmel.pptAtmel.ppt
Atmel.pptDr.YNM
 
PIC Microcontrollers.ppt
PIC Microcontrollers.pptPIC Microcontrollers.ppt
PIC Microcontrollers.pptDr.YNM
 
Crystalstructure-.ppt
Crystalstructure-.pptCrystalstructure-.ppt
Crystalstructure-.pptDr.YNM
 
Basics of OS & RTOS.ppt
Basics of OS & RTOS.pptBasics of OS & RTOS.ppt
Basics of OS & RTOS.pptDr.YNM
 
Introducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptxIntroducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptxDr.YNM
 
Microcontroller-8051.ppt
Microcontroller-8051.pptMicrocontroller-8051.ppt
Microcontroller-8051.pptDr.YNM
 
Introduction to ASICs.pptx
Introduction to ASICs.pptxIntroduction to ASICs.pptx
Introduction to ASICs.pptxDr.YNM
 
VHDL-PRESENTATION.ppt
VHDL-PRESENTATION.pptVHDL-PRESENTATION.ppt
VHDL-PRESENTATION.pptDr.YNM
 
Basics of data communications.pptx
Basics of data communications.pptxBasics of data communications.pptx
Basics of data communications.pptxDr.YNM
 
CPLD & FPGA Architectures and applictionsplications.pptx
CPLD & FPGA Architectures and applictionsplications.pptxCPLD & FPGA Architectures and applictionsplications.pptx
CPLD & FPGA Architectures and applictionsplications.pptxDr.YNM
 
Transient response of RC , RL circuits with step input
Transient response of RC , RL circuits  with step inputTransient response of RC , RL circuits  with step input
Transient response of RC , RL circuits with step inputDr.YNM
 
CISC & RISC ARCHITECTURES
CISC & RISC ARCHITECTURESCISC & RISC ARCHITECTURES
CISC & RISC ARCHITECTURESDr.YNM
 
Lect 4 ARM PROCESSOR ARCHITECTURE
Lect 4 ARM PROCESSOR ARCHITECTURELect 4 ARM PROCESSOR ARCHITECTURE
Lect 4 ARM PROCESSOR ARCHITECTUREDr.YNM
 
Lect 3 ARM PROCESSOR ARCHITECTURE
Lect 3  ARM PROCESSOR ARCHITECTURE Lect 3  ARM PROCESSOR ARCHITECTURE
Lect 3 ARM PROCESSOR ARCHITECTURE Dr.YNM
 
Microprocessor Architecture 4
Microprocessor Architecture  4Microprocessor Architecture  4
Microprocessor Architecture 4Dr.YNM
 
Lect 2 ARM processor architecture
Lect 2 ARM processor architectureLect 2 ARM processor architecture
Lect 2 ARM processor architectureDr.YNM
 
Microprocessor Architecture-III
Microprocessor Architecture-IIIMicroprocessor Architecture-III
Microprocessor Architecture-IIIDr.YNM
 
LECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORSLECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORSDr.YNM
 
Microprocessor architecture II
Microprocessor architecture   IIMicroprocessor architecture   II
Microprocessor architecture IIDr.YNM
 

Mehr von Dr.YNM (20)

Introduction to DSP.ppt
Introduction to DSP.pptIntroduction to DSP.ppt
Introduction to DSP.ppt
 
Atmel.ppt
Atmel.pptAtmel.ppt
Atmel.ppt
 
PIC Microcontrollers.ppt
PIC Microcontrollers.pptPIC Microcontrollers.ppt
PIC Microcontrollers.ppt
 
Crystalstructure-.ppt
Crystalstructure-.pptCrystalstructure-.ppt
Crystalstructure-.ppt
 
Basics of OS & RTOS.ppt
Basics of OS & RTOS.pptBasics of OS & RTOS.ppt
Basics of OS & RTOS.ppt
 
Introducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptxIntroducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptx
 
Microcontroller-8051.ppt
Microcontroller-8051.pptMicrocontroller-8051.ppt
Microcontroller-8051.ppt
 
Introduction to ASICs.pptx
Introduction to ASICs.pptxIntroduction to ASICs.pptx
Introduction to ASICs.pptx
 
VHDL-PRESENTATION.ppt
VHDL-PRESENTATION.pptVHDL-PRESENTATION.ppt
VHDL-PRESENTATION.ppt
 
Basics of data communications.pptx
Basics of data communications.pptxBasics of data communications.pptx
Basics of data communications.pptx
 
CPLD & FPGA Architectures and applictionsplications.pptx
CPLD & FPGA Architectures and applictionsplications.pptxCPLD & FPGA Architectures and applictionsplications.pptx
CPLD & FPGA Architectures and applictionsplications.pptx
 
Transient response of RC , RL circuits with step input
Transient response of RC , RL circuits  with step inputTransient response of RC , RL circuits  with step input
Transient response of RC , RL circuits with step input
 
CISC & RISC ARCHITECTURES
CISC & RISC ARCHITECTURESCISC & RISC ARCHITECTURES
CISC & RISC ARCHITECTURES
 
Lect 4 ARM PROCESSOR ARCHITECTURE
Lect 4 ARM PROCESSOR ARCHITECTURELect 4 ARM PROCESSOR ARCHITECTURE
Lect 4 ARM PROCESSOR ARCHITECTURE
 
Lect 3 ARM PROCESSOR ARCHITECTURE
Lect 3  ARM PROCESSOR ARCHITECTURE Lect 3  ARM PROCESSOR ARCHITECTURE
Lect 3 ARM PROCESSOR ARCHITECTURE
 
Microprocessor Architecture 4
Microprocessor Architecture  4Microprocessor Architecture  4
Microprocessor Architecture 4
 
Lect 2 ARM processor architecture
Lect 2 ARM processor architectureLect 2 ARM processor architecture
Lect 2 ARM processor architecture
 
Microprocessor Architecture-III
Microprocessor Architecture-IIIMicroprocessor Architecture-III
Microprocessor Architecture-III
 
LECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORSLECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORS
 
Microprocessor architecture II
Microprocessor architecture   IIMicroprocessor architecture   II
Microprocessor architecture II
 

MASM -UNIT-III

  • 1. 1 UNIT III – MASM86 The Microsoft Macro Assembler (MASM) is an x86 assembler that uses the Intel syntax for MS- DOS and Microsoft Windows. The earlier versions were released in the year 1981 .Turbo Assembler (TASM) is also an assembler package developed by Borland which runs on and produces code for 16- or 32-bit x86 MS-DOS or Microsoft Windows. These softwares provide the assembly language tools to program the 8086 processor based systems. To program the x86 processors using in MASM , certain concepts are very important. They are reserved words, identifiers, predefined symbols, constants, expressions, operators, data types, registers, and statements. Reserved Words : A reserved word has a special meaning fixed by the language. This must be used under certain special conditions. These reserved words are Instructions, which correspond to operations the processor can execute. Directives, which give commands to the assembler. Attributes, which provide a value for a field, such as segment alignment. Operators, which are used in expressions. MASM reserved words are not case sensitive except for predefined symbols. The assembler generates an error if you use a reserved word as a variable. For Ex: The following operands are reserved words. Reserved words are not case sensitive. $ DWORD PASCAL SWORD ? FAR QWORD SYSCALL @B FAR16 REAL4 TBYTE @F FORTRAN REAL8 VARARG ADDR FWORD REAL10 WORD BASIC NEAR SBYTE ZERO? BYTE NEAR16 SDWORD C OVERFLOW? SIGN? CARRY? PARITY? STDCALL
  • 2. 2 Predefined Symbols :Unlike most MASM reserved words, predefined symbols are case sensitive. @CatStr* @Environ* @Model* @code @fardata @SizeStr* @CodeSize @fardata? @stack* @Cpu @FileCur* @SubStr* @CurSeg @FileName @Time* @data @InStr* @Version @DataSize @Interface* @WordSize @Date* @Line* @Model* Registers : AH CS DX SI AL CX EAX SP AX DH EBP SS BH DI EBX ST BL DL ECX TR3* BP DR0 EDI TR4* BX DR1 EDX TR5* CH DR2 ES TR6 CL DR3 ESI TR7 Identifiers : An identifier is a name that you invent and attach to a definition. Identifiers can be symbols representing variables, constants, procedure names, code labels, segment names, and user-defined data types such as structures, unions, records, and types defined with TYPEDEF. Identifiers longer than 247 characters generate an error. The first character of the identifier can be an alphabetic character (A–Z) or any of these four characters : @ , _ , $ , ?
  • 3. 3 The other characters in the identifier can be any of the characters listed above or a decimal digit (0–9). Predefined Symbols : The assembler includes a number of predefined symbols (also called predefined equates). These symbols can be used at any point in the code to represent the equate value. For example, the predefined equate @ FileName represents the base name of the current file. If the current source file is TASK.ASM , the value of @File Name is TASK. Integer Constants and Constant Expressions : An integer constant is a series of one or more numerals followed by an optional radix specifier. For example, in the following statements mov ax, 25 mov bx, 0B3h the numbers 25 and 0B3h are integer constants. Operators : Operators are used in expressions. The assembler evaluates expressions that contain more than one operator according to the following rules. Operations in parentheses are performed before adjacent operations. Binary operations of highest precedence are performed first. Operations of equal precedence are performed from left to right. Unary operations of equal precedence are performed right to left. Examples of the operators are : + ,– (unary) , &, *, /, MOD, SHL, SHR , +, – (binary) , EQ, NE, LT, LE, GT, GE NOT , AND , OR, XOR , OPATTR, SHORT, .TYPE Data Types : A “data type” describes a set of values.For example ,BYTE, SBYTE, WORD, SWORD, DWORD, SDWORD, FWORD, QWORD, and TBYTE. Registers : The 8086 family of processors have a set of 16-bit registers. They are AX, BX,CX,DX (General purpose registers) segment registers like ,SS.CS.DS.ES and pointer registers like SP,BP and Index registers like DI and SI etc… Statements : Statements are the line-by-line components of source files. Each MASM statement specifies an instruction or directive for the assembler. Statements have up to four fields, [[name:]] [[operation]] [[operands]] [[;comment]]
  • 4. 4 Assembly Language Development Tools : To develop an assembly language program we need certain program development tools . The various development tools required for 8086 programming are explained below. 1. Editor : An Editor is a program which allows us to create a file containing the assembly language statements for the program. Examples of some editors are PC write, Word-star. As we type the program the editor stores the ACSII codes for the letters and numbers in successive RAM locations. If any typing mistake is done editor will alert us to correct it. If we leave out a program statement an editor will let you move everything down and insert a line. After typing all the program we have to save the program for a hard disk. This we call it as source file. The next step is to process the source file with an assembler. While using TASM or MASM we should give a file name and extension .ASM. Ex: Sample. asm 2.Assembler : An Assembler is used to translate the assembly language mnemonics into machine language( i.e binary codes). When you run the assembler it reads the source file of your program from where you have saved it. The assembler generates two files . The first file is the Object file with the extension .OBJ. The object file consists of the binary codes for the instructions and information about the addresses of the instructions. After further processing, the contents of the file will be loaded in to memory and run. The second file is the assembler list file with the extension .LST. 3. Linker : A linker is a program used to connect several object files into one large object file. While writing large programs it is better to divide the large program into smaller modules. Each module can be individually written, tested and debugged. Then all the object modules are linked together to form one, functioning program. These object modules can also be kept in library file and linked into other programs as needed. A linker produces a link file which contains the binary codes for all the combined modules. The linker also produces a link map file which contains the address information about the linked files. The linkers which comes with TASM or MASM assemblers produce link files with the .EXE extension.
  • 5. 5 4. Locator : A locator is a program used to assign the specific addresses of where the segments of object code are to be loaded into memory. A locator program called EXE2BIN comes with the IBM PC Disk Operating System (DOS). EXE2BIN converts a .EXE file to a .BIN file which has physical addresses. 5. Debugger: A debugger is a program which allows to load your object code program into system memory, execute the program, and troubleshoot or debug it. The debugger allows to look into the contents of registers and memory locations after the program runs. We can also change the contents of registers and memory locations and rerun the program. Some debuggers allows to stop the program after each instruction so that you can check or alter memory and register contents. This is called single step debug. A debugger also allows to set a breakpoint at any point in the program. If we insert a break point , the debugger will run the program up to the instruction where the breakpoint is put and then stop the execution. 6. Emulator: An emulator is a mixture of hard ware and software. It is usually used to test and debug the hardware and software of an external system such as the prototype of a microprocessor based instrument. ASSEMBLER DIRECTIVES: Assembler directives are the directions to the assembler which indicate how an operand or section of the program is to be processed. These are also called pseudo operations which are not executable by the microprocessor. The various directives are explained below. 1. ASSUME : The ASSUME directive is used to inform the assembler the name of the logical segment it should use for a specified segment. Ex: ASSUME DS : DATA tells the assembler that for any program instruction which refers to the data segment ,it should use the logical segment called DATA. 2.DB : Define byte. It is used to declare a byte variable or set aside one or more storage locations of type byte in memory. For example, CURRENT_VALUE DB 36H tells the assembler to reserve 1 byte of memory for a variable named CURRENT_ VALUE and to put the value 36 H in that memory location when the program is loaded into RAM .
  • 6. 6 3. DW : Define word. It tells the assembler to define a variable of type word or to reserve storage locations of type word in memory. 4. DD(define double word) :This directive is used to declare a variable of type double word or restore memory locations which can be accessed as type double word. 5.DQ (define quadword) :This directive is used to tell the assembler to declare a variable 4 words in length or to reserve 4 words of storage in memory . 6.DT (define ten bytes):It is used to inform the assembler to define a variable which is 10 bytes in length or to reserve 10 bytes of storage in memory. 7. EQU : Equate It is used to give a name to some value or symbol. Every time the assembler finds the given name in the program, it will replace the name with the value or symbol we have equated with that name 8.ORG : Originate : The ORG statement changes the starting offset address of the data. It allows to set the location counter to a desired value at any point in the program. For example the statement ORG 3000H tells the assembler to set the location counter to 3000H. 9 .PROC- Procedures: It is used to identify the start of a procedure. Or subroutine. 10. END- End program .This directive indicates the assembler that this is the end of the program module. The assembler ignores any statements after an END directive. 11. ENDP- End procedure: It indicates the end of the procedure (subroutine) to the assembler. 12.ENDS-End Segment: This directive is used with the name of the segment to indicate the end of that logical segment. Ex: CODE SEGMENT : Start of logical segment containing code CODE ENDS : End of the segment named CODE.
  • 7. 7 SIMPLE EXAMPLES : Program: Multiplication code segment assume cs : code start: mov ax,10h mov bx,2h mul bx mov cx,ax int 21h code ends end. Program : Display Data data segment datas db 'I am an Indian $' data ends code segment assume cs:code,ds:data start : mov ax,data mov ds,ax lea dx,datas mov ah,09h int 21h code ends end start Program : Addition code segment assume cs: code start : mov ax,3h mov bx,3h add ax,bx mov ah,4ch code ends end Program : Seven segment data ends code segment assume cs: code,ds:data loop2: mov ax,data mov ds,ax mov dx,0d803h mov al,80h out dx,al lea bx,datas
  • 8. 8 mov cl,10h loop1: mov al, [bx] mov dx,0d800h out dx,al call delay inc bx dec cl jnz loop1 jmp loop2 delay proc near push cx push bx mov cx, 07feh back2 : mov bx,0ffffh back1: dec bx jnz back1 loop back2 pop bx pop cx ret delay endp Program : Seven-segment data segment datas db 3fh,06h,5bh,4fh,66h,6dh,7dh,07h db 7fh,6fh,77h,7ch,39h,5eh,79h,71h data ends code segment assume cs:code,ds:data loop2 : mov ax,data mov ds,ax mov dx,0d803h mov al,80h out dx,al lea bx,datas mov cl,10h loop1: mov al,[bx] mov dx,0d800h out dx,al call delay inc bx dec cl jnz loop1 jmp loop2 delay proc near push cx push bx mov cx,07feh
  • 9. 9 back2: mov bx,0ffffh back1: dec bx jnz back1 loop back2 pop bx pop cx ret delay endp program:Factorial code segment assume cs:code mov ax,200 mov ss,ax mov sp,2000 sub sp,0004h mov ax,6 push ax call facto pop ax nop nop nop facto proc near pushf push ax push dx push bp mov bp,sp mov ax,[bp+10] cmp ax,0001h jne go_on mov word ptr [bp+12],0001h mov word ptr [bp+14],0000h jmp exit go_on : sub sp,0004h dec ax push ax call facto mov bp,sp mov ax,[bp+2] mul word ptr [bp+16] mov [bp+18],ax mov [bp+20],dx add sp,0006h exit : pop bp pop dx
  • 10. 10 pop ax popf ret facto endp code ends end Program :Message Display assume cs:code,ds:data data segment message db 0dh,0ah,"mallika is the student of m.sc",0dh,0ah,"$" ;preparing string of the message data ends code segment start: mov ax,data ; initializes ds mov ds,ax mov ah,09 ; set function value for display mov dx, offset message int 21h ; point to message and run mov ah,4ch ; the interrupt int 21h ; return to dos code ends end start Program : Read Numbes Macro MOV AH,01H INT 21H SUB AL,'0' MOV BH,0AH MUL BH MOV NUM,AL MOV AH,01H INT 21H SUB AL,'0' ADD NUM,AL ENDM PRINTSTRING MACRO MSG MOV AH,09H MOV DX,OFFSET MSG INT 21H ENDM DATA SEGMENT CR EQU 0DH LF EQU 0AH MSG DB CR,LF,'ENTER NUMBER','$'
  • 11. 11 MSG1 DB CR,LF,'RESULT: ','$' NUM1 DB ? NUM2 DB ? RES DB ? DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX PRINTSTRING MSG READNUM NUM1 PRINTSTRING MSG READNUM NUM2 MOV AH,00H MOV AL,NUM1 ADD AL,NUM2 MOV RES,AL MOV SI,OFFSET RES CALL HEX2ASC PRINTSTRING MSG1 PRINTSTRING RES MOV AH,4CH MOV AL,00H INT 21H HEX2ASC PROC NEAR PUSH AX PUSH BX PUSH CX PUSH DX PUSH SI MOV CX,00H MOV BX,0AH RPT1: MOV DX,00 DIV BX ADD DL,'0' PUSH DX INC CX CMP AX,0AH JGE RPT1 ADD AL,'0' MOV [SI],AL RPT2: POP AX INC SI MOV [SI],AL
  • 12. 12 LOOP RPT2 INC SI MOV AL,'$' MOV [SI],AL POP SI POP DX POP CX POP BX POP AX RET HEX2ASC ENDP CODE ENDS END START Program: Multibyte addition DATA SEGMENT N1 DB 11H, 22H, 33H N2 DB 22 H, 33H, 44H RESULT DB 3H DUP (00) DATA ENDS CODE SEGMENT ASSUME CS: CODE, DS: DATA START: MOV AX, DATA MOV DS, AX MOV SI, OFFSET N1 MOV DI, OFFSET N2 MOV BX, OFFSET RESULT CLC MOV CX, 0003H MOV AX, 0000H BACK: MOV AL, [SI] MOV DL, [DI] ADC AL, DL MOV [BX], AL INC SI INC DI INC BX DEC CX JNZ BACK MOV AH, 4CH INT 21H INT 3H CODE ENDS END START RESULT: 11H 22H 33H 22H 33H 44H 33H 55 H 77H Program: Multi byte Multiplication
  • 13. 13 DATA SEGMENT N1 DB 03H, 05 H, 07 H N2 DB 05 H, 03H, 02H RESULT DB 4H DUP (00) DATA ENDS CODE SEGMENT ASSUME CS: CODE, DS: DATA START: MOV AX, DATA MOV DS, AX MOV SI, OFFSET N1 MOV DI, OFFSET N2 MOV BX, OFFSET RESULT MOV CL, 03H MOV AX, 0000H MOV DX, 0000H BACK: MOV AL, [SI] MOV CH, [DI] MUL DH MOV [BX], AL INC SI INC DI INC BX LOOP BACK MOV AH, 4CH INT 21H INT 3H CODE ENDS END START RESULT: 03H 05H 07H 05H 03H 02H 0FH 0FH 0EH References : 1. Programmer’s Guide, Microsoft MASM, Micro soft Corporation. 2.Microprocessor and Interfacing –D.V.Hall,TMH