Setting Up an Assembly Language Development Environment on Windows 10 (Using DOSBOX and MASM32)

Setting Up an Assembly Language Development Environment on Windows 10 (Using DOSBOX and MASM32)

Limited Time Resource Download: Reply “Tutorial” to obtain a microcontroller eBook, reply Simulation to get Proteus simulation materials, the Baidu Drive group sharing link update time: 2017-07-12, if it is invalid, please leave a message at the end of the article, do not leave a message in the background, you can also search for more resources you want in the background menu “Resource Search”!

Source: http://blog.csdn.NET/doniexun/article/details/45438457

The best way to learn a language is through practice. For many beginners, the first challenge is how to set up a development platform/environment. Due to the particularity of assembly language, many beginners worry that directly manipulating registers may lead to system crashes or hardware damage. Moreover, with the prevalence of high-level programming languages today, the situations that truly require writing assembly language have become less frequent, so many students learning assembly language are still stuck in theoretical discussions.

I first learned assembly language five years ago but had never practiced it myself. Recently, I needed to disassemble binary executable files for work, so I planned to revisit the assembly language I had learned in order to successfully complete my current project. Below is a record of setting up an assembly language development environment based on DOSBOX + MASM32.

1 Tool Preparation

1) Download DOSBOX

Tool Introduction: DOSBox is a DOS emulator. Since it uses the SDL library, it can be easily ported to other platforms. Currently, DOSBox supports running on Windows, Linux, Mac OS X, BeOS, palmOS, Android, webOS, OS/2, and other systems. Many DOS games can run directly on this platform.

Tool Official Website: http://www.dosbox.com/

Project Homepage: http://sourceforge.net/projects/dosbox/

Download Link: http://sourceforge.Net/projects/dosbox/files/dosbox/0.74/DOSBox0.74-win32-installer.exe/download (32-bit)

Note: Since the project is no longer updated, the official website states that DOSBOX can run on 32-bit and 64-bit Windows Vista and Windows 7. Based on my personal testing, it can also run on 32-bit and 64-bit Windows 10, so those in need can give it a try.

2) Download MASM32

Tool Introduction: MASM32 is a software package organized and written by MASM enthusiast Steve Hutchesson. The highest version is 11r. MASM32 does not refer to Microsoft’s MASM macro assembler, but rather includes a development toolkit for assembly that contains different versions of tools. Its assembler compiler is Ml.exe from MASM6.0 and above, the resource compiler is Rc.exe from Microsoft Visual Studio, and the 32-bit linker is Link.exe from Microsoft Visual Studio, along with other tools like Lib.exe and DumpPe.exe.

Tool Official Website: http://www.masm32.com/

Download Link: http://www.masm32.com/downloads

Note: You can also directly download the compressed package of MASM tools provided by the author of reference material 3, which contains the necessary assembly, linking, and debugging tools. Baidu Drive download link: https://pan.baidu.com/s/1skL2bVJ, password: 7uv1.

2 Install Tools

1) Install DOSBOX

Install the downloaded DOSBox0.74-win32-installer.exe, and simply click Next to complete the installation.

2) Configure DOSBOX

Create a directory to save assembly tools (such as MASM, Link, DEBUG, etc.) and assembly files (*.asm), for example: D:\DEBUG.

Open the installation root directory of DOSBOX (default installation path: C:\Program Files\DOSBox-0.74; if it is a 64-bit system, the default installation path is C:\Program Files (x86)\DOSBox-0.74), double-click the file DOSBox 0.74 Options.bat, and after running this batch file, the system will open the configuration file dosbox-0.74.conf with Notepad.

Position the cursor at the [autoexec] node in the dosbox-0.74.conf file (usually at the end of the file) and add the following content:

  1. MOUNT C D:\DEBUG # Mount directory D:\DEBUG as C: in DOSBOX

  2. set PATH=$PATH$;D:\DEBUG # Add D:\DEBUG to the environment variable PATH

3) Install MASM32

You can extract and install the downloaded masm32v11r.zip, and install it with the default configuration.

After installation, you can directly use the gedit.exe program in masm32v11r to write, compile, and link asm assembly programs.

Note:Alternative to MASM32:

You can directly copy the assembly tools DEBUG.EXE, EDIT.EXE, LINK.EXE, MASM.EXE, etc. from other computers or from the compressed package provided at the above Baidu Drive address to the D:\DEBUG folder (be careful not to copy the tools found in a 32-bit system to use in a 64-bit system).

3 Sample Program

Note: When entering the DOSBOX editing interface, you can press the Windows key to exit the DOSBOX editing interface; the spelling of the following commands ignores case.

