What Is Assembly Language?

This tutorial mainly introduces microprocessor programming compatible with Intel and AMD processors running on Microsoft Windows 32-bit and 64-bit systems. The latest version of Microsoft’s Macro Assembler (known as MASM) is used in this tutorial. Most versions of Microsoft Visual Studio (Professional, Enterprise, Express, etc.) include MASM.You can visit (asmirvine.com) for the latest details on Visual Studio’s support for MASM. The website also includes a lot of useful information on how to set up the software and get started. In x86 systems running Microsoft Windows, some other well-known assemblers include: TASM (Turbo Assembler), NASM (Netwide Assembler), and MASM32 (a variant of MASM). GAS (GNU Assembler) and NASM are two assemblers based on Linux. Among these assemblers, NASM’s syntax is most similar to MASM’s.Assembly language is the oldest programming language and is closest to native machine language among all languages. It allows direct access to computer hardware and requires users to understand computer architecture and operating systems. If you are studying in a university course with a name similar to any of the following, you can learn more specialized knowledge through this tutorial:

  • Microcomputer Assembly Language

  • Assembly Language Programming

  • Introduction to Computer Architecture

  • Fundamentals of Computer Systems

  • Embedded Systems Programming

This tutorial helps to learn the fundamental principles of computer architecture, machine language, and low-level programming. You will learn enough assembly language to test your knowledge of today’s most widely used microprocessor series. You will not learn to write a “toy” computer using a simulated assembler; MASM is an industrial-grade assembler used by professionals in the industry. You will learn about the architecture of the Intel processor series from a programmer’s perspective. If you plan to become a C or C++ developer, you need to understand how memory, addresses, and instructions work at a low level. Many programming errors at the high language level are not easily recognized. Therefore, programmers often find themselves needing to “dig deep” into the program to find out why it is not working.

Common Questions About Learning Assembly

What Background Knowledge Is Needed?

Before learning this tutorial, you should have programmed using at least one structured high-level language, such as Java, C, Python, or C++. You need to understand how to use IF statements, arrays, and functions to solve programming problems.

What Are Assemblers and Linkers?

An assembler is a tool program that converts assembly language source programs into machine language. A linker is also a tool program that combines the single files generated by the assembler into an executable program. There is another related tool called a debugger, which allows programmers to step through the program and inspect the register and memory state while the program is running.

What Hardware and Software Are Needed?

A computer running a 32-bit or 64-bit Microsoft Windows system with a recent version of Microsoft Visual Studio installed.

What Types of Programs Can MASM Create?

32-bit Protected Mode: 32-bit protected mode programs run on all 32-bit and 64-bit versions of Microsoft Windows. They are generally easier to write and understand than real mode programs. From now on, we will refer to it as 32-bit mode.64-bit Mode: 64-bit programs run on all 64-bit versions of Microsoft Windows.16-bit Real-Address Mode: 16-bit programs run on 32-bit versions of Windows and embedded systems. 64-bit Windows does not support such programs.

What Is the Relationship Between Assembly Language and Machine Language?

Machine language is a digital language designed to be understood by computer processors (CPUs). All x86 processors understand a common machine language.Assembly language contains statements written with short mnemonics such as ADD, MOV, SUB, and CALL. Assembly language has a one-to-one relationship with machine language: each assembly language instruction corresponds to one machine language instruction.

What Is the Relationship Between C++ and Java and Assembly Language?

High-level languages like Python, C++, and Java have a one-to-many relationship with assembly language and machine language. For example, a single statement in C++ may expand into multiple assembly instructions or machine instructions.Most people cannot read raw machine code, so we are discussing the assembly language, which is closest to it. For example, the following C++ code performs two arithmetic operations and assigns the result to a variable. Assume X and Y are integers:

int Y;int X = ( Y + 4 ) * 3;

The equivalent assembly language program is as follows. This conversion requires multiple statements because each assembly statement corresponds to only one machine instruction:

mov eax,Y  ;Load Y into EAX registeradd eax,4  ;Add 4 to the content of EAX registermov ebx,3  ;Load 3 into EBX registerimul ebx   ;Multiply EAX by EBXmov x,eax  ;Store the value of EAX into X

A register is a named storage location in the CPU used to hold intermediate results of operations. The focus of this example is not to show which is better, C++ or assembly language, but to illustrate their relationship.

Is Assembly Language Portable?

A language is considered portable if its source programs can be compiled and run on various computer systems. For example, a C++ program can almost be compiled and run on any computer unless it requires specific references to a certain operating system’s library functions. One of the characteristics of the Java language is that its compiled programs can almost run on all computer systems.Assembly language is not portable because it is designed for specific processor families. Currently, there are various different assembly languages in widespread use, each based on a processor family.For well-known processor families like Motorola 68×00, x86, SUN Sparc, Vax, and IBM-370, assembly language instructions directly match the computer architecture or are converted at execution time by a built-in program in the processor called a microcode interpreter.

Why Learn Assembly Language?

If you still have doubts about learning assembly language, consider these points:

  • If you are studying computer engineering, you will likely be required to write embedded programs. Embedded programs are short programs stored in small capacity memory in dedicated devices, including: phones, automotive fuel and ignition systems, air conditioning control systems, security systems, data acquisition instruments, graphics cards, sound cards, hard disk drives, modems, and printers. Because assembly language occupies less memory, it is an ideal tool for writing embedded programs.

  • Real-time applications that handle simulation and hardware monitoring require precise timing and response. High-level languages do not allow programmers precise control over the machine code generated by the compiler. Assembly language allows programmers to precisely specify the executable code of the program.

  • Computer games require software to be highly optimized in terms of reducing code size and speeding up execution. Game programmers are experts at writing code that fully utilizes the hardware features of a target system. They often choose assembly language as a tool because it allows direct access to computer hardware, enabling manual optimization of code for speed.

  • Assembly language helps form a comprehensive understanding of the interaction between computer hardware, operating systems, and applications. Using assembly language, you can apply and verify the theoretical knowledge gained from computer architecture and operating system courses.

  • Some high-level languages abstract their data representations, making them inconvenient for performing low-level tasks such as bit manipulation. In such cases, programmers often call subroutines written in assembly language to complete their tasks.

  • Hardware manufacturers create device drivers for the devices they sell. A device driver is a program that translates generic operating system commands into specific references to hardware details. For example, printer manufacturers create a different MS-Windows device driver for each model they sell. Typically, these device drivers contain a large amount of assembly language code.

Does Assembly Language Have Rules?

Most assembly language rules are based on the physical limitations of the target processor and its machine language. For example, the CPU requires that the sizes of two instruction operands be the same. Compared to C++ or Java, assembly language has fewer rules because the former uses syntax rules to reduce accidental logical errors, at the cost of restricting low-level data access.Assembly language programmers can easily bypass the restrictive features of high-level languages. For example, Java does not allow access to specific memory addresses. Programmers can use the JNI (Java Native Interface) class to call C functions to bypass this restriction, but the result is that the program is not easy to maintain.In contrast, assembly language can access all memory addresses. However, this freedom comes at a high cost: assembly language programmers need to spend a lot of time debugging.

What Is Assembly Language?

Leave a Comment