Assembly Language
- An assembly language is a low-level programming language for microprocessors and other programmable devices. It is not just a single language, but rather a group of languages. An assembly language implements a symAn assembly language is a low-level programming language for microprocessors and other programmable devices. It is not just a single language, but rather a group of languages. An assembly language implements a symbolic representation of the machine code needed to program a given CPU architecture.
- Assembly languages generally lack high-level conveniences such as variables and functions, and they are not portable between various families of processors. They have the same structures and set of commands as machine language, but allow a programmer to use names instead of numbers. This language is still useful for programmers when speed is necessary or when they need to carry out an operation that is not possible in high-level languages.
Why is ASM useful?
- Machine language is a series of numbers, which is not easy for humans to read. Using ASM, programmers can write human-readable programs that correspond almost exactly to machine language.
- The disadvantage is that everything the computer does must be described explicitly, in precise detail. The advantage is that the programmer has maximum control over what the computer is doing.
Read External link-https://bcastudyguide.com/unit-6-assembly-language-2/
Why is ASM a “low-level” language?
- In general, one line of an assembly program contains a maximum of one instruction for the computer.
Read more-https://pencilchampions.com/unit-5-evaluation-of-microprocessor-caal-bca-3rd-sem/
How is ASM different from a “high-level” language?
- Programming this way is more convenient and makes programs easier to read at the sacrifice of low-level control.
- Programs written in high-level languages will never match the raw speed and efficiency of programs written in assembly. Examples of high-level languages include Python, Java, JavaScript, Clojure, and Lisp.
What is a “mid-level” language?
- Programs written in mid-level languages can perform as well, or nearly as well, as programs written in assembly language. Examples of mid-level programming languages include C, C++, Ada, Nim, and Rust.
Is ASM portable?
- A program written in C may require some changes before it will compile on another computer, but the core language is portable.
- The lowest-level languages — machine language and assembly language — are not portable.
Assembly level instructions
- An assembly program can be divided into three sections −
- The data section,
- The bss section, and
- The text section.
The data Section
- The data section is used for declaring initialized data or constants. This data does not change at runtime. You can declare various constant values, file names, or buffer size, etc., in this section
The bss Section
- The bss section is used for declaring variables.
The text section
- The text section is used for keeping the actual code. This section must begin with the declaration global _start, which tells the kernel where the program execution begins.
Read more- https://pencilchampions.com/tag/data-structure-bca/
Comments
- Assembly language comment begins with a semicolon (;). It may contain any printable character including blank. It can appear on a line by itself, like screen
Assembly Language Statements
Read External –https://bcastudyguide.com/unit-6statistical-quality-control/
Assembly language programs consist of three types of statements −
- Executable instructions or instructions,
- Assembler directives or pseudo-ops, and
- Macros.
- The executable instructions or simply instructions tell the processor what to do. Each instruction consists of an operation code (opcode). Each executable instruction generates one machine language instruction.
- The assembler directives or pseudo-ops tell the assembler about the various aspects of theprocess. These are non-executable and do not generate machine language instructions.
- Macros are basically a text substitution mechanism.
Example: Hello, World! in 32-bit assembly, for Windows
- Here is “Hello, World” written for a 32-bit Intel processor. It will also run on a 64-bit processor. We will compile and run it on
- To begin, open Notepad. Copy and paste the code above into a new text file, and save the file as hello.asm.
- To compile the we use NASM, the Netwide Assembler.
- When you run this command, NASM creates an object file. An object file contains machine code, but is not quite an executable file.
- To create the executable, we use the 32-bit version of MinGW (Minimal GNU for Windows) which provides the gcc compiler. It can be downloaded at MinGW site.
Use of macros
- A macro definition is a block of code enclosed between
MACRO
andMEND
directives. It defines a name that you can use as a convenient alternative to repeating the block of code.The main uses for a macro are: - To make it easier to follow the logic of the source code by replacing a block of code with a single meaningful name.
- To avoid repeating a block of code several times.