This document provides an overview of assembly language and its relationship to other levels of software. It defines key concepts like machine language, assemblers, and debuggers. Tables describe the software hierarchy, compare assembly to high-level languages, and show number systems and data sizes. Examples demonstrate an assembling and debugging a simple assembly language program.
1. Chapter 1: Context of
Assembly Language
Slides to Accompany
Assembly Language for Intel-Based Computers,
Third Edition
Copyright 1999-2000, Prentice-Hall Incorporated
Updated 08/00
2. Table 1. Software Hierarchy Levels.
Level Description
Application Program
Software designed for a particular class of
applications.
High-Level Language (HLL)
Programs are compiled into either assembly language
or machine language. Each statement usually
translates into multiple machine language instructions.
Examples are C++, Pascal, Java, and Visual Basic.
Operating System
Contains procedures that can be called from programs
written in either high-level language or assembly
language. This system may also contain an application
programming interface (API).
Assembly Language (ASM)
Uses instruction mnemonics that have a one-to-one
correspondence with machine language.
Machine Language (ML)
Numeric instructions and operands that can be stored
in memory and directly executed by the computer
processor.
3. Essential Tools
• An assembler is a program that converts source-code
programs into a machine language (object file).
• A linker joins together two or more object files and
produces a single executable file.
• A debugger loads an executable program, displays
the source code, and lets the programmer step
through the program one instruction at a time, and
display and modify memory.
4. Figure 1. Machine Language Generation by ASM and
HLL programs.
ASM ML
ML
ML
ML
ML
HLL
5. Table 2. Comparison of Assembly Language to HLLs.
Type of Application High-Level Language Assembly Language
Business application
Formal structures make it
software, written for
easy to organize and
single platform, medium
maintain large sections of
to large size.
code.
No formal structure.
Programmer must impose an
artificial structure.
Hardware device driver. Language may not provide
for direct hardware access.
Awkward coding techniques
must be used, resulting in
possible maintenance
problems.
Hardware access is
straightforward and simple.
Easy to maintain when the
programs are short and well
documented.
Business application
written for multiple
platforms (different
operating systems).
Usually very portable. The
source code can be
recompiled on each target
operating system with
minimal changes.
Must be recoded separately
for each platform, often
using an assembler with a
different syntax. Difficult to
maintain.
Embedded systems and
computer games
requiring direct
hardware access.
Produces too much
executable code, and may
not run efficiently.
Ideal, because the
executable code is small
and runs quickly.
6. Figure 2. Assembly Language Subroutines Used as
Hardware Interfaces.
Application
Program
Interface
Subroutine
Operating
System
Device Driver
Subroutine
Hardware
7. Machine Language
• Consists of binary numbers
• The "native" language of the computer
• Each ML instruction contains an op code (operation
code) and zero or more operands.
• Examples:
Opcode Operand Meaning
-------------------------------------------------
40 increment the AX register
05 0005 add 0005 to AX
8. Page 7: Bits, Bytes, and Doublewords:
byte byte
0 0 1 0 0 1 1 0 0 1 1 0 1 0 1 0 bit
word
Each 1 or 0 is called a bit.
9. Table 3. Storage Sizes and Ranges of Unsigned Integers.
Storage Type Bits Range (low - high)
Unsigned byte 8 0 to 255
Unsigned word 16 0 to 65,535
Unsigned doubleword 32 0 to 4,294,967,295
Unsigned quadword 64 0 to 18,446,744,073,709,551,615
10. Table 4. Digits in Various Number Systems.
System Base Possible Digits
Binary 2 0 1
Octal 8 0 1 2 3 4 5 6 7
Decimal 10 0 1 2 3 4 5 6 7 8 9
Hexadecimal 16 0 1 2 3 4 5 6 7 8 9 A B C D E F
11. Page 9. ASCII Digit String.
Format Value
ASCII binary "01000001"
ASCII decimal "65"
ASCII hexadecimal "41"
ASCII octal "101"
18. Table 8. Signed Integer Storage and Ranges.
Storage Type Bits Range (low - high)
Signed byte 7 -128 to +127
Signed word 15 –32,768 to +32,767
Signed doubleword 31 –2,147,483,648 to 2,147,483,647
Signed quadword 63 –9,223,372,036,854,775,808 to
+9,223,372,036,854,775,807
20. 1.3 Introducing Assembly Language
• An instruction is a symbolic representation of a
single machine instruction
• Consists of:
– label always optional
– mnemonic always required
– operand(s) required by some instructions
– comment always optional
• Examples:
start: mov ax,20 ; initialize the AX register
inc bx ; increment the BX register
stc ; set the Carry flag
22. Running DEBUG.EXE, Assembling a Program
C:>debug
-A 100
0AFE:0100 mov ax,5
0AFE:0103 add ax,10
0AFE:0106 add ax,20
0AFE:0109 mov [120],ax
0AFE:010C int 20
0AFE:010E
assemble, starting at
offset 100
Press ENTER to return to
command mode
23. Tracing the Sample Program.
-T
AX=0005 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0AFE ES=0AFE SS=0AFE CS=0AFE IP=0103 NV UP EI PL NZ NA PO NC
0AFE:0103 051000 ADD AX,0010
-T
AX=0015 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0AFE ES=0AFE SS=0AFE CS=0AFE IP=0106 NV UP EI PL NZ NA PO NC
0AFE:0106 052000 ADD AX,0020
-T
AX=0035 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0AFE ES=0AFE SS=0AFE CS=0AFE IP=0109 NV UP EI PL NZ NA PE NC
0AFE:0109 A32001 MOV [0120],AX
24. Tracing the Sample Program (2)
MOV [0120],AX
-D 120,121
0AFE:0120 35 00
AX=0035 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0AFE ES=0AFE SS=0AFE CS=0AFE IP=010C NV UP EI PL NZ NA PE NC
0AFE:010C CD20 INT 20
-G
Program terminated normally
25. Table 9. Commonly Used Debug Commands.
Command Description
A Starts assembling a program, placing each instruction in
memory. Optionally, an integer argument can be
supplied, which specifies the hexadecimal location
where the first instruction is to be inserted.
G Executes the remainder of the program.
Q Quits Debug
R Displays the CPU registers.
T Traces (execute) one program instruction.