0% found this document useful (0 votes)
49 views34 pages

COAL Chapter 3: Week 3 Shoaib Rauf

The document discusses the basic program execution registers in a CPU including general purpose registers like EAX, EBX, ECX, and EDX which are used for arithmetic, data movement, and specialized tasks. It also covers other registers like segment registers, index registers, flags register EFLAGS, and instruction pointer EIP. The registers store data and instructions during program execution and various instructions can manipulate the registers to perform operations.

Uploaded by

poka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views34 pages

COAL Chapter 3: Week 3 Shoaib Rauf

The document discusses the basic program execution registers in a CPU including general purpose registers like EAX, EBX, ECX, and EDX which are used for arithmetic, data movement, and specialized tasks. It also covers other registers like segment registers, index registers, flags register EFLAGS, and instruction pointer EIP. The registers store data and instructions during program execution and various instructions can manipulate the registers to perform operations.

Uploaded by

poka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

COAL Chapter 3

Week 3
Shoaib Rauf

Courtesy: Dr. Muhammad Nouman Durrani


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

• There are eight general-purpose registers, six


segment registers, a processor status flags
register (EFLAGS), and an instruction pointer
(EIP)
General-Purpose Registers:

The general-purpose registers are primarily used for arithmetic


and data movement.

• As shown in Figure 2–6, the lower 16 bits of the EAX


register can be referenced by the name AX

• Portions of some registers can be addressed as 8-bit values


– For example, the AX register, has an 8-bit upper half named AH
and an 8-bit lower half named AL
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

Some general-purpose registers have specialized uses:


• EAX (accumulator) - favored for arithmetic operations.
– It is automatically used by multiplication and division
instructions

• EBX (Base) - Holds base address for procedures and


variables

• ECX - The CPU automatically uses ECX as a counter for


looping operations

• EDX (Data) - Used in multiplication and division operations


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 real-address mode, 16-bit segment registers indicate base
addresses of pre-assigned memory areas named segments.
– 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.
• 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
The Status flags reflect the
outcomes of arithmetic and
logical operations performed
by the CPU.

Parity- is set if the least-significant byte in the result contains an


even number of 1 bits. It used to verify memory integrity.
Integer Constants
Integer Expressions
• An integer expression is a mathematical expression involving integer
values and arithmetic operators
• The integer expression must evaluate to an integer, which can be stored in
32 bits (0 through FFFFFFFFh)
Directives
• Commands that are recognized and acted upon by the assembler
– Not part of the Intel instruction set
– Used to declare code, data areas, select memory model, declare
procedures, etc.
– not case sensitive

• Different assemblers have different directives


– NASM not the same as MASM, for example

myVar DWORD 26 ; DWORD directive, set aside


; enough space for double word
Mov eax, myVar ; MOV instruction

Irvine, Kip R. Assembly Language


for x86 Processors 6/e, 2010. 20
Instructions
• An instruction is a statement that becomes executable when a program is
assembled.

• Assembled into machine code by assembler

• Executed at runtime by the CPU

• We use the Intel IA-32 instruction set

• An instruction contains:
– Label (optional)
– Mnemonic (required)
– Operand (depends on the instruction)
– Comment (optional)

• Basic syntax
– [label:] mnemonic [operands] [ ; comment]

Irvine, Kip R. Assembly Language


for x86 Processors 6/e, 2010. 22
Labels
• Act as place markers
– marks the address (offset) of code and data

• Follow identifier rules

• Data label
– must be unique
– example: myArray (not followed by colon)
– count DWORD 100

• Code label
– target of jump and loop instructions
– example: L1: (followed by colon)

Irvine, Kip R. Assembly Language for x86


Processors 6/e, 2010. 25
Mnemonics and Operands
• Instruction Mnemonics
– memory aid
– examples: MOV, ADD, SUB, MUL, INC, DEC

• Operands
– constant 96
– constant expression2 + 4
– register eax
– memory (data label) count

Constants and constant expressions are often called immediate values

Irvine, Kip R. Assembly Language for x86


Processors 6/e, 2010. 26
Instruction Format Examples
• No operands
– stc ; set Carry flag

• One operand
– inc eax ; register
– inc myByte ; memory

• Two operands
– add ebx, ecx ; register, register
– sub myByte, 25 ; memory, constant
– add eax, 36 * 25 ; register, constant-expression

Irvine, Kip R. Assembly Language for x86


Processors 6/e, 2010. 27
.data
promptUse byte "Enter two integers: ", 0
results byte "Result is: ", 0
.code
main proc mov edx, offset results
mov esi, offset array call writestring
mov ecx, int_count
l1:
call writeint
mov edx, offset promptUser exit
call writestring main endp
call readint
mov [esi],eax end main
add eax, [esi]
add esi, type dword
loop l1

You might also like