Lab Manual 1
Lab Manual 1
Lab # 01
1
Department of Computer Science and &
Computer Architecture & Organization Information Technology Engineering
16- Bits
Accumulator
AX
Base Index
BX
Count
CX
Data
DX
SP Stack pointer
BP Base Pointer
DI Destination
SI Source Index
Instr. Pointer
IP
FLAGS
FLAGS
Code Segment
CS
Data Segment
DS
SS Stack Segment
ES Extra Segment
2.1 Registers
Registers are temporary storage locations inside the processor. A register can be accessed more
quickly than a memory location. Different registers serve different purposes. Some of them are
described below:
2.1.1 General-Purpose Registers
EAX, EBX, ECX and EDX are called data or general purpose registers. (E is for extended as they
are 32-bit extensions of their 16-bit counter parts AX, BX, CX and DX in 16-bit ISA). Other
General purpose registers includes BP, DI and SI registers . Bits in a register are conventionally
numbered from right to left, beginning with 0 as shown below.
31 30 29 -------- 2 1 0
2
Department of Computer Science and &
Computer Architecture & Organization Information Technology Engineering
Apart from accessing the register as a whole, EAX, EBX, ECX, EDX registers can be accessed
in pieces as illustrated in Figure 1-2
. AH AL 8 bits + 8 bits
AX
16 bits
EAX 32 bits
Figure 1-2
Register Purpose
AX For 16/32 bits operations, AX registers stores operands for arithmetic operations.
ESI(Extended Source Index) and EDI(Extended Destination Index) registers are respectively used as
source and destination addresses in string operations. They can also be used to implement array
indices.
The EIP (Extended Instruction Pointer) register contains the offset in the current code segment for
the next instruction to be executed. (Segments will be explained shortly). ESP(Extended Stack
Pointer) and EBP(Extended Base Pointer) are used to manipulate stack - a memory area reserved for
holding parameters and return address for procedure calls. ESP holds address of top of stack, location
where the last data item was pushed. EBP is used in procedure calls to hold address of a reference
point in the stack.
3
Department of Computer Science and &
Computer Architecture & Organization Information Technology Engineering
EFLAGS register is never accessed as a whole. Rather, individual bits of this register either control
the CPU operation (control flags) or reflect the outcome of a CPU operation (status flag). Table
below gives some of the commonly used control and status flags.
8 Trap Flag (TF) Control Permits operation of the processor in single-step mode.
Indicates that all external interrupts, such as keyboard
9 Interrupt Flag (IF) Control entry, are to be processed or ignored.
Table below gives the clear understanding that how these registers can be view and use in
programming.
4
Department of Computer Science and &
Computer Architecture & Organization Information Technology Engineering
Consider for example, storing 0xA2B1C3D4 in main memory. The two byte orderings are
illustrated below.
2030 A2 D4 2030
B1 C3
2031 2031
C3 B1
2032 2032
D4 A2
2033 2033
BIG LITTLE
The segment registers (CS, DS, SS, ES, FS, and GS) hold 16-bit segment selectors. Each of the
segment registers is associated with one of three types of storage: code, data, or stack. For example,
the CS register contains the segment selector for the code segment, where the instructions being
executed are stored. The processor fetches instructions from the code segment, using a logical
address that consists of the segment selector in the CS register and the contents of the EIP register.
The EIP register contains the offset within the code segment of the next instruction to be fetched.
CS
CS
DS
DS
SS
SS
ES
FS
GS
DS
DS
DS
EXERCISE:
1. Fill in the following tables to show storage of 0xABDADDBA at address 1996 in the
memory of a machine using (i) little endian (ii) big endian byte ordering.
Contents
Address Contents
1996
1997
1998
1999
BIG Endian
LITTLE Endian
3. Show the ECX register and the size and position of the CH, CL, and CX within it.
4. For each add instruction in this exercise, assume that EAX contains the given contents before the
instruction is executed. Give the contents of EAX as well as the values of the CF, OF, SF, PF,
AF and ZF after the instruction is executed. All numbers are in hex. (Hint: add eax, 45 adds 45 to
the contents of register eax and stores the result back in eax)