COLLEGE OF INFORMATION AND COMMUNICATION TECHNOLOGY (CICOT)
COURSE CODE: CPS 303
COURSE TITLE: ASSEMBLY LANGUAGE PROGRAMMING
TOPIC: ASSEMBLY LANGUAGE PROGRAMMING
BY
SALAWUDEEN IBRAHIM MATRIC NO: S12202019
ASSEMBLY LANGUAGE Introduction An assembly language is a low-level programming language for a computer, or other programmable device, in which there is a very strong correspondence between the language and the architecture's machine code instructions. Each assembly language is specific to a particular computer architecture, in contrast to most high-level programming languages, which are generally portable across multiple architectures, but require interpreters or compiling. Assembly language is converted into executable machine code by a utility program referred to as an assembler; the conversion process is referred to as assembly, or assembling the code. Assembly language uses a mnemonic to represent each low-level machine operation or opcode. Some opcodes require one or more operands as part of the instruction, and most assemblers can take labels and symbols as operands to represent addresses and constants, instead of hard coding them into the program. Macro assemblers include a macroinstruction facility so that assembly language text can be pre-assigned to a name, and that name can be used to insert the text into other code. Many assemblers offer additional mechanisms to facilitate program development, to control the assembly process, and to aid debugging. History Assembly languages date to the introduction of the stored-program computer. Assembly languages eliminated much of the error-prone and time-consuming first-generation programming needed with the earliest computers, freeing programmers from tedium such as remembering numeric codes and calculating addresses. They were once widely used for all sorts of programming. However, by the 1980s their use had largely been supplanted by high-level languages, in the search for improved programming productivity. Today assembly language is still used for direct hardware manipulation, access to specialized processor instructions, or to address critical performance issues. Typical uses are device drivers, low-level embedded systems, and real-time systems. Historically, a large number of programs have been written entirely in assembly language. Operating systems were entirely written in assembly language until the introduction of the Burroughs MCP in 1961, which was written in ESPOL, an Algol dialect. Many commercial applications were written in assembly language as well, including a large amount of the IBM mainframe software written by large corporations. COBOL, FORTRAN and some PL/I eventually displaced much of this work, although a number of large organizations retained assembly-language application infrastructures well into the '90s. Most early microcomputers relied on hand-coded assembly language, including most operating systems and large applications. This was because these systems had severe resource constraints, imposed idiosyncratic memory and display architectures, and provided limited, buggy system services. Perhaps more important was the lack of first-class high-level language compilers suitable for microcomputer use. A psychological factor may have also played a role: the first generation of microcomputer programmers retained a hobbyist, "wires and pliers" attitude. In a more commercial context, the biggest reasons for using assembly language were minimal bloat (size), minimal overhead, greater speed, and reliability. Typical examples of large assembly language programs from this time are IBM PC DOS operating systems and early applications such as the spreadsheet program Lotus 1-2-3. Even into the 1990s, most console video games were written in assembly, including most games for the Mega Drive/Genesis and the Super Nintendo Entertainment System. According to some industry insiders, the assembly language was the best computer language to use to get the best performance out of the Sega Saturn, a console that was notoriously challenging to develop and program games for. The popular arcade game NBA Jam in 1993 is another example. Assembly language has long been the primary development language for many popular home computers of the 1980s and 1990s (such as the Sinclair ZX Spectrum, Commodore 64, Commodore Amiga, and Atari ST). This was in large part because BASIC dialects on these systems offered insufficient execution speed, as well as insufficient facilities to take full advantage of the available hardware on these systems. Some systems, most notably the Amiga, even have IDEs with highly advanced debugging and macro facilities, such as the freeware ASM-One assembler, comparable to that of Microsoft Visual Studio facilities (ASM-One predates Microsoft Visual Studio).
Types There are many types of assembly languages. The current most popular are ARM, MIPS, and x86. ARM is used on lots of cell phones and many embedded systems. MIPS is for Motorola systems - Macs, some video game consoles. x86 assembler is used on Intel PCs. Each flavor has different versions which span the gammut from 16-bit to 64-bit opcodes. The thing about assembly is old architectures tend to die and new ones come along, but the fundamental things that RISC style systems do are mostly the same. It's just a matter of learning the mnemonics between systems. APPLICATIONS 1. Assembly language is typically used in a system's boot code, (BIOS on IBM-compatible PC systems and CP/M), the low-level code that initializes and tests the system hardware prior to booting the operating system, and is often stored in ROM. 2. Some compilers translate high-level languages into assembly first before fully compiling, allowing the assembly code to be viewed for debugging and optimization purposes. 3. Relatively low-level languages, such as C, allow the programmer to embed assembly language directly in the source code. Programs using such facilities, such as the Linux kernel, can then construct abstractions using different assembly language on each hardware platform. The system's portable code can then use these processor-specific components through a uniform interface. 4. Assembly language is valuable in reverse engineering. Many programs are distributed only in machine code form which is straightforward to translate into assembly language, but more difficult to translate into a higher-level language. Tools such as the Interactive Disassembler make extensive use of disassembly for such a purpose. 5. Assemblers can be used to generate blocks of data, with no high-level language overhead, from formatted and commented source code, to be used by other code.
STRUCTURE
Assembly language programs divide roughly into five sections a. header b. equates c. data d. body e. closing
a. HEADER The header contains various directives which do not produce machine code Sample header: %TITLE "Sample Header" .8086 .model small .stack 256
b. EQUATES Constant values are known as equates Sample equate section: Count EQU 10 Element EQU 5 Size = Count * Element MyString EQU "Maze of twisty passages" Size = 0 = is used for numeric values only Cannot change value of EQU symbol EQUated symbols are not variables EQU expressions are evaluated where used; = expressions are evaluated where defined
c. The Data Segment Begins with the .data directive. Two kinds of variables initialized and uninitialized. Initialized variables take up space in the program's code file. Declare uninitialized variables after initialized ones so they do not take up space in the program's code file.
d. The Program Body Also known as the code segment. Divided into four columns: labels, mnemonics, operands, and comments. Labels refer to the positions of variables and instructions, represented by the mnemonics. Operands are required by most assembly language instructions. Comments aid in remembering the purpose of various instructions.
e. The Closing The last lines of an assembly language program are the closing. Indicates to assembler that it has reached the end of the program and where the entry point is main. END is a pseudo-op; the single "operand" is the label specifying the beginning of execution, usually the first instruction after the code pseudo-op.
Relationships Assembly language was invented to make it easier for humans to write machine language. Both are implementation-specific and deal with the individual instructions to the processor, but machine-code is slightly lower level, represented to the human programmer as a series of numbers, and almost always in pure binary. Assembly, on the other hand, is written symbolically, not in pure binary. It is designed to be read by the human programmer and then converted to machine code binary, but still works with individual instructions.