Professional Documents
Culture Documents
ECE 314 WK7 - Assembly Language Basics
ECE 314 WK7 - Assembly Language Basics
Language:
Example: In a hypothetical machine
language, an opcode of "0001" might
represent addition, while "0010"
represents subtraction.
In many machine language instructions, there
are one or more operands. Operands provide
the data or addresses needed to carry out the
specified operation. The way operands are
encoded can vary, but there are two primary
methods:
How Instructions
are Encoded in a. Immediate Operand: The value of the
operand is directly included within the
Machine instruction itself. For example, if you want to
add the value 42 to a register, the immediate
The assembler, a program that converts assembly code into machine code, maps each
mnemonic to a specific binary opcode (operation code) and encodes the operands
accordingly.
For example, MOV AX, BX might be translated into a sequence of 0s and 1s that
represent the appropriate opcode and operands for the given CPU architecture.
What Are
Registers
Registers are small, high-speed storage locations within
a CPU (Central Processing Unit) that are used to hold
data temporarily during program execution. Think of
registers as the CPU's internal scratchpad or working
memory.
Key Characteristics
of Registers:
Speed: Registers are the fastest storage locations in a computer. Accessing data from registers is
significantly quicker than accessing data from memory.
Limited in Number: A CPU typically has a limited number of registers, which can vary depending on
the architecture. Common register sets include general-purpose registers, special-purpose registers,
and floating-point registers.
Usage: Registers are used for a variety of purposes, including data storage, arithmetic operations,
addressing memory, and control flow operations.
3 Types of
Registers:
General-Purpose Registers: These registers can be used for a wide range of tasks, such as
holding data, performing arithmetic operations, and serving as temporary storage for
intermediate results. Common examples include AX, BX, CX, and DX.
General-Purpose
Registers (8086):
The 8086 architecture includes several general-purpose registers, each serving a specific purpose:
AX (Accumulator): Often used for arithmetic operations and data manipulation. For example, you might
perform addition or subtraction with data in AX.
BX (Base Register): Typically used for addressing data in memory, especially in conjunction with the DI or SI
registers for effective address calculations.
CX (Count Register): Often used for loop control and string operations. It can also serve as a general-
purpose register.
DX (Data Register): Used in arithmetic operations and for I/O operations, such as transferring data
between the CPU and peripheral devices.
3 Types of
Registers:
Special-Purpose Registers: These registers serve specific
functions within the CPU.
Special-Purpose
Registers (8086):
IP (Instruction Pointer): Keeps track of the memory address of the next instruction to be executed. It is
crucial for program control flow.
SP (Stack Pointer): Points to the top of the stack, which is essential for managing the program's call
stack during function calls and subroutine execution.
BP (Base Pointer): Often used as a reference point for accessing data on the stack within function calls.
It helps maintain a stable frame for the current function.
SI (Source Index) and DI (Destination Index): These registers are commonly used for string
manipulation instructions like copying, comparing, or searching strings in memory.
Segment
Registers (8086):
In addition to general-purpose and special-purpose registers, the 8086
architecture features segment registers, which are used for memory segmentation:
CS (Code Segment): Points to the segment in memory containing executable code.
DS (Data Segment): Points to the segment in memory containing data.
ES (Extra Segment): Often used as an additional data segment in some operations,
like string manipulations.
SS (Stack Segment): Points to the segment in memory used for the stack.
FS and GS (Additional Segments): In later x86 architectures (not strictly 8086),
these registers are introduced for additional data segments.
Memory and Addressing in Assembly
Language
Memory Addresses:
Memory locations are identified by numerical addresses. Each address corresponds to a specific
location in memory where data or instructions are stored.
Addresses are typically represented within square brackets, such as [1234], indicating the data or
instruction stored at memory address 1234.
Memory Access in Assembly Language:
Direct addressing is a simple memory access mode where the memory address is explicitly
provided within the instruction.
This mode is suitable for accessing data at specific, known memory addresses.
Example: MOV AL, [4567] loads the byte at memory address 4567 into the AL register.
Register Addressing:
Register addressing mode involves using a register as an indirect pointer to a memory address.
The content of the register serves as the address.
It's often used when the memory address is stored in a register and needs to be accessed
indirectly.
Example: MOV [BX], AX stores the content of the AX register at the memory address specified by
the BX register.
Indexed Addressing:
Indexed addressing mode is especially useful when working with data structures like arrays. It
allows you to add an offset or index to a base memory address to access elements efficiently.
Example: MOV CX, [SI+10] loads the value at the memory address SI+10 into the CX register,
where SI serves as the base address.
Memory Operations:
Apart from data movement, assembly instructions like ADD, SUB, and CMP can directly operate
on data stored in memory locations.
These instructions allow for arithmetic operations and comparisons with memory-resident data.
Example: ADD [BX], 5 adds 5 to the value stored at the memory address specified by the BX
register.
Importance in Assembly Programming:
Memory Models:
In some CPU architectures like x86, memory is organized into
segments, and different memory models define how memory is
accessed. These models dictate the addressing schemes used in
programs.
Addressing Range:
Different CPU architectures have varying addressing ranges,
determined by the number of address bits available. For example, the
8086 CPU has a 20-bit address bus, allowing access to a maximum of 1
MB of memory.
What Are Instruction Sets?