61
Processor Architecture And Interfacing

Pai unit 1_l1-l2-l3-l4_upload

Embed Size (px)

Citation preview

Page 1: Pai unit 1_l1-l2-l3-l4_upload

Processor Architecture And Interfacing

Page 2: Pai unit 1_l1-l2-l3-l4_upload

UNIT-1

Introduction to Assembly Language Programming and 80386 Processors

Page 3: Pai unit 1_l1-l2-l3-l4_upload

Computer organization How operational attributes are linked together and contribute to realize the architectural specifications. Deals with all physical components of computer systems that interacts with each other to perform various functionalities.

Computer architecture Decides architectural attributes of a hardware components needed to form a relationship with other hardware component to form a functional system.

Computer architecture comes before computer organization

Architectural attributes - instruction set, word length, techniques for addressing memories

Design and architecture of house - decides specifications Organization - building the house by bricks or by latest technology

Page 4: Pai unit 1_l1-l2-l3-l4_upload
Page 5: Pai unit 1_l1-l2-l3-l4_upload

Software Abstraction

Page 6: Pai unit 1_l1-l2-l3-l4_upload

Hardware Abstraction

Page 7: Pai unit 1_l1-l2-l3-l4_upload
Page 8: Pai unit 1_l1-l2-l3-l4_upload

Hardware / Software Interface

Page 9: Pai unit 1_l1-l2-l3-l4_upload

Abstract CPU Architecture

Page 10: Pai unit 1_l1-l2-l3-l4_upload

Functional Blocks of a CPU

Page 11: Pai unit 1_l1-l2-l3-l4_upload

A microprocessor -- also known as a CPU or central processing unit -- is a complete

computation engine that is fabricated on a single chip.

A microprocessor incorporates the functions of a computer's central processing unit

(CPU) on a single integrated circuit (IC) or at most a few integrated circuits

Three basic characteristics differentiate microprocessors:

• Instruction set: The set of instructions that the microprocessor can execute.

• bandwidth : The number of bits processed in a single instruction.

• clock speed : Given in megahertz (MHz), the clock speed determines how many

instructions per second the processor can execute.

Central Hardware - A Microprocessor

Page 12: Pai unit 1_l1-l2-l3-l4_upload

What’s difference between processors ?

Page 13: Pai unit 1_l1-l2-l3-l4_upload

Development of Intel processor  (i) 8088

– Has 16-bit registers and 8-bit data bus– 20 bit address bus - address up to 1 MB of

internal memory– Although registers can store up to 16-bits at a

time but the data bus is only able to transfer 8 bit data at one time

(ii) 8086– Is similar to 8088 but has a 16-bit data

bus and runs faster. – 20 bit address bus - address up to 1 MB of

internal memory

What’s difference between INTEL processors ?

Page 14: Pai unit 1_l1-l2-l3-l4_upload

(iii) 80286– Runs faster than 8086 and 8088– Can address up to 16 MB of internal memory

( 24 bit address)– multitasking => more than 1 task can be ran simultaneously

(iv) 80386– has 32-bit registers and 32-bit data bus– can address up to 4 billion bytes. of memory (4

GB)– support “virtual mode”, whereby it can swap

portions of memory onto disk: in this way, programs running concurrently have space to operate.

(v) 80486– has 32-bit registers and 32-bit data bus– the presence of CACHE

Page 15: Pai unit 1_l1-l2-l3-l4_upload

(vi) Pentium– has 32-bit registers, 64-bit data bus– has separate caches for data and

instruction – the processor can decode and execute more

than one– instruction in one clock cycle (pipeline)

 (vii) Pentium II & III

– has different paths to the cache and main memory

Page 16: Pai unit 1_l1-l2-l3-l4_upload

8086 Architecture

Page 17: Pai unit 1_l1-l2-l3-l4_upload

8086 Registers

Page 18: Pai unit 1_l1-l2-l3-l4_upload
Page 19: Pai unit 1_l1-l2-l3-l4_upload

Processor (CPU) is partitioned into two logical units:   1) An Execution Unit (EU) 2) A Bus Interface Unit (BIU)

EU– EU is responsible for program execution – Contains of an Arithmetic Logic Unit (ALU), a Control Unit

(CU) and a number of registers

BIU– Delivers data and instructions to the EU.– manage the bus control unit, segment registers and

instruction queue.– The BIU controls the buses that transfer the data to the EU, to

