Coal Week 2 Lectures (Lec 4-6)
Coal Week 2 Lectures (Lec 4-6)
Computer Organization
& Assembly Language
INSTRUCTOR
The linker reads the object file and checks to see if the program contains any calls to procedures in a link library. The
linker copies any required procedures from the link library, combines them with the object file, and produces the
executable file. Microsoft 16-bit linker is LINK.EXE and 32-bit is Linker LINK32.EXE.
OS Loader: A program that loads executable files into memory, and branches the CPU to the program’s starting
address, (may initialize some registers (e.g. IP) ) and the program begins to execute.
Debugger is a utility program, that lets you step through a program while it’s running and examine registers and
memory
Is called Assemble-Link-Execute Cycle.
Listing File
A listing file contains:
a copy of the program’s source code,
with line numbers,
the numeric address of each instruction,
the machine code bytes of each instruction (in hexadecimal), and
a symbol table.
The symbol table contains the names of all program identifiers, segments, and related
information.
Listing File
Use it to see how your program is assembled
Contains:
source code
Object Code
Relative addresses
Segment names
Symbols
Variables
Procedure
Constants
Listing File
Loading and Executing a Program
The operating system (OS) searches for the program’s filename in the current disk
directory.
If it cannot find the name there, it searches a predetermined list of directories (called paths) for
the filename.
If the OS fails to find the program filename, it issues an error message.
If the program file is found, the OS retrieves basic information about the program’s file from the
disk directory, including the file size and its physical location on the disk drive.
The OS determines the next available location in memory and loads the program file into
memory.
It allocates a block of memory to the program and enters information about the program’s size
and location into a table (sometimes called a descriptor table).
Additionally, the OS adjust the values of pointers within the program so they contain addresses
of program data.
Loading and Executing a Program
The OS begins execution of the program’s first machine instruction (its entry
point).
The OS assigns the process an identification number (process ID), which is used to
keep track of it while running.
It is the OS’s job to track the execution of the process and to respond to requests
for system resources.
Examples of resources are memory, disk files, and input-output devices.
When the process ends, it is removed from memory.
Basic Program Execution Registers
Registers are high-speed storage locations directly inside the CPU, designed to be
accessed at much higher speed than conventional memory.
As shown in Figure 2–6, the lower 16 bits of the EAX register can be referenced by the
name AX
The remaining general-purpose registers can only be accessed using 32-bit or 16-bit
names, as shown in the following table:
Specialized Uses of general-purpose
registers
Data Registers (EAX, EBX, ECX, EDX): These four registers are available to the programmer
for general data manipulation.
The high and low bytes of the data registers can be accessed separately.
EAX (Extended Accumulator Register) is preferred to use in in arithmetic, logic and control
instructions.
EBX (Extended Base Register) is used to serve as an address register.
ECX (Extended Counter Register) serves as loop counter.
EDX (Extended Data Register) is used in multiplication and division.
Index Registers
Index Registers contain the offsets for data and instructions.
Offset- distance (in bytes) from the base address of the segment.
ESP (extended stack pointer register) contains the offset for the top of the stack to
addresses data on the stack (a system memory structure)
ESI and EDI (extended source index and extended destination index ) points to the source
and destination string respectively in the string move instructions
EBP is used to reference function parameters and local variables on the stack
Segment Registers
In protected mode, segment registers hold pointers to segment descriptor tables (The
descriptor describes the location, length and access rights of the memory segment).
Some segments hold program instructions (code), others hold variables (data), and
another segment named the stack segment holds local function variables and function
parameters.
Memory
Segment Registers
Memory Segment: A memory segment is a block of consecutive memory bytes.
Each segment is identified by a segment number, staring with 0.
Within a segment, a memory location is specified by giving an off- set. This is the
number of bytes from the beginning of the segment.
To keep track of the various program segments, segment register are used.
The ECS (Extended Code Segment), EDS (Extended Data Segment), and ESS (Extended
Stack Segment) registers contain the code, data, and segment numbers respectively.
If a program needs to access a second data segment, it can use the EES (Extended
Extra segment) register.
Instruction Pointer
The EIP, or instruction pointer, register contains the address of the next instruction to be
executed.
Certain machine instructions manipulate EIP, causing the program to branch to a new
location.
EFLAGS Register
The EFLAGS register consists of individual binary bits that control the operation of the
CPU or reflect the outcome of some CPU operation.
A flag is set when it equals 1; it is clear (or reset) when it equals 0.
Programs can set individual bits in the EFLAGS register to control the CPU’s operation
For example: Interrupt when arithmetic overflow is detected
EFLAGS Register
There are two types of flags:
Control flags: which determine how instructions are carried out
Status flag: which report on the result operation
Control flags include:
Direction Flag (DF): affects the direction of block data transfers (like long character string)
1=up; 0= down.
Interrupt Flag (IF): determines whether interrupts can occur (whether devices like keyboard,
disk drives and system clock can get the CPU’s attention to get their needs attended to.
Trap Flag (TF): determines whether the CPU is halted after every instruction. Used for
debugging purposes
EFLAGS Register
protected mode,
Windows XP can execute multiple separate virtual-8086 sessions at the same time
Mode of Operations
The data segment holds the base address for variables. This segment stores data for the
program
The extra segment is an extra data segment (often used for shared data)
The stack segment holds the base address for the stack. The segment is also to store interrupt
and subroutine return addresses
Real Address Mode
Linear address = Segments x 10 (hex) + Offset
Example:
Given:
Segment = A1F0 (hex)
Offset = 04C0 (hex)
Logical Address = A1F0:04C0 (hex)
What is linear address?
Solution:
Real Address Mode
Address Space
In 32-bit protected mode, a task or program can address a linear address space of up
to 4 GB
Real-address mode programs, on the other hand, can only address a range of 1 MB