BIC 10503: COMPUTER ARCHITECTURE

Slides:



Advertisements
Similar presentations
Instruction Set Design
Advertisements

There are two types of addressing schemes:
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#4)
Instruction Set Architecture & Design
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
CH11 Instruction Sets: Addressing Modes and Formats
What is an instruction set?
Processor Organization and Architecture Module III.
Machine Instruction Characteristics
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CS-334: Computer.
Homework Problems 1. M1 runs the program P in 1.4 * 9 * ns or ns M2 runs the program P in 1.6*9800*10ns or ns Hence M2 is faster by.
INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Module 3 Instruction Set Architecture (ISA): ISA Level Elements of Instructions Instructions Types Number of Addresses Registers Types of Operands.
Computer Architecture and Organization
Computer Architecture EKT 422
Computer Organization
ECEG-3202 Computer Architecture and Organization Chapter 6 Instruction Sets: Addressing Modes and Formats.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
WEEK 3 I/O Port Programming ET2640 Microprocessors and Microcontrollers.
What is a program? A sequence of steps
Ass. Prof. Dr Masri Ayob TK 2123 Lecture 14: Instruction Set Architecture Level (Level 2)
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
Instruction Sets: Characteristics and Functions  Software and Hardware interface Machine Instruction Characteristics Types of Operands Types of Operations.
Intel MP Organization. Registers - storage locations found inside the processor for temporary storage of data 1- Data Registers (16-bit) AX, BX, CX, DX.
Computer Architecture. Instruction Set “The collection of different instructions that the processor can execute it”. Usually represented by assembly codes,
Assembly language programming
Displacement (Indexed) Stack
Homework Reading Lab with your assigned section starts next week
Instruction set Architecture
Overview of Instruction Set Architectures
William Stallings Computer Organization and Architecture 6th Edition
Format of Assembly language
Introduction to 8086 Microprocessor
8086 Microprocessor.
Computer Organization & Assembly Language Chapter 3
Architecture Review Instruction Set Architecture
Alvaro Mauricio Peña Dariusz Niworowski Frank Rodriguez
William Stallings Computer Organization and Architecture 8th Edition
Homework Reading Continue work on mp1
Computer Organization and Assembly Language (COAL)
Processor Organization and Architecture
Symbolic Instruction and Addressing
Introduction to Assembly Language
Data Addressing Modes • MOV AX,BX; This instruction transfers the word contents of the source-register(BX) into the destination register(AX). • The source.
Central Processing Unit
Computer Organization and ASSEMBLY LANGUAGE
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
CS 301 Fall 2002 Computer Organization
Processor Organization and Architecture
ECEG-3202 Computer Architecture and Organization
ECEG-3202 Computer Architecture and Organization
Symbolic Instruction and Addressing
Chapter 9 Instruction Sets: Characteristics and Functions
Computer Architecture
ECEG-3202 Computer Architecture and Organization
Computer Architecture CST 250
Chapter 6 –Symbolic Instruction and Addressing
Process.
William Stallings Computer Organization and Architecture 8 th Edition Chapter 11 Instruction Sets: Addressing Modes and Formats.
COMPUTER ORGANIZATION AND ARCHITECTURE
Chapter 10 Instruction Sets: Characteristics and Functions
Presentation transcript:

BIC 10503: COMPUTER ARCHITECTURE Chapter 6 Instruction Sets

Overview 6.1 Characteristics and Functions 6.2 Addressing Modes and Formats 6.3 Assembly Language Programming

6.1 Characteristics and Functions

What is an Instruction Set? The collection of different instructions that the processor can execute is referred to as the processor’s instruction set The operation of the processor is determined by the instructions it executes, referred to as machine instructions or computer instructions Each instruction must contain the information required by the processor for execution 2

Elements of an Instruction Operation code (Op code) Specifies the operation to be performed (LOAD,ADD) Source Operand reference Source for the operation Result Operand reference Source to store the result Next Instruction Reference Tells the processor where to fetch next instruction 3

Instruction Cycle State Diagram

Instruction Representation In machine code each instruction has a unique bit pattern Each unique bit pattern has a symbolic representation to ease programmers in reading/writing codes: e.g. ADD, SUB, LOAD These representation is also called as assembly code Operation Code are normally followed by Operands :- e.g. ADD A,B 5

Simple Instruction Format

Some of the most commonly used:- Opcodes Also called mnemonics Some of the most commonly used:- ADD – add SUB – subtract MUL – multiply DIV – divide LOAD – load data from memory STOR – store data to memory MOV – move data * operand can also be represented symbolically

Number of Addresses (a) Result, Operand 1, Operand 2 a = b + c; May be a forth - next instruction (usually implicit) Not common Needs very long words to hold everything 7