memory and to external input/output devices, whereas the segment registers control memory addressing.

8086 Architecture

Page 20: Pai unit 1_l1-l2-l3-l4_upload

EU and BIU work in parallel, with the BIU keeping one step ahead. The EU will notify the BIU when it needs to data in memory or an I/O device or obtain instruction from the BIU instruction queue.

 When EU executes an instruction, BIU

will fetch the next instruction from the memory and insert it into to instruction queue.

8086 Architecture

Page 21: Pai unit 1_l1-l2-l3-l4_upload

AH AL BH BL CH CL DH DL SP BP SI DI

AX

CXDX

BX

EU : Execution Unit BIU : Bus Interface Unit

CS

Program Control

DS SS ES

ALUCU

Flag register

123

Bus Control Unit

4

n

Bus

Instruction Pointer

Instruction Queue

(Program Counter)

8086 Architecture

Page 22: Pai unit 1_l1-l2-l3-l4_upload

Addressing Data in Memory

•  Intel Personal Computer (PC) addresses its memory according to bytes. (Every byte has a unique address beginning with 0)

• Depending on the model of a PC, CPU can access 1 or more bytes at a time

• Processor (CPU) keeps data in memory in reverse byte sequence (reverse-byte sequence: low order byte in the low memory address and high-order byte in the high memory address)

Page 23: Pai unit 1_l1-l2-l3-l4_upload

Example : consider value 052916 (0529H)

register

  memory

• When the processor takes data (a word or 2 bytes), it will re-reverse the byte to its actual order 052916

05 29

29 05

Address 04A2616

(low-order/least significant byte)Address 04A2716

(high-order/most significant byte)

2 bytes 05 and 29

Page 24: Pai unit 1_l1-l2-l3-l4_upload

Segment And Addressing

• Segments are special areas in the memory that is defined in a program, containing the code, data, and stack.

• The segment position in the memory is not fixed and can not be determined by the programmer

• 3 main segments for the programming process:

(i)  Code Segment (CS)• Contains the machine instructions that are to

execute.• Typically, the first executable instruction is at

the start of this segment, and the operating system links to that location to begin program execution.

• CS register will hold the beginning address of this segment 

Page 25: Pai unit 1_l1-l2-l3-l4_upload

(ii) Data Segment (DS)• Contains program’s defined data, constants

and working areas.• DS register is used to store the starting

address of the DS

(iii) Stack Segment (SS)• Contains any data or address that the

program needs to save temporarily or for used by your own “called” subroutines.

• SS register is used to hold the starting address of this segment

Page 26: Pai unit 1_l1-l2-l3-l4_upload

Address

Address

Address

Stack segment

Data segment

Code segment

Contains the beginning address of each segment

Segment register (in CPU)

memory(MM)

SS Register

DS Register

CS Register

Page 27: Pai unit 1_l1-l2-l3-l4_upload

Stack segment

Data segment

Code segment

Contains the beginning address of each segment

Segment register (in CPU)

memory(MM)

SS Register

DS Register

CS Register

035F0

01300

02ED0

035F

02ED

0130

Page 28: Pai unit 1_l1-l2-l3-l4_upload

Segment Offsets

• Within a program, all memory locations within a segment are relative to the segment’s starting address.

• The distance in bytes from the segment address to another location within the segment is expressed as an offset (or displacement).

• Thus the first byte of the code segment is at offset 00, the second byte is at offset 01 and so forth.

• To reference any memory location in a segment (the actual address), the processor combines the segment address in a segment register with the offset value of that location. actual address = segment address + offset

Page 29: Pai unit 1_l1-l2-l3-l4_upload

Eg: A starting address of data segment is 038E0,

so the value in DS register is 038E. An instruction references a location with an offset of 0032H bytes from the start of the data segment.

  the actual address = DS segment address

(0) + offset = 038E(0) + 0032H = 03912H

Ex. IF CS = 04F0 find physical address of data (a) at an offset 3BE0 (b) F3C8 in the code segment

Page 30: Pai unit 1_l1-l2-l3-l4_upload

Registers

• Registers are used to control instructions being executed, to handle addressing of memory, and to provide arithmetic capability

• Registers of Intel Processors can be categorized into:

1. Segment register2. Pointer register3. General purpose register4. Index register5. Flag register

Page 31: Pai unit 1_l1-l2-l3-l4_upload

i) Segment register

