Chap 3
Chap 3
Architecture
Chapter three
1
contents.
3.1. Basic organization of the von Neumann machine
3.2. Control unit; instruction fetch, decode, and execution
3.3. Instruction sets and types (data manipulation, control, I/O)
3.4. Assembly/machine language programming
3.5. Instruction formats
3.6. Addressing modes
3.7. Subroutine call and return mechanisms
3.8. I/O and interrupts
2
3.1 Basic organization of the von Neumann machine
• The invention of stored program computers has been
ascribed to a mathematician, John von Neumann.
• It was pointed out by von-Neumann that the same memory
can be used or storing data and instructions.
3
• Today’s stored-program computers have the following
characteristics:
– Three hardware systems:
• A central processing unit (CPU)
• A main memory system
• An I/O system
• The capacity to carry out sequential instruction processing.
• A single data path between the CPU and main memory.This
single path is known as the von Neumann bottleneck.(rate at
which data and program can get into the CPU is limited by the
bandwidth of the interconnect))
4
5
3.2 Control unit; instruction fetch, decode, and execution
• The control unit
– Directs the information flow through ALU by
• - Selecting various Components in the system
• - Selecting the Function of ALU
– A cycle is made of three phases: fetch, decode and execute.
• During the fetch phase, the instruction whose address is determined by
the PC is obtained from the memory and loaded into the IR. The PC is
then incremented to point to the next instruction.
• During the decode phase, the instruction in IR is decoded and the
required operands are fetched from the register or from memory.
• During the execute phase, the instruction is executed and the results
are placed in the appropriate memory location or the register.
• Once the third phase is completed, the control unit starts the cycle
again, but now the PC is pointing to the next instruction. The process
continues until the CPU reaches a HALT instruction.
6
An example
Let us show how our simple computer can add two integers A and B
and create the result as C. We assume that integers are in two’s
complement format. Mathematically, we show this operation as:
We assume that the first two integers are stored in memory locations
(40)16 and (41)16 and the result should be stored in
memory location (42)16. To do the simple addition needs five
instructions, as shown next:
Assume for the moment that we need to add 161 + 254 = 415. The
numbers are shown in memory in hexadecimal is, (00A1)16, (00FE)16,
and (019F)16.
7
these five instructions are encoded as:
8
5.8
9
10
11
12
13
3.3. Instruction sets and types (data
manipulation, control, I/O)
• What is an Instruction Set?
• The complete collection of instructions that are understood by a CPU
• Instruction Types
– Data transfer: registers, main memory, stack or I/O
– Data processing: arithmetic, logical
– Control: systems control, transfer of control
14
DATA TRANSFER INSTRUCTIONS
Name Mnemonic
Typical Data Transfer Instructions
Load LD
Store ST
Move MOV
Exchange XCH
Input IN
Output OUT
Push PUSH
Pop POP
Data Transfer Instructions with Different Addressing Modes
Some assembly language conventions modify the mnemonic symbol to
differentiate between addressing modes
LDI – load immediate
• Some use a special character to designate the mode
Assembly
Mode Convention Register Transfer
Direct address LD ADR AC M[ADR]
Indirect address LD @ADR AC M[M[ADR]]
Relative address LD $ADR AC M[PC + ADR]
Immediate operand LD #NBR AC NBR
Index addressing LD ADR(X) AC M[ADR + XR]
Register LD R1 AC R1
Register indirect LD (R1) AC M[R1]
Autoincrement LD (R1)+ AC M[R1], R1 R1 + 1 15
Autodecrement LD -(R1) R1 R1 - 1, AC M[R1]
DATA MANIPULATION INSTRUCTIONS
Three Basic Types: Arithmetic instructions
Logical and bit manipulation instructions
Shift instructions
Arithmetic Instructions
Name Mnemonic
Increment INC
Decrement DEC
Add ADD
Subtract SUB
Multiply MUL
Divide DIV
Add with Carry ADDC
Subtract with Borrow SUBB
Negate(2’s Complement) NEG
17
Cont…
+1
In-Line Sequencing
(Next instruction is fetched from the
PC next adjacent location in the memory)
19
3.4. Assembly/machine language programming
• Machine language
– Native to a processor: executed directly by hardware
– Instructions consist of binary code: 1s and 0s
• Assembly language
– Slightly higher-level language
– Readability of instructions is better than machine language
– One-to-one correspondence with machine language
instructions
• Assemblers translate assembly to machine code
• Compilers translate high-level programs to machine code
– Either directly, or
– Indirectly via an assembler
20
21
A Hierarchy of Languages
22
Translating Languages
English: D is assigned the sum of A times B plus 10.
High-Level Language: D = A * B + 10
23
Advantages of High-Level Languages
• Program development is faster
– High-level statements: fewer instructions to code
• Program maintenance is easier
– For the same above reasons
• Programs are portable
– Contain few machine-dependent details
• Can be used with little or no modifications on different
machines
– Compiler translates to the target machine language
– However, Assembly language programs are not portable
24
• Why Learn Assembly Language?
Two main reasons:
– Accessibility to system hardware
• Assembly Language is useful for implementing system software
• Also useful for small embedded system applications
– Space and Time efficiency
• Understanding sources of program inefficiency
• Tuning program performance
• Writing compact code
25
Assembler
• Software tools are needed for editing, assembling, linking,
and debugging assembly language programs
• An assembler is a program that converts source-code
programs written in assembly language into object files in
machine language
• Popular assemblers have emerged over the years for the Intel
family of processors. These include …
– TASM (Turbo Assembler from Borland)
– NASM (Netwide Assembler for both Windows and Linux),
and
– GNU assembler distributed by the free software foundation
– MASM (Macro Assembler from Microsoft)
26
• Learning assembly language programming will
help understanding the operations of the
microprocessor
• To learn:
– Need to know the functions of various registers
– Need to know how external memory is organized and
how it is addressed to obtain instructions and data
(different addressing modes)
– Need to know what operations (or the instruction
set) are supported by the CPU. For example,
powerful CPUs support floating-point operations but
simple CPUs only support integer operations
27
Example:
• The statement must specify which operation (opcode) is to be
performed and the operands
• Eg ADD AX, BX
ADD is the operation
AX is called the destination operand
BX is called the source operand
The result is AX = AX + BX
• When writing assembly language program, you need to think
in the instruction level
28
Example
• In c++, you can do A = (B+C)*100
• In assembly language, only one instruction per statement
A=B ; only one instruction - MOVE
A = A+C ; only one instruction - ADD
A = A*100 ; only one instruction - Multiply
Formats of assembly language
• General format for an assembly language statement
Label Instruction Comment
Start: Mov AX, BX ; copy BX into AX
29
• In 8086, memory is divided into segments
• Only 4 64K-byte segments are active and these are: code,
stack, data, and extra
30
• In assembly programming, you cannot operate on two
memory locations in the same instruction
• So you usually need to store (move) value of one location into
a register and then perform your operation
• After the operation, you then put the result back to the
memory location
• Therefore, one form of operation that you will use very
frequent is the store (move) operation!!!
And using registers!!!!!
• In C++ A = B+C ; A, B, C are variables
• In assembly language A,B, C representing memory locations
so you cannot do A = B+C
– MOV AL, B ; move value of B into AL register
– ADD, AL, C ; do the add AL = AL +C
– MOV A, AL ; put the result to A
31
• In general, an assembly program must include the code
segment!!
• Other segments, such as stack segment, data segment are
not compulsory
• There are key words to indicate the beginning of a segment
as well as the end of a segment. Just like using main(){} in
C++ Programming
Example
• DSEG segment ‘data’ ; define the start of a data
segment
• DSEG ENDS ; defines the end of a data segment
• Segment is the keyword DSEG is the name of the segment
• Similarly key words are used to define the beginning of a
program, as well as the end.
32
Example
CSEG segment ‘code’
START PROC FAR ; define the start of a program (procedure)
RET ; return
START ENDP ; define the end of a procedure
CSEG ends
End start ; end of everything
33
3.5 INSTRUCTION FORMAT
Instruction Fields
OP-code field - specifies the operation to be performed
Address field - designates memory address(s) or a processor register(s)
Mode field - specifies the way the operand or the
effective address is determined
The number of address fields in the instruction format
depends on the internal organization of CPU
Program to evaluate X = (A + B) * (C + D) :
ADD A, B ,R1 /* R1 M[A] + M[B] */
ADD C, D, R2 /* R2 M[C] + M[D] */
MUL R1, R2, X /* M[X] R1 * R2 */
Two-Address Instructions:
Program to evaluate X = (A + B) * (C + D) :
ITEC2021: Computer 39
Organization
TYPES OF ADDRESSING MODES
Register Indirect Mode
Instruction specifies a register which contains
the memory address of the operand
- Saving instruction bits since register address
is shorter than the memory address
- Slower to acquire an operand than both the
register addressing or memory addressing
- EA = [IR(R)] ([x]: Content of x)
40
TYPES OF ADDRESSING MODES
Direct Address Mode
Instruction specifies the memory address which
can be used directly to the physical memory
- Faster than the other memory addressing modes
- Too many bits are needed to specify the address
for a large physical memory space
- EA = IR(address), (IR(address): address field of IR)
41
Direct
44
relative