Presentation is loading. Please wait.

Presentation is loading. Please wait.

BIC 10503: COMPUTER ARCHITECTURE

Similar presentations


Presentation on theme: "BIC 10503: COMPUTER ARCHITECTURE"— Presentation transcript:

1 BIC 10503: COMPUTER ARCHITECTURE
Chapter 6 Instruction Sets

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

3 6.1 Characteristics and Functions

4 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

5 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

6 Instruction Cycle State Diagram

7 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

8 Simple Instruction Format

9 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

10 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

11 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

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

13 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

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

15 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

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

17 Types of Operation 1. Arithmetic
20

18 Types of Operation 2. Logical
21

19 Types of Operation 3. Conversion
21

20 Types of Operation 4. Data Transfer
19

21 Types of Operation 5. Input/Output
23

22 Types of Operation 6. Transfer of Control
25

23 6.2 Addressing Modes and Formats

24 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

25 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

26 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

27 Immediate Addressing Diagram
Instruction Opcode Operand 4

28 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

29 Direct Addressing Diagram
Instruction Opcode Address A Memory Operand 6

30 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

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

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

33 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

34 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

35 Register Addressing Diagram
Instruction Opcode Register Address R Registers Operand 12

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

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

38 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

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

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

41 Stack Addressing Diagram
Instruction Implicit Top of stack register 12

42 Addressing Modes Summary

43 6.3 Assembly Language Programming

44 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.

45 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

46 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.

47 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.

48 Registers 1. 8-bit general registers: AL, BL, CL, DL, AH, BH, CH, DH
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

49 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.

50 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.

51 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

52 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

53 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…...

54 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.

55 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.

56 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.

57 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

58 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.

59 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

60 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

61 Reference List of Intel x86 most basic instructions

62 THANK YOU


Download ppt "BIC 10503: COMPUTER ARCHITECTURE"

Similar presentations


Ads by Google