📜 ⬆️ ⬇️

MASM, TASM, FASM, NASM for Windows and Linux

Part I
Part II
Part III

In this article, I want to consider issues that may arise in a person who has begun to learn assembly language, related to installing various translators and translating programs under Windows and Linux, and also provide links to resources and books devoted to the study of this topic.

MASM


Used to create drivers for Windows.

Click on the link to the site and download the package (masm32v11r.zip). After installing the program, a folder with our C: \ masm32 package is created on the disk. Create the program prog11.asm, which does nothing.
')
.586P .model flat, stdcall _data segment _data ends _text segment start: ret _text ends end start 

Perform the assembly (translation) of the prog11.asm file using assembler from the masm32 site.

image
The / coff key is used here for translating 32-bit programs.
Linking is performed by the link / subsystem: windows prog11.obj command ( link / subsystem: console prog11.obj )

As stated on Wikipedia
MASM is one of the few Microsoft development tools for which there were no separate 16-bit and 32-bit versions.


Also assembler version 6. you can take on the site of Kip Irvin kipirvine.com/asm , the author of the book "Assembly Language for Intel Processors".

By the way, here is a link to the personal site of Vladislav Pirogov, the author of the book “Assembler for Windows”.

MASM from Microsoft

Next, download MASM (version 8.0) from the Microsoft website by the link . The downloaded file is called “MASMsetup.exe”. When you run this file, we get the message - "Microsoft Visual C ++ Express Edition 2005 required".

Open this file with the archiver (for example 7zip). Inside we see the file setup.exe, extract it, open it with the archiver. Inside we see two files vc_masm.msi, vc_masm1.cab. Extract the file vc_masm1.cab, open the archiver. Inside we see the file FL_ml_exe _____ X86.3643236F_FC70_11D3_A536_0090278A1BB8. We rename it to the fl_ml.exe file, then we will assemble the prog11.asm file using the assembler fl_ml.exe.

image

MASM in Visual Studio

Also MASM can be found in the folder with Visual Studio (I have VS 10) here: C: \ Program Files \ Microsoft Visual Studio 10.0 \ VC \ bin \ ml.exe.

image

In order to run on a 32-bit or 64-bit system and create programs that work under both 32-bit and 64-bit Windows, MASM32 (ml.exe, fl_ml.exe) is suitable. In order to work on 32-bit and 64-bit systems and create programs that run under 64-bit Windows, but those that don't work under 32-bit need assembler ml64.exe. It lies in the folder C: \ Program Files \ Microsoft Visual Studio 10.0 \ VC \ bin \ amd64 and right here - C: \ Program Files \ Microsoft Visual Studio 10.0 \ VC \ bin \ x86_amd64.

TASM


Borland's software package for developing assembly language programs for the x86 architecture. Borland has now stopped distributing its assembler.

You can download, for example, here . There is no installer, just extract the program. Here is the source from the book by Peter Abel (Fig. 3.2) "Assembly Language for the IBM PC and programming."

 stacksg segment para stack 'stack' db 12 dup ('stackseg') stacksg ends codesg segment para 'code' begin proc far assume ss:stacksg,cs:codesg,ds:nothing push ds sub ax,ax push ax mov ax, 0123h add ax, 0025h mov bx,ax add bx,ax mov cx,bx sub cx,ax sub ax,ax nop ret begin endp codesg ends end begin 

Perform the assembly (translation) of the file abel32.asm.

image

The correctness of the program can be checked by linking (tlink.exe) the object file and running the resulting file in the debugger.

As mentioned above, MASM can be used to work with 16-bit programs. Perform assembly (translation) of the program abel32.asm using MASM assembler:

image

The / coff key is not used here.
Linking is performed by the file link16.exe

Fasm


In the article by Chris Kaspersky “Comparison of assembler translators” it is written that “FASM is an extraordinary and very original, but alas, toy assembler. Suitable for small tasks like „hello, world“, viruses, demos and other works of hacker creativity. "

Download FASM from the official site . There is no installer, just extract the program. Open the fasm editor - C: \ fasm \ fasmw.exe. In the folder C: \ fasm \ EXAMPLES \ HELLO there is a file HELLO.asm.

 include 'win32ax.inc' .code start: invoke MessageBox,HWND_DESKTOP,"Hi! I'm the example program!",invoke GetCommandLine,MB_OK invoke ExitProcess,0 .end start 

Open the file HELLO.asm from fasmw.exe. Change the line include 'win32ax.inc' to the line include 'c: \ fasm \ INCLUDE \ WIN32AX.INC'. Run from the menu Run → Run.

image

Here are links to resources dedicated to FASM:

→ FASM on Cyberforum
→ FASM on asmworld .com programs under Dos
→ Series of articles "Assembler under Windows for Dummies"
→ Site on narod

FASM in Linux

In order to use FASM in Linux (I have Ubuntu), download the appropriate distribution (fasm-1.71.60.tgz), unpack it, we will have a fasm binary file in the folder, copy this file to / usr / local / bin for , so that you can run it from the console, like any other command. Let's execute assembly of the hello.asm program from the fasm / examples / elfexe / hello.asm folder.

image

The correctness of the program can be checked in the debugger.

Nasm


Nasm successfully competes with Gas's standard assembler in Linux and many other UNIX systems.

Nasm in Linux can be installed using the package manager or from the command line: in the Debian (Ubuntu) distribution using the apt-get install nasm command , in the Fedora , CentOS , RedHat distributions using the yum install nasm distribution .

Create a program that displays the message “Hello” 5 times. An example is taken from Andrei Viktorovich Stolyarov’s book “Programming in NASM assembler language for UNIX OS”. The textbook, as well as the library “stud_io.inc” is on the author’s personal website .

 %include "stud_io.inc" global _start section .text _start: mov eax, 0 again: PRINT "Hello" PUTCHAR 10 inc eax cmp eax, 5 jl again FINISH 

Perform assembly and linking and run the file hello.asm.

 $ nasm -f elf hello.asm $ ld hello.o -o hello $ ./hello 

For 64bit, you must use the command nasm -f elf64 hello.asm

NASM for Windows

NASM for Windows can be installed by downloading the appropriate distribution from the corresponding site .

Assembly:
nasm -f bin _.asm -o _.com

Links to Nasm resources:

→ Website A.V. Stolyarova
→ The site where the electronic textbook is located (in the archive)
→ The same

AS


Standard assembler in almost all varieties of UNIX, including Linux and BSD. The free version of this assembler is called GAS (GNU assembler). Allows you to broadcast programs using the GCC compiler.

From the textbooks, only a book in English “Programming from the ground up” was found. In Russian, we managed to find only one chapter from S. Zubkov’s book Assembler for DOS, Windows and UNIX.

Take the example of a program that does nothing from the site . Create a program gas.s

 .section .text .globl _start _start: movl $1, %eax movl $2, %ebx int $0x80 

Perform assembly (translation), linking and running the program:

 $ as -o gas.o gas.s $ ld -o gas gas.o $ ./gas 

If in this program you change _start to main, then you can perform assembly (translation) and linking with the gcc compiler.

 .section .text .globl main main: movl $1, %eax movl $2, %ebx int $0x80 

Perform assembly (translation), linking and running the program:

 $ gcc gas.s -o gas $ ./gas 

Conclusions : if you study programming under Windows, then you can opt for the Masm; Tasm is no longer supported, but suitable for learning from old classic textbooks.

Under Linux Gas, it is suitable for those who use GCC, and for those who do not like the syntax of Gas, Nasm will do.

Source: https://habr.com/ru/post/326078/


All Articles