Number of Addresses (b) One address act as operand and result a = a + b Reduces length of instruction Requires some extra work Temporary storage to hold some results 8

Number of Addresses (c) Implicit second address Usually a register (AC) Common on early machines 9

How Many Addresses? More addresses Fewer addresses Pro: Cons: Fewer instructions per program Cons: More complex instructions More registers Fewer addresses Less complex instructions Faster fetch/execution of instructions More instructions per program 11

Types of Operand Addresses Numbers Characters Logical Data Integer/floating point Characters ASCII etc. Logical Data AND NEG NOT OR 14

Data storage (main memory) Data movement (I/O) Instruction Types Data processing Data can be processed by using Arithmetic and Logic instructions, e.g. ADD Data storage (main memory) Data can be stored to/from memory/registers Data movement (I/O) I/O instructions are meant to move data and instructions to/from external devices Program flow control Test and Branch instructions are used to control program flow 6

Types of Operation Transfer of Control I/O Data Transfer Arithmetic Logical Conversion Data Processing Data Storage Program Flow Control Data Movement 18

Types of Operation 1. Arithmetic 20

Types of Operation 2. Logical 21

Types of Operation 3. Conversion 21

Types of Operation 4. Data Transfer 19

Types of Operation 5. Input/Output 23

Types of Operation 6. Transfer of Control 25

6.2 Addressing Modes and Formats

The operand of an instruction is representing either: Addressing Modes The operand of an instruction is representing either: The actual memory address of the operand, OR A pointer to a physical memory address, OR Other representation. Addressing modes allow us to specify where the operands are located. 2

Addressing Modes Seven most basic Addressing Modes:- Immediate Direct Indirect Register Register Indirect Displacement (Indexed) Stack Notation used: A = contents of an address field in the instruction R = contents of an address field in the instruction that refers to a register 2

Addressing Modes 1. Immediate Addressing Operand is part of instruction Operand value stored in address field Operand = A e.g. ADD 5 Add 5 to contents of accumulator 5 is operand No memory reference to fetch data Fast Limited range 3

Immediate Addressing Diagram Instruction Opcode Operand 4

Addressing Modes 2. Direct Addressing Address field contains address of operand Effective address (EA) in address field EA = A e.g. LDA 100b Look in memory at address 100b for operand Copy/load contents of memory address 100b to accumulator Single memory reference to access data No additional calculations to work out effective address Limited address space 5

Direct Addressing Diagram Instruction Opcode Address A Memory Operand 6

Addressing Modes 3. Indirect Addressing Memory cell pointed to by address field contains the address of (pointer to) the operand EA = (A) Look in A, find address (A) and look there for operand e.g. ADD (M) Add contents of cell pointed to by contents of M to accumulator 7

Indirect Addressing (cont.) Large address space May be nested e.g. EA = (((A))) Multiple memory accesses to find operand Hence slower 8

Indirect Addressing Diagram Instruction Opcode Address A Memory Pointer to operand Operand 9

Addressing Modes 4. Register Addressing Operand is held in register named in address filed EA = R Limited number of registers Shorter instructions Faster instruction fetch 10

Register Addressing (cont.) No memory access Very fast execution Very limited address space Multiple registers helps performance Requires good assembly programming or compiler writing 11

Register Addressing Diagram Instruction Opcode Register Address R Registers Operand 12

Addressing Modes 5. Register Indirect Addressing EA = (R) Operand is in memory cell pointed to by contents of register R 13

Register Indirect Addressing Diagram Instruction Opcode Register Address R Memory Registers Pointer to Operand Operand 14

Addressing Modes 6. Displacement Addressing EA = A + (R) Address field hold two values A = base value R = register that holds displacement or vice versa 15

Displacement Addressing Diagram Instruction Opcode Register R Address A Memory Registers Pointer to Operand + Operand 16

Addressing Modes 7. Stack EA = top of stack e.g. POP AX ;Pop top item from stack and load into register AX 15

Stack Addressing Diagram Instruction Implicit Top of stack register 12

Addressing Modes Summary

6.3 Assembly Language Programming

Assembly Language Assembly Language Assembler A symbolic representation of the machine language of a specific processor. Augmented by additional types of statements that facilitate program writing and that provide instructions to the assembler. Assembler A program that translates assembly code into machine code.

Assembly Language Statement Structure Example 1 (without label): ADD R1, 5 ; R1 = R1 + 5 mnemonic operands comment Example 2 (with label): MYLABEL: INC R1 ; increment R1 label mnemonic operands comment

Programming Language Learning any programming language involves mastering a number of common concepts: Variables: Declaration/definition Assignment: Assigning values to variables Input/Output: Displaying messages/displaying variable values Control flow: Loops, JUMPs Subprograms: Definition and Usage Programming in assembly language involves mastering the same concepts and a few other issues.