There are 6 segment registers : 

(a)CS register• Contains the starting address of program’s code

segment.• The content of the CS register is added with the

content in the Instruction Pointer (IP) register to obtain the address of the instruction that is to be fetched for execution.

 (Note: common name for IP is PC (Program Counter)) 

(b) DS register• Contains the starting address of a program’s data

segment. • The address in DS register will be added with the

value in the address field (in instruction format) to obtain the real address of the data in data segment.

Page 32: Pai unit 1_l1-l2-l3-l4_upload

(c) SS Register• Contains the starting address of the

stack segment.• The content in this register will be added

with the content in the Stack Pointer (SP) register to obtain the required word.

(d)ES (Extra Segment) Register• Used by some string (character data)

operations to handle memory addressing• ES register is associated with the Data

Index (DI) register. 

(e) FS and GS Registers• Additional extra segment registers

introduced in 80386 for handling storage requirement.

Page 33: Pai unit 1_l1-l2-l3-l4_upload

(ii) Pointer Registers

• There are 3 pointer registers in an Intel PC :

 (a)Instruction Pointer register• The 16-bit IP register contains the

offset address or displacement for the next instruction that will be executed by the CPU

• The value in the IP register will be added into the value in the CS register to obtain the real address of an instruction

Page 34: Pai unit 1_l1-l2-l3-l4_upload

Example :  The content in CS register = 39B40H The content in IP register =

514H next instruction address:

39B40H + 514H . 3A054H

•  Intel 80386 introduced 32-bit IP, known as EIP (Extended IP)

Page 35: Pai unit 1_l1-l2-l3-l4_upload

(b) Stack Pointer Register (Stack Pointer (SP))

• The 16-bit SP register stores the displacement value that will be combined with the value in the SS register to obtain the required word in the stack

• Intel 80386 introduced 32-bit SP, known as ESP (Extended SP)

Example:Value in register SS = 4BB30HValue in register SP = + 412H

4BF42H(c) Base Pointer Register • The 16-bit BP register facilitates referencing

parameters, which are data and addresses that a program passes via a stack

• The processor combines the address in SS with the offset in BP

Page 36: Pai unit 1_l1-l2-l3-l4_upload

(iii) General Purpose RegistersThere are 4 general-purpose registers, AX, BX, CX, DX: (a) AX register• Acts as the accumulator and is used in operations that

involve input/output and arithmetic • The diagram below shows the AX register with the number

of bits.

 

8 bit 8 bit

32 bits

AH AL

AX

EAX

EAX : 32 bitAX : 16 bit (rightmost 16-bit portion of EAX)AH : 8 bit => leftmost 8 bits of AX (high portion)AL : 8 bit => rightmost 8 bit of AX (low portion)

Page 37: Pai unit 1_l1-l2-l3-l4_upload

(b) BX Registero  Known as the base register since it is the only this

general purpose register that can be used as an index to extend addressing.

o  This register also can be used for computations o  BX can also be combined with DI and SI register as

a base registers for special addressing  like AX, BX is also consists of EBX, BH and BL

8 bit 8 bit

32 bits

BX

EBX

BH BL

Page 38: Pai unit 1_l1-l2-l3-l4_upload

(c) CX Register

• known as count register• may contain a value to control the number of times a loops is repeated

or a value to shift bits left or right • CX can also be used for many computations • Number of bits and fractions of the register is like below :

8 bit 8 bit

32 bits

CX

CH CL

ECX

Page 39: Pai unit 1_l1-l2-l3-l4_upload

(d) DX Register• Known as data register• Some I/O operations require its use • Multiply and divide operations that involve large

values assume the use of DX and AX together as a pair to hold the data or result of operation.

• Number of bits and the fractions of the register is as below :

8 bit 8 bit

32 bits

DX

DH DL

EDX

Page 40: Pai unit 1_l1-l2-l3-l4_upload

(iv) Index RegisterThere are 2 index registers, SI and DI

 (a) SI Register

o  Needed in operations that involve string (character) and is always usually associated with the DS register o   SI : 16 bito   ESI : 32 bit (80286 and above)

 (b) DI Register

o  Also used in operations that involve string (character) and it is associated with the ES register o  DI : 16 bito  EDI : 32 bit (80386 and above)

Page 41: Pai unit 1_l1-l2-l3-l4_upload