1) Run DOSBOX, and at the command prompt C:\> enter the command: EDIT filename.asm to start EDIT.EXE and enter code editing mode, and input the following sample program:

copy

  1. code segment

  2. assume cs:code

  3. start:

  4. mov ax,5h

  5. mov bx,6h

  6. add ax,bx

  7. mov ah,4ch ; Call DOS function 4C

  8. int 21h ; Exit DEBUG state, return to DOS

  9. code ends

  10. end start

2) After saving the file, return to the DOSBOX command line and enter the command: MASM filename.asm to generate the object file filename.OBJ (you can modify the target file name during the generation process, pressing Enter will keep the default target file name).

Note: At this point, three files may be generated: *.obj, *.lst, and *.crf files (Windows 10 x64 system may only generate the *.obj file). Among them, the list file *.lst and the cross-reference file are not mandatory; the former is a table comparing machine language and assembly language generated by the assembly language, which can be used for debugging; the latter provides all user-defined symbols and the line numbers for each symbol’s definition and reference.

3) Enter the command: LINK filename.OBJ to link and generate the executable file filename.EXE.

Note: Since the stack segment is not defined in the above code, a warning will be prompted during linking: LINK : warning L4021: no stack segment, which does not affect the generation of the executable file, so it can be temporarily ignored.

Additionally, two files may be generated at this point: *.exe and *.map files (Windows 10 x64 system may only generate the *.exe file). The address mapping file *.map provides information about memory address allocation.

4) Enter the command: DEBUG filename.EXE, and after the DEBUG command prompt “-” appears, start debugging. Below are some debugging commands and screenshots:

Enter the command: R to view the initial values of the register group before the program runs;

Setting Up an Assembly Language Development Environment on Windows 10 (Using DOSBOX and MASM32)

Enter the command: U to view the disassembled code of the program. From the disassembled code, it can be seen that variables will be assembled as direct addressing mode, using the effective address of the variable in the data segment.

Setting Up an Assembly Language Development Environment on Windows 10 (Using DOSBOX and MASM32)

Enter the command: T for single-step debugging;

Setting Up an Assembly Language Development Environment on Windows 10 (Using DOSBOX and MASM32)

Enter the command: D to observe memory changes (D without an address or range defaults to display the last 80 bytes of content after the previous D command);

Setting Up an Assembly Language Development Environment on Windows 10 (Using DOSBOX and MASM32)

Enter the command: G address to run the program directly from the current position to the specified address.

Setting Up an Assembly Language Development Environment on Windows 10 (Using DOSBOX and MASM32)

Enter the command: E address to modify the content in memory, for example: E DS:0100, input space to modify byte by byte, press Enter to stop modifying.

Setting Up an Assembly Language Development Environment on Windows 10 (Using DOSBOX and MASM32)

4 References

1) MASM Baidu Encyclopedia: http://baike.baidu.com/view/1754206.htm

2) DOSBOX Baidu Encyclopedia: http://baike.baidu.com/view/716885.htm

3) Writing Assembly Language with DOSBox on Win8: http://www.tuicool.com/articles/v2A3mm

Setting Up an Assembly Language Development Environment on Windows 10 (Using DOSBOX and MASM32)

Limited Time Resource Download: Reply “Tutorial” to obtain a microcontroller eBook, reply “Simulation” to get Proteus simulation materials.

> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >

How to Share to Moments

Click the three dots in the upper right corner, and select “Share to Moments” from the pop-up menu

Microcontroller Subscription Account

WeChat Name: Microcontroller updates daily various knowledge about microcontrollers, electronic DIY, and the latest news in the electronics industry. Follow us, it’s great!Setting Up an Assembly Language Development Environment on Windows 10 (Using DOSBOX and MASM32)

Recommended Popular Articles

Reply with the numbers below or click directly to get related articles:

001:Must-Read for Microcontroller Beginners

002:Words from Zhou Ligong to Young People Learning Microcontrollers

003:Experts Discuss: The Difficulty of Software and Hardware Entry and Mastery Time Span

004:Reflections on Learning the 51 Microcontroller; Recommended Learning Materials; Essential Programs to Write

005:Comparison of Several Microcontrollers Used

006: “ARM+LINUX Learning Path (Learning Order, Knowledge Points, and Book Recommendations)

007:Differences and Connections between ARM/DSP/FPGA/CPLD/SOPC/SOC

008:Fun Electronic DIY: Food Power Generation in the Hands of Artists

009:My Experience: From a Production Line Worker to a Microcontroller Engineer

010:A Friend Brought Back a Toolbox from Germany for 200,000

Click the lower left corner “Read the Original“, to enterForum for Discussion!!!

Leave a Comment