Title: More on Assembler
1More on Assembler
2Output from use of Assembler (1 of 2)
- The output from an Assembler may consist of
- a listing of the original Assembly Language
program and the machine code generated, - a listing of errors encountered in the Assembly
process, with or without suggested causes for the
error, - a symbol table,
- / continued
3Output from use of Assembler (2 of 2)
- A cross-reference table showing where each symbol
is to be found within the program, a summary of
external references used within the program, and
whether these are resolved or unresolved, - a list of subroutines and macros and their
lengths in bytes. - Any use of subroutines requires a defined
mechanism of subroutine linkage to be built into
the Assembly language.
4Structure of Assembly Programs
- When you first look at an Assembly language
program you might see comments and instructions.
Like any programming, it takes a little while to
distinguish what is documentation and what is
code. - As well as these two sections of a program there
may also be 'calls' to other programs (including
macros) or 'includes'.
5Structure of Assembly Programs (2)
- In some Assemblers there is a possibility that
libraries of other code might be made open -
included - for the use of the program that
follows the 'include' statement.
6Comments
- Comments are most usually denoted by the use of
semicolon () or a hash (). - You might see a heading like this
-
-
- Art's Assembler Code
- Program 1
-
-
-
- Below this line is a list of code.
7Comments
- Or something like this
- This is an Assembler program
-
- Written by Art
- Date 28 Nov 2006
-
- --- oOo ---
-
-
- Below this line is a list of code.
8More on Program Structure
- In assembly language code lines have two parts
- ltinstructiongt ltparametergt, ltparametergt
- . Part 1 . Part 2 ..
- The first part is the name of the instruction
which is to be executed. The second part has the
parameters of the command. For example - MOV AL, 25
- In the above example, we are using the
instruction 'MOV'. This particular line of code
means "move the value 25 to the AL register".
9More on Program Structure (2)
- In this case 'AL' is the name of a particular
register - AL and AH combined make up the AX
register. (Remember, there are usually 32
registers and they all are named, labelled or
numbered to allow an Assembler programmer to use
them specifically.) - Is that '25' an actual decimal value of 25? In
this case, YES because this is an example. Most
Assembly Languages use Hexidecimal numbering for
calculations and addressing.
10More on Program Structure (3)
- Another example
- ADD AH BH
- Here 'ADD' is the command to be executed - in
this case an addition. "AH" as well as "BH" are
the parameters. If we assume that AH and BH are
the labels for parts of the AX and BX registers
then the contents of BH will be added to the
contents of AH and the value is usually stored in
the first register of the two parameters - in
this case, AH.
11More on Program Structure (4)
- The name of the instructions in many Assembly
Languages is made of two, three or four letters. - These instructions are also called mnemonic names
or operation codes, since they represent a
function the processor will perform. - Sometimes instructions are used as follows
- ADD AL, 170
- The brackets in the second parameter indicate
that the programmer is working with the content
of the memory cell number 170 and not with the
170 as a value. This is known as direct
addressing.
12Mnemonics
- Coming up in two slides is a list of instruction
mnemonics used by many Assemblers. - Each listed instruction has one or two examples
but there may be several more examples of each
type of instruction. - In actual programs there will most often be
numbers or addresses pertaining to the mnemonic
that follow the three- or four-letter instruction.
13Mnemonics (2)
- Also, there may be variations on the instruction.
- An example of that is MOV since this instruction
does not need parameters when it appears as MOVS.
- In this case the 'S' is a dedicated register for
this type of instruction.
14Instruction Types
- Transfer instructions
- Transfer instructions are used to move the
contents of the operators. - MOV (parameters)
- MOVS
15Instruction Types (2)
- Loading instructions
- Loading instructions are used to load bytes or
groups of bytes into a register. - LODS
16Instruction Types (3)
- Stack instructions
- Stack instructions allow the 'stack' to be used
to store or retrieve data. - POP (parameter)
- PUSH (parameter)
17Instruction Types (4)
- Logic instructions
- Logic instructions are used to perform logic
operations on the operators. - AND OR TEST
18Instruction Types (5)
- Arithmetic instructions
- Arithmetic instructions are used to perform
arithmetic operations on the operators. - ADD (parameters)
- SUB (parameters)
- MUL (parameters)
- DIV (parameters)
19Instruction Types (6)
- Jump instructions
- Jump instructions are used to transfer the flow
of the process to the indicated operator. - JMP (parameter)
20Instruction Types (7)
- Loop instructions
- Loop instructions are used transfer the process
flow, conditionally or unconditionally, to a
destiny, repeating this action until the counter
is zero. - LOOP (parameter)
21Instruction Types (8)
- Counting instructions
- Counting instructions are used to decrease or
increase the content of the counter or counters. - INC (parameter)
- DEC (parameter)
22Instruction Types (9)
- Comparison instructions
- Comparison instructions are used to compare
operators. - CMP (parameters)
23Instruction Types (10)
- Flag instructions
- Flag instructions directly affect the content of
the flag or flags. - CLI (CLear Instruction flag)
- STI (STart Instruction flag)
24NASM - Microsoft's Assembler
- The Netwide Assembler, NASM, is an 80x86
assembler designed for portability and
modularity. It supports a range of object file
formats, including - Linux a.out and ELF,
- (ELF Executable and Linkable Format object
files), - NetBSD/FreeBSD,
- (BSD Berkley Software Distribution)
- COFF, (Common Object File Format)
- Microsoft 16-bit OBJ, (Object files)
- Win32 and
- rdf (relocatable dynamic object file format)
25NASM - Microsoft's Assembler (2)
- NASM will output plain binary files.
- Its syntax is designed to be simple and easy to
understand, similar to Intel's but less complex. - It supports Pentium, P6 and MMX opcodes and has
macro capability.
26NASM - Microsoft's Assembler (3)
- The Netwide Assembler came about because there
was a need for a good free x86-series assembler
that system programmers (or anybody) could use.
27NASM Versus Others
- Comparing other assemblers to NASM
- A86 is good, but not free. It is DOS only. Users
have to pay for 32-bit capability. - AS86 is Linux-specific It does not have much
documentation. - Gas is free, and ports over DOS and Unix, but it
is not very useful since error checking is
minimal. The syntax is difficult to work with.
You cannot write 16-bit code using this assembler.
28NASM Versus Others (2)
- MASM (Microsoft Macro Assembler) is expensive.
It runs under DOS only. - TASM (Turbo Assembler) is user friendly. Its
syntax is much like MASM's. It is expensive. It
is DOS-only.
29NASM with Operating Systems
- NASM can be used with the following operating
systems - Windows
- DOS (Disk Operating System)
- Linux
- BSD (Berkley Software Distribution)
- QNX (A real time Operating System based on Unix)
30NASM with Operating Systems (2)
- Can you assemble and use the same NASM code
across multiple Operating Systems? A generic NASM
subroutine will assemble and be usable under
every operating system it supports.
31NASM with Operating Systems (3)
- NASM has the widest set of books that teaching
assembly language programming to beginners in a
non-DOS environment. - NASM should be compatible with two other 'asm'
assemblers MASM and TASM. It is not compatible
with FASM (Flat Assembler), though.
32MASM
- The name MASM originally referred to Macro
Assembler but over the years it has become
synonymous with Microsoft Assembler. - MASM, as a programming tool, had its earliest
version in 1981. - MASM has Intel syntax for writing x86 assembler
and it is a de facto standard in terms of its
compatibility with Microsoft object file formats. - But
33MASM (2)
- Many people do not like code that is not open
source. (MASM is not open source.) - MASM is not the fastest assembler available.
- MASM is not the most powerful assembler
available. (E.g. TASM is faster.) - Because using MASM involves the use of MS-DOS
operating system it is of little use to
programmers wanting to learn or use assembly
language on modern Operating Systems.
34TASM
- Turbo Assembler is, like many of them, a
stand-alone assembler. - It includes all the tools needed to create and
debug assembly programs for 16 and 32 bit DOS and
Windows platforms, including Windows 3.X, Win95,
Win98, and NT. Some of the tools included are
assemblers, linkers, console style debuggers, and
resource compilers. Each of these tools comes in
a 16 bit and a 32 bit version. - It is Borland Turbo Assembler. It has full Intel
chip set support-from 8086 to Pentium.
35TASM (2)
- Specifications include
- Up to 48,000 lines-per-minute assembly
- Full 8088, 8086, 80286, 80386, i486, and Pentium
support - IDEAL and MASM assembly modes
- Interface support for C, C, Pascal, FORTRAN,
and COBOL - Multi-pass assembler with forward-reference
resolution - Fast 16- and 32-bit Turbo Linker
- Turbo Debugger for DOS and Windows
36FASM
- Flat Assembler is an Intel x86 macro Assembler
for MSDOS, Win32 and Linux systems that accepts
16 bit and 32 bit 80x86/Pentium code, MMX, SSE,
SSE2 instructions and macros. - It has support for code optimisation and can
generate binary files, MZ and PE executables. - FASM Is not widely used since it is not as
flexible as NASM and MASM.