masm(microsoft macro assembler)
TRANSCRIPT
M & M
MASM: The Microsoft Macro Assembler Without question, MASM is the world's most
popular assembly language translator. There are many reasons for its popularity, though the fact that Microsoft produced it has a lot to do with this. Of course, MASM has been around for over two decades and has had lots of time to develop a huge following. It doesn't hurt that MASM is one of the most powerful and stable assemblers around. It also doesn't hurt that there are lots of on-line and off-line resources available for MASM. The real question isn't "why is MASM so popular?" Rather, the question really is "why isn't everyone using MASM?" There are a couple of reasons:
MASM(Microsoft Macro Assembler)
The Microsoft Macro Assembler (MASM) is an x86assembler for Microsoft Windows that uses the Intel syntax. The current versions of MASM exist in 2 flavors, the first one understands 16-bit and 32-bit assembly sources, the latter (ML64] is restricted to 64-bit sources.
STEPS TO WORK ON MASM
C:masm.edit[filename.asm] Save file with filename asm C:\masm.masm filename.asm C:\masm.link filename+io C:\masm>filename
Which Version of MASM are you Using?
Like most function files, the MASM.exe file is constantly updated. In production, typically some date is chosen as a production date, but changes continue.
COMMAND TO KNOW THE VERSION OF MASM-
C:> dir MASM*
What to type on the Command Line
to assemble hello.asm
C:> Path = c:\masm613\binC:> Masm hello
This assumes that masm.exe is in the bin subdirectory.
Note that the extension of the file is not typed on the command line (it is assumed to be asm)
This function creates an object file (file containing machine language code – binary file) named hello.obj
MASM.exe
In lab, you type:C:> masm hello,hello,helloThis is (source filename, object filename, listing
filename)
In order to run codeview, you type:C:> masm /zi hello, hello, hello
What to type on the Command Line
to Link Hello.obj
Want to link Hello.obj with any external files used in the source code (none needed)
Want to create an executable fileC:> Path = c:\masm613\binrC:> Link hello
This creates an executable file. If you don’t put any of the extensions, it will ask you.
This assumes that Link.exe is located in the bin subdirectory.
The OFFSET Operator If a data label is referenced in an expression,
MASM will generally assume that the content of the memory reference is to be targeted. To access the address and not the content of a data label, MASM supplies addditional operators - OFFSET and SEG - to tell the assembler the different intention:
mov eax, data_label ; load the content of data_label ( assumed DWORD here )
mov eax, OFFSET data_label; load the address ( the offset part of it )
Square Bracket Operator [] The square bracket operator behaves
differently depending on the context. For direct addressing, the square brackets are similar to the + operator. As a result, square brackets around a data label have no effect:
mov eax, [eax] ; dereference the CONTENT of the variable and copy it into the EAX register
HIGH LEVEL CONTROL LOOPS- MASM provides a notation to emulate a
variety of high level control and loop structures.It supports the .IF block structure,
.if – .elseif – .else – .endif
ABOUT MASM EDITOR
There is a specific notation with the programmable menus so that programmers can run assemblers or compilers directly from Quick Editor.The notation works by getting the name of the file loaded in the editor and parsing the full path and file name in a range of formats that can be used with compilers, linkers, assembler and batch files.
If you have the following file loaded in Quick Editor,
c:\masm\bin\myprog.asm
The following notation is expanded by Quick Editor into the various components of the files path and filename.
full path and name with extension{a} => c:\masm\bin\myprog.asm
full path and name with NO extension{b} => c:\masm\bin\myprog
name with extension{f} => myprog.asm
name with NO extension{n} => myprog
full path with NO name{p} => c:\masm\bin\
EXAMPLES-
to run a compiled EXE file, the menu entry would be like this,&Run EXE File,{b}.exeThis option is expanded by Quick Editor into,c:\masm\bin\myprog.exe
If you need to run a file in the same directory as the file loaded in the editor, the menu entry would look like this,
Run &Other File,{p}otherfile.exeThis is expanded by Quick Editor into,c:\masm\bin\otherfile.exe
Some intructions in MASM
AAA ASCII Adjust After Addition AAD ASCII Adjust AX Before Division AAM ASCII Adjust AX After Multiply AAS ASCII Adjust AL After
Subtraction ADC Add With Carry ADD Arithmetic Addition AND Logical And
CBW Convert Byte to Word CDQ Convert Double to Quad (386+) CLC Clear Carry CLD Clear Direction Flag CLI Clear Interrupt Flag (disable) CLTS Clear Task Switched Flag (286+
privileged)
CMP Compare CMPS Compare String (Byte, Word or
Doubleword) CMPXCHG Compare and Exchange DAA Decimal Adjust for Addition DAS Decimal Adjust for Subtraction DEC Decrement DIV Divide
SOME EXAMLES ON ARITHEMATIC OPERATIOPNS-
This notation applies to both named and numbered variables.
add = add to numeric variable add #16 1
sub = sub from numeric variable sub #24 12
Example: Adding 3 Integers
TITLE Add and Subtract (AddSub.asm)
; This program adds and subtracts 32-bit integers.
INCLUDE Irvine32.inc .code main PROC mov eax,10000h ; EAX = 10000h add eax,40000h ; EAX = 50000h sub eax,20000h ; EAX = 30000h call DumpRegs ; display registers exit main ENDP END main
DATA ASSIGNMENT
string = "literal" $5 = "Quoted Text"string = string $6 = $5number = immediate #2 = 125number = number #2 = #36
number1STRING Text$
number1 = 1Text$ = "Hi, I am text data !"
BRANCHING
goto branch to label
lbl0: .... goto lbl1 .... goto lbl0 .... lbl1:
call branch to label and store return IP
EXAMPLE
call initialise ; call the label "initialise .... ; <---- return here .... .... ....
initialise: .... ret ; return to the next instruction ; after the last "call"
RUNTIME OPERATORS
run time operators - equal "==" or "=" not equal "!=" or "<>" greater than ">" less than "<" greater or equal ">=" or "=>" less or equal "<=" or "=<“
equal "==" or "=" not equal "!=" or "<>"
TERMINATION
Termination
’end’ terminate script (required to terminate script
DIRECTORY COMMANDS
mkdir create a directory arg1 quoted text or a string variable
chdir change directory arg1 quoted text or a string variable
rmdir delete an empty directory arg1 quoted text or a string variable
copyfile copy a disk file arg1 file to copy as quoted text or a string variable arg2 new file name as quoted text or a string variable existing file will be overwritten by new file name
movefile move a disk file from one location to another arg1 file to copy as quoted text or a string variable arg2 new file name as quoted text or a string variable
deletefile delete a disk file arg1 quoted text or a string variable
FILE I/O FUNCTIONS
fcreate create a file and return its file handle hFile = fcreate "myfile.ext"
fopen open an existing file for read / write and return its file handle hFile = fopen "myfile.ext"
fclose close an open file handle. #3 = fclose hFile fprint fprintc write string data to an open file. The fprintc variation expands C style escapes into their match characters.
fsize return the size of an open file flen = fsize hFile
fread read a count of bytes from an open file and return that data as a user defined string $22 = fread #2 16 arg1 = open file handle arg2 = byte count to read
THANK YOU
SUBMITTED BY-