Sie sind auf Seite 1von 31

M&m

Click to edit Master subtitle style

4/9/12

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 4/9/12 popular?" Rather, the question really is

MASM(Microsoft Macro Assembler)

TheMicrosoft Macro Assembler(MASM) is anx86assembler forMicrosoft Windowsthat uses theIntel syntax. The current versions of MASM exist in 2 flavors, the first one understands16bitand32-bitassembly sources, the latter (ML64] is restricted to64bitsources.

4/9/12

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

4/9/12

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.

Which Version of MASM are you Using?

COMMAND TO KNOW THE VERSION OF MASMC:> dir MASM*

4/9/12

What to type on the Command Line to assemble hello.asm


C:> Path = c:\masm613\bin C:> 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

4/9/12

MASM.exe

In lab, you type:

C:> masm hello,hello,hello


This is (source filename, object filename, listing filename)

In order to run codeview, you type:

4/9/12 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 file

C:> Path = c:\masm613\binr C:> Link hello

This creates an executable file. If you dont put any of the extensions, it will ask you. assumes that Link.exe is located in

4/9/12 This

The OFFSET Operator If a data label is referenced in an expression, MASM will generally assume that thecontentof the memory reference is to be targeted. To access theaddressand 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 )

4/9/12

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

4/9/12

HIGH LEVEL CONTROL LOOPSMASM provides a notation to emulate a variety of high level control and loop structures. It supports the.IFblock structure, .if .elseif .else .endif

4/9/12

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.

4/9/12

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 4/9/12 {a} => c:\masm\bin\myprog.asm

name with extension {f} => myprog.asm

name with NO extension {n} => myprog

4/9/12

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}.exe This option is expanded by Quick Editor into, c:\masm\bin\myprog.exe If you need to run a file in the same 4/9/12 directory as the file loaded in the editor,

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

4/9/12

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)

4/9/12

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

4/9/12

SOME EXAMLES ON ARITHEMATIC OPERATIOPNSThis notation applies to both named and numbered variables.

add = add to numeric variable add #16 1 sub = sub from numeric variable sub #24 12

4/9/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 ; add eax,40000h ; sub eax,20000h ; ; 4/9/12 call DumpRegs

EAX = 10000h EAX = 50000h EAX = 30000h display

DATA ASSIGNMENT

string = "literal" $5 = "Quoted Text" string = string $6 = $5 number = immediate #2 = 125 number = number #2 = #36 number1 STRING Text$

number1 = 1 4/9/12 Text$ = "Hi, I am text data !"

BRANCHING

goto branch to label lbl0: .... goto lbl1 .... goto lbl0 .... lbl1:

callbranch to label and store return IP 4/9/12

EXAMPLE call initialise ; call the label "initialise .... ; <---return here .... .... ....

initialise: .... 4/9/12

RUNTIME OPERATORS

run time operators equal "==" or "=" not equal "!=" or "<>" greater than ">" less than "<" greater or equal ">=" or "=>" less or equal "<=" or "=< equal "==" or "="

4/9/12

TERMINATION

Termination endterminate script(required to terminate script

4/9/12

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 4/9/12

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 4/9/12

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"

4/9/12

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.

4/9/12

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 4/9/12

THANK YOU

SUBMITTED BY-

4/9/12

Das könnte Ihnen auch gefallen