Macro assembly MASM System

Source: Internet
Author: User
1.1 macro assembly MASM System

In the macro assembly MASM system, programmers can use two methods to process the source program: Command Line and integration environment.

1.1.1 command line

1. Compile the source program

You can use various editors in the computer system to edit the Assembly source program. Commonly used editors include edit, Q, word, notepad, and wordpad. The source file suffix is ASM.

2. Assembler

After the source program is compiled, use the MASM command to compile the source program. If the source program has no syntax errors, the target file (OBJ file) will be generated to prepare for the final generation of executable files. However, if the source program has errors, the assembler will display the error location and cause, and you can also view the error location and cause in the list file (LST file.

The following are some examples of using this command.

Example 1.1 view the features of the MASM command. (The command entered by the user is underlined, and the content displayed by the system is not underlined. The following is the same)

...>MASM /?
Usage: MASM/options source (. ASM), [out (. OBJ)], [list (. lst)], [CREF (. CRF)] [;]
......

Common options are:/Zi and/ZD, because they are related to symbol tracing.

Example 1.2 use the MASM command to compile the source program

...> MASM Test
Microsoft (r) MASM compatibility driver
Copyright (c) Microsoft Corp 1993. All rights reserved.
Invoking: ml. EXE/I./ZM/C test. ASM
Microsoft (r) macro proceser version 6.11
Copyright (c) Microsoft Corp 1981-1993. All rights reserved.
Processing ing: Test. ASM

If the MASM command displays a processing result similar to the preceding one, it indicates that the source file test. ASM has been compiled successfully and the target file test. OBJ has been generated.

Example 1.3 Use the MASM command to compile the source program

...>MASM Test
......
Processing ing: Test. ASM
Test. ASM (10): Error a2070: Invalid instruction operands

If the MASM command displays a processing result similar to the preceding one, it indicates that the source file is incorrect and the target file is not generated. In this example, 10th rows are displayed with the syntax error: Invalid Command operands. In this case, use the editor to read the 10th lines of the source program and check whether the input command is correct.

If the source program has many errors and it is difficult to remember all the error locations, you can use the list file to assist in troubleshooting.

For example, 1.4, the list file is generated when the source program is compiled.

...>MASM test, test
......
Processing ing: Test. ASM
Test. ASM (10): Error a2070: Invalid instruction operands

The list file test. lst is a text file that can be directly read by the editor and shows the location and cause of the error. The following is an instance of the list file.

...>Edit test. lst

Microsoft (r) macro runner er version 6.11 08/26/00 18:42:57

  Test. ASM   Page 1-1
. Model small
. 486
0000 . Data
. Radix 7
0000 2a 08 0f W2 dB 60, 11, 18; 0000 is the offset, and 2a 08 0f is the data
0003 000a 0009 W1 DW 10 t, 1001b; 0003 is the offset, 000a 0009 is the data
0000 . Code
  . Startup
MoV DL, 7777 H
Test. ASM (10): Error a2070: Invalid instruction operands
  MoV ax, DX
0012 0f A4 C2 01 Shld dx, ax, 1
0016 D1 D0 RCL ax, 1
. Exit 0
End

There are other content after this, but they are not helpful for troubleshooting. Therefore, this is omitted.

3. Connection Program

After the source file is compiled successfully, you can use the Connection Program (link. EXE) to generate the executable file.

Example 1.5: view the specific options of the Connection Program (link. EXE.

...>Link /?
Link <objs>, <exefile>, <mapfile>, <libs>, <deffile>
Valid options are:
......

Common Function options include :/? ,/Help,/codeview, And/stack

Example 1.6 use a Connection Program to generate an execution file.

Method 1:

...> LINK TEST
......
Run file named test.exe]:
List file [NUL. MAP]:
Libraries [. Lib]:
Definitions file [NUL. Def]:
Link: Warning l4021: no stack segment

In this method, you need to confirm the various file names during the connection process. If the default file name is used, press "enter.

Among the above four file names, the most important two file names are: Execution file name and library file name. Generally, you do not need to change the final generated execution file name. If you need other library files during the connection process, enter the required library file name when prompted in the third line.

The last line displays a warning message, indicating that the program does not define the stack segment. You can ignore this warning message because the execution file is runable, A default stack segment is automatically added when the operating system is loaded.

Method 2: add the Semicolon ";" after the file name. By default, the default values of all types of files are used.

...>Link test;
......
Link: Warning l4021: no stack segment

4. Run the program

To run the generated file, you can directly enter the file name.

...>Test

5. symbol debugging program

When the running result of a program is not the expected result, You Need To debug the program to find the wrong statement or logical relationship. The MASM system provides the source code-level debugging tool CV (codeview ). For more information about CV usage, see codeview in debugging tools.

Example 1.7 use the symbolic debugging tool CV to debug the program test. ASM to generate an executable file.

...>MASM/Zi/ZD Test; Suppose there is no syntax error
...>Link/CO Test
...>CV test.exe 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.