Registers have predefined names and do not need to be declared. Variables Here we will simply use the x86 registers’ name as the variables in our programs. Registers have predefined names and do not need to be declared.

Registers 1. 8-bit general registers: AL, BL, CL, DL, AH, BH, CH, DH 2. 16- bit general registers: AX, BX, CX, DX, SP, BP, SI, Dl 3. 32-bit general registers: EAX ; Accumulator EBX ; Base ECX ; Counter EDX ; Data ESP ; Stack pointer EBP ; Base pointer ESI ; Source index EDI ; Destination Index

Registers Each of the registers is 8/16/32 bits long i.e. can contain a 8/16/32-bit binary number. The main four registers are sometimes referred to as data registers. They are the AX, BX, CX and DX registers. The data registers can be treated as 16-bit registers or they can each be treated as two 8-bit registers. Each 8-bit register can be used independently.

Registers The AX register may be accessed as ah and al (H and L refer to high-order and low-order bytes). BX may be accessed as BH, BL CX may be accessed as CH, CL DX may be accessed as DH, DL If you use a data register as an 8 bit register, you cannot use its 16 bit parent at the same time.

Assignment In programming languages such as C/C++/Java, assignment takes the form: x = 42 ; y = 24; z = x + y; In assembly language we carry out the same operation but we use an instruction to denote the assignment operator (“=”). The above assignments would be carried out in x86 assembly language as follows: MOV AX, 42 ADD AX, 24 MOV BX,AX

The MOV instruction carries out assignment. Assignment (cont.) The MOV instruction carries out assignment. It allows us place a number in a register or in a memory location (a variable) i.e. it assigns a value to a register or a variable. e.g. MOV BX, ‘A’ ; To store the ASCII code for the letter A in register BX. MOV BX, 2 ;set the value 2 into BX

Input/Output In assembly language we must have a mechanism to call the operating system subprogram to carry out I/O. In addition we must be able to tell the operating system what kind of I/O operation we wish to carry out, e.g. to read a character from the keyboard, to display a character or string on the screen, etc…...

In x86 assembly language, we do not call operating system subprograms by name, instead, we use a software interrupt mechanism The x86 INT instruction generates a software interrupt. It uses a single operand which is a number indicating which MS-DOS subprogram is to be invoked. For I/O, the number used is 21h. Thus, the instruction INT 21h transfers control to the operating system, to a subprogram that handles I/O operations. This subprogram handles a variety of I/O operations by calling appropriate subprograms. This means that you must also specify which I/O operation (e.g. read a character, display a character) you wish to carry out. This is done by placing a specific number in a specific register.

The AH register is used to pass this information. For example, the subprogram to display a character is subprogram number 2h. This number must be stored in the AH register. When the I/O operation is finished, the interrupt service program terminates and our program will be resumed.

Character Output There are three elements involved in carrying out this operation using the INT instruction: We specify the character to be displayed. This is done by storing the character’s ASCII code in a specific x86 register. In this case we use the DL register, i.e. we use DL to pass a parameter to the output subprogram. We specify which of MS-DOS’s I/O subprograms we wish to use. The subprogram to display a character is subprogram number 2h. This number is stored in the AH register. We request MS-DOS to carry out the I/O operation using the INT instruction. This means that we interrupt our program and transfer control to the MS-DOS subprogram that we have specified using the AH register.

Character Output Example : Write a code fragment to display the character ’a’ on the screen:   MOV DL, ‘a’ ; DL = ‘a’ MOV AH, 2h ; 2h is a subprogram to display character INT 21h ; call ms-dos, output character

Character Input There are also three elements involved in performing character input: As for character output, we specify which of MS-DOS’s I/O subprograms we wish to use, i.e. the character input from the keyboard subprogram. This is MS-DOS subprogram number 1h. This number must be stored in the AH register. We call MS-DOS to carry out the I/O operation using the INT instruction. The MS-DOS subprogram uses the AL register to store the character it reads from the keyboard.

Example: Write a code fragment to read a character from the keyboard Character Input Example: Write a code fragment to read a character from the keyboard MOV AH, 1h ; keyboard input subprogram INT 21h ; character input ; character is stored in AL

Example: Reading and displaying a character: Character Input Example: Reading and displaying a character: MOV AH, 1h ; 1h is keyboard input subprogram INT 21h ; read character into AL MOV DL, AL ; copy character to DL MOV AH, 2h ; 2h is character output subprogram ; display character in dl

Reference List of Intel x86 most basic instructions http://www.jegerlehner.ch/intel/IntelCodeTable.pdf

THANK YOU