(v) FLAG Registero   Flags register contains bits that show the status of some activities o   Instructions that involve comparison and arithmetic will change the flag status where some instruction will refer to the value of a specific bit in the flag for next subsequent action

- 9 of its 16 bits indicate the current status of the computer and the results of processing - the above diagram shows the stated 9 bits

O D I T S Z A P C

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

Page 42: Pai unit 1_l1-l2-l3-l4_upload

O D I T S Z A P C

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

OF (overflow): indicate overflow of a high-order (leftmost) bit following arithmeticDF (direction): Determines left or right direction for moving or comparing string (character) data IF (interrupt): indicates that all external interrupts such as keyboard entry are to be processed or ignoredTF (trap): permits operation of the processor in single-step mode. Usually used in “debugging” processSF (sign): contains the resulting sign of an arithmetic operation (0 = +ve, 1 = -ve) ZF (zero): indicates the result of an arithmetic or comparison operation (0 = non zero; 1 = zero result)AF (auxillary carry): contains a carry out of bit 3 into bit 4 in an arithmetic operation, for specialized arithmeticPF (parity): indicates the number of 1-bits that result from an operation. An even number of bits causes so-called even parity and an odd number causes odd parityCF (parity): contains carries from a high-order (leftmost) bit following an arithmetic operation; also, contains the content of the last bit of a shift or rotate operation.

Page 43: Pai unit 1_l1-l2-l3-l4_upload

Levels of Programming Languages 1) Machine Language

– Consists of individual instructions that will be executed by the CPU one at a time

 2) Assembly Language (Low Level Language)– Designed for a specific family of processors (different

processor groups/family has different Assembly Language) – Consists of symbolic instructions directly related to machine

language instructions one-for-one and are assembled into machine language.

3) High Level Languages– e.g. : C, C++ and Vbasic– Designed to eliminate the technicalities of a particular

computer.– Statements compiled in a high level language typically

generate many low-level instructions.

Introduction to assembly language programming

Page 44: Pai unit 1_l1-l2-l3-l4_upload

Reasons for using Assembly Language

1. A program written in Assembly Language requires considerably less memory and execution time than one written in a high –level language.

2. Assembly Language gives a programmer the ability to perform highly technical tasks that would be difficult, if not impossible in a high-level language.

3. Although most software specialists develop new applications in high-level languages, which are easier to write and maintain, a common practice is to recode in assembly language those sections that are time-critical.

4. Resident programs (that reside in memory while other program execute) and interrupt service routines (that handle input and output) are almost always develop in Assembly Language.

Page 45: Pai unit 1_l1-l2-l3-l4_upload

Assembly Language

• Program implemented directly on the physical CPU

• Is not portable between various families of processors

• It gives programmers the insight required to write effective code in high-level

Basic • Every computer - has at its heart exactly two things: a CPU and some memory

• Computer program is nothing more than a collection of binary codes in memory.

• Different numbers tell the CPU to do different things.

• The CPU reads the op-code one at a time, decodes them, and does what the numbers say. opcode 64 - means add 1 to AX. opcode 8E- swap numbers stored in AX with BX.

• 184, 0, 184, 142, 216, 198, 6, 158, 15, 36, 205, 32. ( Display $ )

648E

Page 46: Pai unit 1_l1-l2-l3-l4_upload

Assembly Language

• Op codes are not understood by human.

• Programs could be written using words instead of numbers is assembly language

• A special program called an assembler would then take the programmer's words

and convert them to numbers that the computer could understand.

The program above, written in assembly language, looks like this:

MOV AX, 47104 MOV DS, AX MOV [3998], 36 INT 32

• Assembler converts each line of code into CPU-level instruction• INT instruction transfers processor control to the device drivers or operating system.

Page 47: Pai unit 1_l1-l2-l3-l4_upload

Assembly Language

• Registers used to store numbers

• DS happens to be a segment register and is used to pick which area of memory the CPU can write to

• In our program, we put the number 47104 into DS, which tells the CPU to access the memory on the video card.

• Put the number 36 ($) into location 3998 of the video card's memory

• 3998 is the memory location of the bottom right hand corner of the screen, a dollar sign shows up on the screen a few microseconds later.

• An interrupt is used to stop one program and execute another in its place.

• In our case, we want interrupt 32, which ends our program and goes back to MS-DOS, or whatever other program was used to start our program

Page 48: Pai unit 1_l1-l2-l3-l4_upload

Assembly Language

