Programming in Assembly

Author: Frank Hunt
Date Of Creation: 13 March 2021
Update Date: 1 July 2024
Anonim
x86 Assembly: Hello World!
Video: x86 Assembly: Hello World!

Content

Programming in assembly is often a crucial starting point when computer programmers are learning their trade. Assembly, or assembly language (or also ASM) is a programming language for computers and other devices, and it is generally considered a low-level variant compared to more advanced languages ​​that provide additional functionality. Once you've written the code, an assembly converts it to machine code (zeros and ones). While the applications for assembly programming have become more limited due to the growing complexity of processors, assembly remains useful for a number of purposes, including writing code for standalone executables or device drivers.

To step

Part 1 of 3: Familiarizing yourself with assembly

  1. Read more about the assembly language. Before attempting to write code, it is always a good idea to understand the language itself first. A number of resources are available, ranging from textbooks to online guides.
  2. Learn the basic terms. For example, you'll want to know that an IDE (integrated development environment) provides a coding interface that handles things like editing text, debugging, and compiling. You can also better understand how assembly actually works, such as the fact that "registers" store the numbers associated with program code. A better understanding of the terminology will make it easier to learn how to program yourself.
  3. Decide if assembly is for you. Keep in mind that there are a number of programming languages, including some that provide much more functionality than assembly. However, there are still a number of applications for which assembly is useful, from creating standalone executables for phone firmware and air conditioning systems, to developing certain processor-specific instructions.
  4. Decide which assembly you want to use. assemblies such as A86, NASM or GNU generally perform less complex functions and can be suitable starting points for beginners. Each assembly works a little differently, but the following instructions work under the assumption that you are using MASM (Microsoft Macro assembly) - a base assembly that works with Windows operating systems. It uses x86 assembly language and Intel syntax.

Part 2 of 3: Download and install the assembly and IDE

  1. Download the assembly yourself. You can find the latest version of MASM in Visual Studio Enterprise 2015 (an extensive IDE with a number of tools), but the simpler original version (MASM 8.0) is free to download. Some assemblies, such as Flat assembly, can be used on multiple operating systems, including Windows, DOS and Linux. Other assembly languages, including Netwide assembly (NASM) and GNU assembly (GAS), also work on a Mac.
    • To download MASM 8.0, click the Download button at the top of the page referenced in this step.
    • System requirements vary depending on the assembly you choose, but MASM 8.0 requires Windows 2000 Service Pack 3, Windows Server 2003, or Windows XP Service Pack 2.
    • For the installation of MASM 8.0 it is also necessary that you have downloaded and installed Visual C ++ 2005 Express Edition.
  2. Download an IDE. Do a search for "WinAsm download" to find and install the WinAsm IDE, which generally works fine with MASM. Other IDEs may be more suitable depending on the programming language you are using. A popular alternative is RadAsm.
  3. Install MASM 8.0. You can start the installation right away by clicking Run once the program has been downloaded. You can also install it at a later time, in that case click Save. After clicking Run, MASM 8.0 will be installed in the folder "[Visual C ++ Express] bin" under the name ml.exe.
  4. Install your IDE. After WinAsm has downloaded, extract the files and copy them to the folder "c: Program Files ". You can also put a shortcut on your desktop to make them easier to access.
  5. Configure your IDE. First start the WinAsm program. If you've placed a shortcut on your desktop, double-click it. Note that this process will be different if you are using a different assembly or IDE.
  6. Integrate WinAsm with MASM 8.0. Start by clicking on the WinAsm's Tools tab, select Options from this tab, and finally select the Files and Paths tab. Then change the first three lines (referring to paths) to your MASM installation folder. When you are done, click OK.
    • When editing the information under the "Files and Paths" tab, the first three lines should read as follows. The binary path must be C: Masm32Bin, the Include path is C: Masm32Include, and the library path is C: Masm32Bin.

Part 3 of 3: Programming

  1. Start writing code. Start with WinAsm and click on the File tab. Then select New project, and you will see several options. These options are Console Application and Standard EXE. For example, if you are trying to create a GUI (graphical user interface) based application, select the latter.
  2. Use assembly program structure. A typical structure can consist of a line defining the architecture, a data section (section.data) with initialized data or constants, a bss section (section.bss) declaring variables, and a text section (section.text) in which you your actual program code. That last section always starts with a global _start declaration. Each sequence is known as a block of code.
  3. Understand the basic commands. There are three types of assembly language statements, executable statements or instructions (these tell processors what to do through operative code), assembly directives or pseudo-ops (these describe assembly processes to the assembly), and macros (these serve as a mechanism for entering of text).

Tips

  • Writing effective code in assembly language (or any other language) generally requires considerable study. In particular, you will want to learn the required syntax for code statements and how to compile and link an assembly program.
  • If you are having difficulty setting up a specific assembly, it may be wise to join a forum where certain questions can be addressed.
  • Some programming languages ​​have facilities to combine assembly, such as the ASM ("") function in C and C ++. This is a good way to start.
  • If you're interested in an IDE that works with newer MASM versions, check out Visual MASM at www.visualmasm.com/.