17
Assembly Disc2 Eng Alaa.I.Haniya

Assembly lab lab1 - site.iugaza.edu.ps

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Assembly lab lab1 - site.iugaza.edu.ps

Assembly Disc2

Eng Alaa.I.Haniya

Page 2: Assembly lab lab1 - site.iugaza.edu.ps

Basic Microcomputer Design

• clock synchronizes CPU operations

• control unit (CU) coordinates sequence of execution steps

• ALU performs arithmetic and bitwise processing

Central Processor Unit

(CPU)

Memory Storage

Unit

registers

ALU clock

I/O

Device

#1

I/O

Device

#2

data bus

control bus

address bus

CU

Page 3: Assembly lab lab1 - site.iugaza.edu.ps

Clock

synchronizes all CPU and BUS operations

machine (clock) cycle measures time of a single operation

clock is used to trigger events

one cycle

1

0

Page 4: Assembly lab lab1 - site.iugaza.edu.ps

Instruction Execution Cycle

• Fetch

• Decode

• Fetch operands

• Execute

• Store output

I-1 I-2 I-3 I-4

PC program

I-1instruction

register

op1op2

memory fetch

ALU

registers

write

decode

execute

read

write

(output)

registers

flags

Page 5: Assembly lab lab1 - site.iugaza.edu.ps

I-1 I-2 I-3 I-4

PC program

I-1instruction

register

op1op2

memory fetch

ALU

registers

write

deco

de

execute

readw

rite

(output)

registers

flags

Page 6: Assembly lab lab1 - site.iugaza.edu.ps

Multi-Stage Non-Pipeline

Instruction execution divided into discrete stages

S1 S2 S3 S4 S5

1

Cycle

s

Stages

S6

2

3

4

5

6

7

8

9

10

11

12

I-1

I-2

I-1

I-2

I-1

I-2

I-1

I-2

I-1

I-2

I-1

I-2

Example of a non-pipelined processor.

1.Many wasted cycles.

2.For k state and n instruction , the number of required cycles is n*k.

Page 7: Assembly lab lab1 - site.iugaza.edu.ps

Pipelined Execution

More efficient use of cycles, greater throughput of instructions:

S1 S2 S3 S4 S5

1

Cycle

s

Stages

S6

2

3

4

5

6

7

I-1

I-2 I-1

I-2 I-1

I-2 I-1

I-2 I-1

I-2 I-1

I-2

For k states and n instructions, the number of required cycles is:

k + (n – 1)

Page 8: Assembly lab lab1 - site.iugaza.edu.ps

When one of the stages requires two or more clock cycles to complete, clock cycles are again wasted

Wasted Cycles (pipelined)

• Assume that stage S4 is the execute stage that requires 2 clock cycles to complete .

• As more instructions enter the pipeline, wasted cycles occur .

• For k stages, where one stage requires 2 cycles, n instructions require k + 2n – 1 cycles .

Page 9: Assembly lab lab1 - site.iugaza.edu.ps

• A superscalar processor has multiple execution pipelines .

• The Pentium processor has two execution pipelines

Called U and V pipes .

Superscalar Architecture

• In the following, stage S4 has 2 pipelines

• Each pipeline still requires 2 cycles

• eliminates wasted cycles

• For k stages and n instructions, number of cycles = k + n

Page 10: Assembly lab lab1 - site.iugaza.edu.ps

Accessing Parts of Registers

• Use 8-bit name, 16-bit name, or 32-bit name

• Applies to EAX, EBX, ECX, and EDX

AH AL

16 bits

8

AX

EAX

8

32 bits

8 bits + 8 bits

Page 11: Assembly lab lab1 - site.iugaza.edu.ps

Some Specialized Register Uses

General-Purpose • EAX – accumulator

• ECX – loop counter

• ESP – stack pointer

• ESI, EDI – index registers

• EBP – extended frame pointer

Segment • CS – code segment

• DS – data segment

• SS – stack segment

• ES, FS, GS - additional segments

Page 12: Assembly lab lab1 - site.iugaza.edu.ps

EIP – instruction pointer

EFLAGS

• status and control flags

• each flag is a single binary bit

Some Specialized Register Uses

Page 13: Assembly lab lab1 - site.iugaza.edu.ps

Status Flags

Carry • unsigned arithmetic out of range

Overflow • signed arithmetic out of range

Sign • result is negative

Zero • result is zero

Auxiliary Carry • carry from bit 3 to bit 4

Parity • sum of 1 bits is an even number

Page 14: Assembly lab lab1 - site.iugaza.edu.ps

Addressable Memory

Protected mode

• 4 GB

• 32-bit address

Real-address and Virtual-8086 modes

• 1 MB space

• 20-bit address

Page 15: Assembly lab lab1 - site.iugaza.edu.ps

Real-Address mode

• 1 MB RAM maximum addressable

• Application programs can access any area of memory

• Single tasking

• Supported by MS-DOS operating system

Page 16: Assembly lab lab1 - site.iugaza.edu.ps

Segmented Memory

Segmented memory addressing: absolute (linear) address is a combination of a 16-bit segment value added to a 16-bit offset

00000

10000

20000

30000

40000

50000

60000

70000

80000

90000

A0000

B0000

C0000

D0000

E0000

F0000

8000:0000

8000:FFFF

seg ofs

8000:0250

0250

one segment

Page 17: Assembly lab lab1 - site.iugaza.edu.ps

Calculating Linear Addresses

Given a segment address, multiply it by 16 (add a hexadecimal zero), and add it to the offset

Example: convert 08F1:0100 to a linear address

Adjusted Segment value: 0 8 F 1 0

Add the offset: 0 1 0 0

Linear address: 0 9 0 1 0