• Running the Program• Next, click on your start menu, and run the program called MS-DOS Prompt• Type DEBUG and press enter • You will see the Debug prompt, which is a simple dash.• We are now in a program called Debug. Debug is a powerful utility that lets you

directly access the registers and memory of your computer for various purposes. • Debug's a command is for assemble. • You will see something like 1073:0100. • This is the memory location we are going to enter assembly language

instructions at. • The first number is the segment, and the second number is the memory location

within the segment (offset)• Debug only understands hexadecimal numbers, • Enter our program now. Type each of the instructions - when you finish entering the last

instruction, press enter twice mov ax,B800movds,axmov byte[0F9E],24int 20

Page 49: Pai unit 1_l1-l2-l3-l4_upload

Assembly Language

• Once you have entered the program, you can go ahead and run it.

• Simply type g for go and press enter when you are ready to start the program.

• You should see a dollar sign in the lower right hand corner of your screen

• These words are put out by Debug to let you know that the program ended normally

• Go ahead and type q to get out of Debug

• Now, type exit to get out of MS-DOS. You should now be back in Windows

Page 50: Pai unit 1_l1-l2-l3-l4_upload
Page 51: Pai unit 1_l1-l2-l3-l4_upload

Assembly Language Program Development Steps

1. Analyze the problem

2. Create source program ----------- Use Editor ---------- test.asm

3. Assemble the source file ----- Use Assembler ------ test.obj , test.lst

4. Link the object file ---- Use Linker ----- test.exe , test. Map

5. Run the program independently or use Debugger / Emulator

Page 52: Pai unit 1_l1-l2-l3-l4_upload

Assembly Language Program Development Tools

• Editor

• Assembler

• Linker

• Loader

• Debugger

• Emulator

Page 53: Pai unit 1_l1-l2-l3-l4_upload

Editor

• Is a program that helps to create and modify contents of a file

• We can write assembly language instructions or mnemonics and store them

as a file with extension .ASM .data msg db "Hello, World!", 0Dh,0Ah, 24h

.code mov ax,@data mov ds,ax mov dx, offset msg mov ah, 09h int 21h

mov ah, 0 int 16h

Hello.asm

Page 54: Pai unit 1_l1-l2-l3-l4_upload

The Assembler• Translates the mnemonics into binary machine code • WE will use TASM or MASM

- Finds displacement (offset) of data and labels and puts this into symbol table - Inserts these offsets into the translated binary code

- Pseudo Instructions are special commands to the assembler about the positioning of the program, the address the program should presumed to be assembled at,

Command : TASM /l hello.asm

Page 55: Pai unit 1_l1-l2-l3-l4_upload

Hello.lst file

Page 56: Pai unit 1_l1-l2-l3-l4_upload

-- Produces binary codes for the combined module.

-- Also produces a map file having addresses of all linked files

-- Linker does not assign absolute address -- only relative address from 0000

hence the program is relocatable code

Page 57: Pai unit 1_l1-l2-l3-l4_upload
Page 58: Pai unit 1_l1-l2-l3-l4_upload
Page 59: Pai unit 1_l1-l2-l3-l4_upload

Debugger

The Assembly Language Debugger is a tool for debugging executable programs at the assembly level.

Debugger loads the object code into system memory (RAM) Execute and debug the program

Features - Step into / Step over - to see register and memory contents - Breakpoints - Easy memory manipulation - Disassembler for intel x86 instructions - Easy register manipulation

Page 60: Pai unit 1_l1-l2-l3-l4_upload

Debugger

The Assembly Language Debugger is a tool for debugging executable programs at the assembly level.

Debugger loads the object code into system memory (RAM) Execute and debug the program

Features - Step into / Step over - to see register and memory contents - Breakpoints - Easy memory manipulation - Disassembler for intel x86 instructions - Easy register manipulation

Page 61: Pai unit 1_l1-l2-l3-l4_upload

Emulator

• emulator is hardware or software or both that duplicates (or emulates) the functions

of one computer system (the guest) in another computer system (the host)

• emulated behavior closely resembles the behavior of the real system (the guest)

• exact reproduction of behavior as against simulation

• Used to test and debug hardware of an external system

• Host is connected to guest by cable

• Then the object code is downloaded into the guest’s memory for execution

• All features of debugger are present in the emulator

• The only difference is that emulator gets the status of all memory locations

and registers from the external hardware.

• This traced data can be analyzed to find errors