Escolar Documentos
Profissional Documentos
Cultura Documentos
(E 4160)
Thava kumar A/L Devanayagam 1
Chapter 1
Pengenalan kepada mikropemproses Introduction to Microprocessors
What is a Microprocessor ?
A microprocessor is a multipurpose, clockdriven, register-based electronic device that reads binary instructions from a storage device called memory, accept binary data as input and processes data according to the instructions given and provides results as output. Ex: 8085, 8086, Z80, 6800, Pentium processors etc
Microprocessors
The microprocessor is a programmable integrated device that has computing and decision-making capability similar to that of the central processing unit (CPU) of a computer. The fact that the microprocessor is programmable means it can be instructed to perform given tasks within its capability. The microprocessor is a clock-driven semiconductor device consisting of electronic logic circuits manufactured by using either a large-scale integration (LSI) or very-large-scale integration (VLSI) technique.
Thava kumar A/L Devanayagam 4
Microprocessors
A typical MPU has three basic parts inside. They are:
the Program Counter (PC) Memory, and Input / Output (I/O).
The Program Counter keeps track of which command is to be executed. The Memory contains the commands to be executed. The Input / Output handles the transfer of data to and from the outside world (outside the MPU physical package). There are many other actual parts inside the MPU, however, we will learn about every single one, one step at a time.
Thava kumar A/L Devanayagam 5
Microprocessors
Nowadays, the microprocessor is being used in a wide range of products called microprocessor-based products or systems. The microprocessor can he embedded in a larger system, can be a stand alone unit controlling processes, or it can function as the CPU of a computer called a microcomputer.
Thava kumar A/L Devanayagam 6
Microprocessors
The microprocessor communicates and operates in the binary numbers 0 and 1, called bits. Each microprocessor has a fixed set of instructions in the form of binary patterns called a machine language. It is difficult for humans to communicate in the language of 0s and 1s. Therefore, the binary instructions are given abbreviated names, called mnenomics, which form the assembly language for a given microprocessor.
Thava kumar A/L Devanayagam 7
Microprocessors
A typical programmable machine can be represented with four components: microprocessor, memory, input, and output. These four components work together or interact with each other to perform a given task; thus, they comprise a system. The physical components of this system are called hardware. A set of instructions written for the microprocessor to perform a task is called a program, and a group of programs is called software.
Thava kumar A/L Devanayagam 8
Microprocessors
The microprocessor applications are classified primarily in two categories:
reprogrammable systems and embedded systems.
Microprocessors
In reprogrammable systems, such as microcomputers, the microprocessor is used for computing and data processing. These systems include:
general-purpose microprocessors capable of handling large data, mass storage devices (such as disks and CD-ROMs), and peripherals such as printers; a personal computer (PC) is a typical illustration.
Thava kumar A/L Devanayagam 10
Microprocessors
In embedded systems, the microprocessor is a part of a final product and is not available for reprogramming to the end user. Example:
copying machine washing machine. Air-conditioner Etc.
Thava kumar A/L Devanayagam 11
Microcontroller - a device that includes microprocessor, memory, and I/O signal lines on a single chip, fabricated using VLSI technology.
Thava kumar A/L Devanayagam 12
Arithmetic Logic Unit (ALU) This is the area of microprocessor where various computing functions are performed on data. Control Unit The control unit provides necessary timing and control signals to all operating units in the microcomputer. It controls the flow of data between microprocessor, memory and peripherals. Memory Memory unit stores group of binary digits (word) that can represent: a. instructions (program) that the computer is to perform. b. the data that are to be operated on by the program. Input Consists of all of the devices used to take information and data from the external environment to be inputted into the computer system. Output (I/O) Consists of all of the devices used to transfer information and data from computer system to the external environment.
Thava kumar A/L Devanayagam 18
Definisi Mikrokomputer : Ahli terbaru keluarga komputer, yang mengandungi cip mikropemproses, cip ingatan dan antara mukaan I/O. Dalam beberapa kes, semua yang disebut berada dalam satu cip tunggal
19
Satu cip silikon yang bekerja sebagai heart komputer. Menerima arahan daripada memori utk mengimplementasikan tugas.
20
1. MEMORI UTAMA:
1.
RAM (Random Access Memory): Data boleh dibaca dan disimpan. Data yang disimpan akan hilang apabila bekalan diputuskan. ROM (Read Only Memory): Data boleh dibaca tetapi tidak bolehditulis. Data yang disimpan tidak akan hilang apabila bekalan diputuskan.
2.
2. MEMORI KEDUA:
RAM boleh menyimpan data sementara. Contohnya floppy disc,,harddisk dan CDROM (Compact-disc ROM), yang mana boleh menyimpan kepada 600 million characters dan sesuai untuk menyimpan maklumat yang bersaiz besar.
Thava kumar A/L Devanayagam 21
Mengandungi litar antaramuka yang diperlukan untuk membenarkan persisian dihubungkan komponen lain. Contoh litar antaramuka ialah cip-cip LSI direka oleh pengeluar MPU untuk mengantaramuka MPU ke pelbagai komponen input/output. Contoh litar antaramuka yang mudah ialah daftar buffer. Unit I/O membenarkan pengguna untuk berkomunikasi dengan sistem komputer melalui antaramuka untuk berkomunikasi dengan komponen persisian. Contoh persisian ialah keyboard, printer dan sensor Saiz port input/output ialah sama dengan saiz bas data mikropemproses.
22
TAHUN 1971
SYARIKAT Intel
1972
1974
Intel
Intel Motorola
1975
MOS Zilog
1976
1978 1980 1982
Intel
Intel Intel Intel Motorola
1983
Motorola
1984
1985 1987 1989
Motorola
Intel Motorola Intel
TAHUN
SYARIKAT Motorola
INOVASI 68040 68030 yg lebih laju (FPU) bina dlm Pentium - 80486 yg lebih laju; superskalar; FPU + 2 ALU
1993
Intel
Motorola/IBM/ Power PC mP RISC Apple 1994 2003 Motorola AMD Intel 68060 68040 yg lebih laju; superskalar; FPU + 2 ALU the first 64-bit IA-32 backwards-compatible architecture, AMD64 x86-64 chips, the 64-bit desktop Both processors can run 32-bit legacy apps as well as the new 64-bit software. With 64-bit Windows XP, Linux and Mac OS X (to a certain extent) that run 64-bit native dual-core processors are widely used in high-end servers and workstations while quad-core processors for servers are beginning to become available.
2006
Intel
24
DATA TYPES
DATA CAPASITY 2N
RANGE 01 0 - 15 0 255
2 16 256
16
32
Word
Long Word
65536
4,294,967,296
0 65535
0 - 4,294,967,295
25
Fetch (next) Instruction 3) Microprocessor continue the next instruction. Execute Instruction
1: Microprocessor fetch instruction representing the signal carried by the address bus.
NO
Is it a HALT instruction?
YES
END
Thava kumar A/L Devanayagam 26
uP Opkod
28
29
30
31
ALU
REGISTER SECTION
33
34
35
Registers section:
These internal registers serve as temporary data storage, before, in progress and after the process done by ALU. Data transfer within these registers is much faster as compared to the memory. This section contains various registers (inside the MPU), each of which performs a special function. These registers are: general purpose registers array, accumulator, instruction register, program counter, and flag register.
Thava kumar A/L Devanayagam 36
Accumulator
The accumulator is an 8-bit register that is part of the arithmetic/logic unit (ALU). This register is used to store 8-bit data and to perform arithmetic and logical operations. The result of an operation is stored in the accumulator. The accumulator is also identified as register A.
37
Flags
The following flags are set or reset after the execution of an arithmetic or logic operation; data copy instructions do not affect any flags. See the instruction set (Appendix F) to find how flags are affected by an instruction.
Z-Zero: The Zero flag is set to 1 when the result is zero; otherwise it is reset. CY - Carry: If an arithmetic operation results in a carry, the CY flag is set; otherwise it is reset. S - Sign: The Sign flag is set if bit D7 of the result = 1; otherwise it is reset. P - Parity: If the result has an even number of 1s, the flag is set; for an odd number of 1s, the flag is reset. AC - Auxiliary Carry: In an arithmetic operation, when a carry is generated by digit D3 and passed to digit D4, the AC flag is set. This flag is used internally for BCD (binary-coded decimal) operations; there is no Jump instruction associated with this flag.
Thava kumar A/L Devanayagam 38
Flag
Block Diagram
D7 D6 D5 D4 D3 D2 D1 D0
AC
CY
39
Example
Instruction:
ADD B
Register contents after instruction:
A B Flag
1001 1010 1000 1001 0010 0011
23 h 89 h 10 h
Note: All flags are modified to reflect the result of the addition.
40
1. Carry (CY)
MSB: b7 b8 = 1 C=1
2. Zero (Z)
Operation
Non-Zero
Z=0
41
3. Sign (S)
4. Auxiliary Carry
Bendera ini akan disetkan apabila berlaku carry dari bit-3 ke bit-4 semasa operasi campur atau tolak. Bendera ini biasanya akan digunakan dalam operasi aritmetik BCD (binary Coded Decimal) Operasi: 2F16 00101111 + 3816 00111000 6716 01100111
Thava kumar A/L Devanayagam 42
5. Pariti (P)
Bendera pariti menunjukkan bilangan bit 1 yang ada dalam daftar penumpuk sahaja. Jika P =1 (ganjil) P = 0 (genap) Operasi: 9C16 10011100 4216 01000010 DE16 11011110 Bil. Bit adalah enam maka iaiti genap,P =0
43
General-purpose Registers
The 8085 has six general-purpose registers to store 8-hit data; B, C, D, E, H, and L. They can be combined as register pairs - BC, DE, and HL - to perform some 16-bit operations. The programmer can use these registers to store or copy data into the registers by using data copy instructions.
44
SP:
It points to a memory location in R/W memory, called the stack. The beginning of the stack is defined by loading a 16-bit address in the stack pointer. The PC will automatically update when calling to /returning from Subroutines.
Thava kumar A/L Devanayagam 45
16 Bit Registers
Program Counter
A pointer to the next instruction to be executed Contains the 16-bit memory address of the next instruction Updated after processor has fetched the instruction
6-bit register acting as memory pointer sequences the execution of instructions PC points to the memory address from which the next byte is to be fetched. while a byte being fetched it is incremented by 1 to point to next memory location.
46
Stack Pointer
Stack an area in memory in which temporary info is stored Stack FILO (First In Last Out) basis Holds the address of the top of the stack 16-bit register acting as memory pointer. SP points to the memory location in R/W memory (RAM), called the stack. The beginning of the stack is defined by loading a 16-bit address in the stack pointer (SP).
Thava kumar A/L Devanayagam 47
49
50
Bus system
A wire is used to transfer a signal from one point to another. A group of wires is called bus. In the microcomputer system, there are three buses (data, address, and control) to connect the microprocessor (CPU) to each of the devices in the microcomputer system such as memory and I/O devices. These buses will carry (sending or receiving) all the information and signals involved in the system operation from one device to another.
Thava kumar A/L Devanayagam 51
DATA BUS
Bidirectional bus, because data can flow to or from the CPU. The size of data bus is determined by the number of lines (bits) which is also called data size. Data size: Size of single cell in the memory. Numbers of bit the CPU can handle at any one time. Intel 8085 microprocessorhas 8 bits data bus, thus: Data size n = 8 bits, Data lines are labelled Dn : D0, D1, .. D6, D7 In other words, the CPU can handle, or data bus can transfer 8 bits data in parallel simultaneously, thus determine the speed of data transfer. The same data bus (bits) can be set to either inputs or outputs depending on whether the CPU is performing a read or a write operation respectively.
Thava kumar A/L Devanayagam 52
ADDRESS BUS
Unidirectional bus, because information flows over it in only one direction, i.e. from CPU to the memory or I/O elements. The number of address lines (address bus size) determine the number of memory cells that CPU can handle. For instance, the Intel 8085 has 16 bits of address bus: n = 16 bits (Size of address bus): Address bus is labelled An : A0, A1, .. A14, A15 2n = 216 = 65536: CPU can handle or address 65536 single cells (each cell has 8 bits data size) of memory. In other words, 16 bit address lines can represent 65536 memory location: 0 to 65535 locations, addressed as 0000h to FFFFh
53
CONTROL BUS
This is the set of signals that is used to synchronize the activities of the separate microcomputer elements. Control bus consists some individual lines for sending and some others for receiving signals from CPU, thus control bus is bidirectional. For instance, CPU sends control signals (Read/Write) to the memory or I/O devices to tell them either to be set to receive or send data respectively. CPU send Control signal : Read Action: CPU receive data CPU send Control signal : Write Action: CPU send data
Thava kumar A/L Devanayagam 54
55
56
Status Register
57
Kuiz 1
executes each machine instruction by performing a fetch/execute cycle. CPU fetches an opcode byte from memory and decodes it to find out what it is supposed to do. CPU executes the instruction. instructions examine or modify memory or input and output (I/O). After the is completed, the cycle resumes instruction for the next instruction.
Thava kumar A/L Devanayagam 59
CPU
Arahan
1 Pembilang Aturcara Mikropemproses
Thava kumar A/L Devanayagam
Bas Alamat 2 3
Ingatan
60
1 Alamat ingatan bagi suruhan pertama diletakkan ke pembilang aturcara 2 Pembilang aturacara akan meletakkan alamat ingatan tersebut ke bas alamat 3 Alamat ingatan kemudiannya dihantar ke ingatan 4 Ingatan menterjemahkan alamat tersebut dan kedudukan ingatan yang dikehendaki dapat dikesan 5 Ingatan akan menghantar suruhan kembali ke mikropemproses melalui talian bas data 6 Suruhan diletakkan di dalam Daftar Arahan dalam mikropemproses.
Thava kumar A/L Devanayagam 61
7 Mikropemproses menterjemah suruhan tersebut sebelum dilaksanakan 8 Pembilang aturcara akan ditokok dan mikropemproses bersedia menerima suruhan seterusnya
62
Chapter 2
PENGENALAN PENGAWAL MIKRO Introduction to Microcontroller
63
What is Microcontroller?
A microcontroller is an integrated chip that is often part of an embedded system. The microcontroller includes a CPU, RAM, ROM, I/O ports, and timers like a standard computer, but because they are designed to execute only a single specific task to control a single system, they are much smaller and simplified so that they can include all the functions required on a single chip. A microcontroller differs from a microprocessor, which is a general-purpose chip that is used to create a multifunction computer or device and requires multiple chips to handle various tasks. A microcontroller is meant to be more self-contained and independent, and functions as a tiny, dedicated computer.
Thava kumar A/L Devanayagam 64
DEFINITION
mC = single- chip microcomputer Contains on-chip resources typically used in embedded applications. May not requires extra off-chip resources to function. Ex: Intels 8051, 8096, Motorola M68HC11, PIC 16XX series etc.
65
mC APPLICATIONS
Applications Computing Example PC, Notebook, laser printer
Cars
Cards
Engine control
Banking, Touch N Go
Thava kumar A/L Devanayagam 66
Ciri-ciri microcontroller
Rekabentuk bersifat All-in-one Ketegapan (Robustness) Keperluan Kuasa yang rendah (Low Power Consumption)
67
68
Externally
69
70
mC SYSTEM
Buffers & converter Bus Condition I/O signal levels if necessary Data,address and control Data = sinals represent instructions and values of different variables, such as temperature Address = indicate where data is stored Control = signals coordinate microcontroller operation with associated chips.
71
mC SYSTEM
Clock Circuit Generates a fixed-frequency signal that provides timing information for the entire system. a crystal connected to two pins of the microcontroller Power converts incoming power such as Circuit 115V alternating current (ac) or 12 V direct current (dc) to the nominal 5 V dc required to operate the microcontoller.
Thava kumar A/L Devanayagam 72
73
74
Sistem Bas
Bas Alamat Kumpulan talian yang membawa isyarat alamat dari pemproses ke ingatan dan I/O supaya pemproses boleh mencapai lokasi dan port-port yang tertentu. Kumpulan talian yag membawa data dari pemproses ke ingatan dan port keluaran dari ingatan dan port masukan ke pemproses
75
Bas Data
Bas Kawalan
Kumpulan talian yang membawa isyarat kawalan untuk proses seperti baca dari RAM dan port, reset dan interrupt pemproses.
76
77
78
Feature 8051 ROM (program space in bytes) 4K RAM (bytes) 128 Timers 2 I/O pins 32 Serial port 1 Interrupt sources 6
8052 8K 256 3 32 1 8
8031 0K 128 2 32 1 6
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
8051 (8031)
Pins of 80511/4
Vccpin 40 Vcc provides supply voltage to the chip. The voltage source is +5V. GNDpin 20ground XTAL1 and XTAL2pins 19,18 These 2 pins provide external clock. Way 1using a quartz crystal oscillator Way 2using a TTL oscillator Example 4-1 shows the relationship between XTAL and the machine cycle.
1
95
Pins of 80512/4
RSTpin 9reset It is an input pin and is active highnormally low. The high pulse must be high at least 2 machine cycles. It is a power-on reset. Upon applying a high pulse to RST, the microcontroller will reset and all values in registers will be lost. Reset values of some 8051 registers
Way 1Power-on reset circuit Way 2Power-on reset with debounce
96
Pins of 80513/4
/EApin 31external access There is no on-chip ROM in 8031 and 8032 . The /EA pin is connected to GND to indicate the code is stored externally. /PSEN ALE are used for external ROM. For 8051, /EA pin is connected to Vcc. / means active low. /PSENpin 29program store enable This is an output pin and is connected to the OE pin of the ROM. See Chapter 14.
3
97
Pins of 80514/4
ALEpin 30address latch enable It is an output pin and is active high. 8051 port 0 provides both address and data. The ALE pin is used for de-multiplexing the address and data by connecting to the G pin of the 74LS373 latch. I/O port pins The four ports P0, P1, P2, and P3. Each port uses 8 pins. All I/O pins are bi-directional.
98
99
XTAL2
XTAL1
GND
100
Example :
Find the machine cycle for (a) XTAL = 11.0592 MHz (b) XTAL = 16 MHz. Solution:
(a) 11.0592 MHz / 12 = 921.6 kHz; machine cycle = 1 / 921.6 kHz = 1.085 ms (b) 16 MHz / 12 = 1.333 MHz; machine cycle = 1 / 1.333 MHz = 0.75 ms
101
102
+ 10 uF 31 EA/VPP X1 X2
30 pF
8.2 K 30 pF
11.0592 MHz
19
18
9 RST
103
31 10 uF 30 pF
EA/VP X1 P X2 RST
9
8.2 K
104
105
106
107
Pereka sistem boleh menentukan jumlah RAM, ROM dan pengkalan I/O yg diperlukan dalam sistem
Pereka sistem tidak boleh menentukan jumlah RAM, ROM dan pengkalan I/O kerana ia adalah tetap yg diperlukan dalam sistem Biasa digunakan untuk tujuan kawalan
108
Chapter 3
PENGENALAN KEPADA BAHASA PENGHIMPUN (SET SURUHAN) INTRODUCTION TO ASSEMBLY LANGUANGE
109
DEFINISI BAHASA
BAHASA ialah satu medium komunikasi di antara dua atau lebih individu atau kumpulan
110
Language Categories
Three classes of Languages
High-level languages
Hide the detail of computer and O.S.
Platform-independent
C++,Java and Fortran
Assembly languages
Platform-specific Backward compatible
Thava Kumar A/L Devanayagam 111
Language Categories
Machine languages
Contain binary value Platform-specific
112
SISTEM KOMUNIKASI KOMPUTER Pengaturcara Bahasa Tahap tinggi Bahasa Penghimpun Tahap Tinggi
JEPUN
P E N T E R J E M A H
Penterjemah
Compiler
Assembler
Tahap Pertengahan
B A H A S A
Bahasa mesin
Tahap Rendah
Komputer
113
COMPILERS (Pengkompil)
Bahasa Tahap Tinggi (Basic, Pascal and C) Arahan pengaturcaraan dalam english dan sangat mesra kepada pengguna programmers.. Bahasa Tahap Pertengahan (Bahasa penghimpun) Arahan pengaturcaraan dalam english seperti abbreviation masih tidak mesra kepada pengguna. ASSEMBLER (Penghimpun)
114
Linker combines object code with any other required object code.
stored as in executable file.
116
PERBEZAAN KELEBIHAN
BAHASA PENGHIMPUN
Cepatkan penulisan bhs mesin, kod senang ingat atau singkatan kpd pkt mudah yg dikenali mnemonik mengantikan nilai perenambelasan
KEKURANGAN
Arahan pengaturcaraan dalam english seperti abbreviation masih tidak mesra kepada pengguna.
Machine Language: The binary medium communication with a computer through a designed set of instructions specific to each computer. Ex- 1000 0000 ADD B 80H Instructions in binary form machine lang. Mnemonic Hex codes This instruction adds the contents of register B to the accumulator.
118
FF01
3E
MVI A,1
;load A with1
Alamat
Opcode
Mnemonik Operand
Komen
Medan yang mewakili setiap baris aturcara bahasa penghimpun dgn lokasi alamat heksadesmal Medan yang mengandungi kod-kod operasi (heksadesimal) untuk set suruhan 8085 yang telah diterjemahkan dri mnemonik Mengandungi mnemonik suruhan bahasa penghimpun mnemonik suruhan diterjemahkan menjadi kod mesin yang boleh dilaksanakan pemproses pengaturcara memasukkan aturcara dgn lebih mudah, tanpa keperluan untuk menghafal nilai-nilai opkod Sesetengah suruhan memerlukan operand, terdapat suruhan tidak memerlukan operand Pengaturcara memasukkan penerangan ringkas mengenai setiap baris aturcara, setiap komen mestilah dimulakan dengan simbol (;)
OPERAND KOMEN
119
120
121
122
Instruction Formats
Three-operand instruction
- the op code and three operands.
Two-operand instruction
-the first operand is both destination and one of the source register.
Instruction Formats
124
Instruction Formats
One-operand instruction
- the accumulator register is always the destination and one of the source register.
Zero-operand instruction
- all operands are drawn from the stack.
Instruction Formats
125
Instruction Types
Data Transfer Instructions
-Move data from one place to another
Load data from memory into the microprocessor.
127
128
129
The memory location, which is indirectly addressed by the HL register pair, appears as the letter M in all instructions.
Thava kumar A/L Devanayagam 130
131
132
133
134
135
Copies the contents of location 1000H into the L register and the contents of location 1001 H into the H register
stores the contents of the L register at memory location I200H and the H register at location 1201H
136
137
138
139
140
141
142
The programmer decides what portion of the read/write memory is to function as the stack, and then loads the SP with the top location plus one byte. The byte location above the stack is never used, but must be the initial value of the stack pointer. The SP always points to the current exit point. The stack is a LIFO stack.
Thava kumar A/L Devanayagam 143
145
146
Note: POP PSW will copy the data from location pointed by SP into flag register and data from (SP+1) will copy into A. The SP=SP+2.
Thava kumar A/L Devanayagam 147
Ia juga merupakan suatu kawasan dalam memori (kebiasaannya RAM) di mana data atau alamat akan disimpan semasa mikropemproses melaksanakan salah satu daripada 3 perkara berikut: i. Semasa mikropemproses melaksanakan arahan PUSH dan POP. ii. Apabila mikropemroses melaksanakan arahan jump to subroutine: CALL dan RET) iii. Bila ada interrupt kepada mikropemproses.
149
TAKRIFAN Struktur data diambil dengan turutan (tindanan) berlawanan dengan turutan semasa menyimpan (last-in-first-out LIFO)
GAMBARAJAH BLOK
Last In In Plate6
Plate6 Plate5 Plate4 Plate3 Plate2 Plate1 Plate6 Plate5 Plate4 Plate3 Plate2 Plate1
Out Plate-5
Plate5 Plate4 Plate3 Plate2 Plate1
In Plate1
In Plate2
Plate2 Plate1
Out Plate-1
Plate1
Plate1
In Plates
Out Plates
150
JENIS-JENIS TINDAN
LIFO Last In First Out Data yang disimpan (PUSH) kemudian, akan dikeluarkan terdahulu (POP) First In First Out Data yang mula disimpan (PUSH), akan dikeluarkan (POP) terdahulu.
FIFO
151
Operasi PUSH dan POP dilakukan ke atas kandungan daftar iaitu BC, DE atau HL. Suruhan PUSH dan POP tidak akan menyebabkan sebarang perubahan pada daftar bendera/status. Suruhan PUSH dan POP adalah suruhan 16 bit (2 byte) Semasa operasi PUSH, SP akan berkurangan sebanyal 02H dan kandungan pasangan daftar akan disimpan ke dalam tindan. Semasa operasi POP, kandungan tindan akan dimuatkan ke dlm pasangan daftar dan penunjuk tindan akan bertambah sebanyak 02H.
152
Contoh: Suruhan PUSH B bermakna daftar B dan C akan disimpan ke dalam tindan. ((SP))-1) <= (B) ((SP))-2) <= (C) (SP) <= (SP)-2)
153
Contoh: Suruhan POP D bermakna kandungan tindan dimasukkan ke dalam daftar D dan E (E) <= ((SP)) (D) <= ((SP) + 1) (SP) <= (SP) + 2)
Thava kumar A/L Devanayagam 154
FIRST IN FIRST OUT POP MVI B, A6H ; MVI C, 5AH; PUSH B ; POP D; hlt FFF0 FFEF FFEE FFEE FFEF FFF0 PUSH
Thava kumar A/L Devanayagam 155
5A A6 5A A6
E D C B
156
157
158
EXAMPLE 1
Load the accumulator A with the data byte 82H (the letter H indicates hexadecimal number), and save the data in register B. Instructions: MVI A, 82H, MOV B,A
The first instruction is a 2-byte instruction that loads the accumulator with the data byte 82H, and the second instruction MOV B,A copies the contents of the accumulator in register B without changing the contents of the accumulator.
Thava kumar A/L Devanayagam 159
Instruction Types
Data Operation Instructions
-modify their values.
Arithmetic instructions:add, subtract,multiply, divide, clear.
162
Arithmetic Instructions
163
Arithmetic Instructions
164
Arithmetic Instructions
165
Arithmetic Instructions
166
ADDITION
Addition takes several forms in the 8085 microprocessor:
8-bit binary, 16-bit binary, and two-digit binary-coded-decimal (BCE)) addition.
Binary addition functions with either signed or unsigned numbers; BCD addition uses only unsigned numbers. The instruction set supports additions using register addressing, register indirect addressing, and immediate addressing, but not direct addressing.
Thava kumar A/L Devanayagam 167
ADDITION
168
ADDITION
169
ADDITION
170
171
172
173
174
Sixteen-Bit Addition
The 8085 instruction set does contain special instructions (DAD) that do 16-bit addition.
175
BCD Addition
BCD addition is like binary addition except that the numbers range in value only from 0 through 9. A special instruction allows BCD addition by using the standard binary addition (ADD) instructions.
The DAA instruction appears after a BCD addition (with a binary add instruction) to correct the BCD result. The DAA instruction does not convert a binary number to a BCD number.
Thava kumar A/L Devanayagam 176
Example 5-6 illustrates the summation of the packed BCD numbers 11 and 19. After this addition, the accumulator contains a 2AH, which is not a BCD number:
the answer should be a 30BCD The DAA instruction corrects the answer after the addition and provides a 30BCD after the DAA instruction executes.
Thava kumar A/L Devanayagam 177
BCD Addition
The DAA instruction changes the result through the two tests listed by adding a OOH, 06H, 60H, or 66H to the accumulator.
If the least significant half-byte is greater than 9 or if the AC flag = 1, the DAA instruction adds a 06H to the accumulator. If the most significant half-byte is greater than 9 or if the C flag bit 1, the DAA instruction adds a 60H to the accumulator.
178
Increment
The last form of addition is to increment or add 1. The increment command is either an 8-bit (INR) increment or a 16-bit (INX) Increment instruction. The INR instructions affect all the flags except carry, and the INX instructions affect no flags.
179
180
Subtraction
The 8085 supports 8-bit binary subtraction and decrement. It also supports a subtraction instruction that allows a borrow to be propagated through additional bytes of a number. The subtract-with-borrow instruction aids in the subtraction of multiple-byte numbers.
181
Subtraction The 8085 performs subtraction by using the method of 2s complement. Subtraction can be performed by using either:
the instruction SUB to subtract contents of a source register or the instruction SUI to subtract an 8-bit number from contents of the accumulator. In either case, the accumulator contents are regarded as minuend (the number from which to subtract).
Thava kumar A/L Devanayagam 182
Subtraction
Various subtraction instructions: register, register indirect, and immediate addressing. Direct addressing is not allowed for a subtraction. Each of these instructions affects the flag bits, so they reflect various conditions about the difference after a subtraction.
183
Subtraction
The 8085 performs the following steps internally to execute the instruction SUB (or SUI):
Converts subtrahend (the number to be subtracted) into its 1s complement. Adds 1I to 1s complement to obtain 2s complement of the subtrahend. Add 2s complement to the minuend (the contents of the accumulator). Complements the Carry flag.
184
PROBLEM STATEMENT
Write a program to do the following:
Load the number 3011 in register B and 3911 in register C. Subtract 39H from 3011. Display the answer at PORT I.
185
186
PROGRAM DESCRIPTION
Registers B and C are loaded with 30H and 39H, respectively. The instruction MOV A,B copies 30H into the accumulator (shown as register contents).
187
execute the instruction SUB C the microprocessor performs the following steps internally:
188
PROGRAM DESCRIPTION
The number F7H is a 2s complement of the magnitude (39H-30H)=09H.
This Cy flag is set, indicating the answer is in 2s complement.
189
Subtraction
P= 0
Odd parity
190
191
192
193
LOGIC INSTRUCTIONS
Four basic logic functions: invert, AND, OR, and exclusive-OR. Why does a microprocessor instruction set contain logic instructions? Logic instructions sometimes replace discrete logic gates. Today, program storage costs about of a cent per byte. System control software usually requires bit manipulation a logic operation.
194
Inversion (NOT)
The CMA instruction (2FH in machine language), onescomplements or inverts the contents of the accumulator. This operation, which affects none of the flag bits, causes each bit of the accumulator to be inverted (changed from 1 to 0 or 0 to 1). The CMA instruction causes the accumulator to appear as eight inverters (or NOT).
This means that this one-byte instruction replaces eight discrete inverters if the speed required is not too great. The amount of circuitry replaced by the CMA instruction is 14 of a 7404 TTL hex inverter.
195
The AND instruction, functions as eight independent twoinput AND gates. This instruction replaces two 7408 quad two-input AND gates.
196
197
198
The OR Operation
Has two separate functions in a microprocessor-based system:
It selectively sets bits of the accumulator or Replaces discrete OR gates.
The inclusive-OR instruction functions as eight independent two-input OR gates. This instruction replaces two 7432 quad two-input OR gates.
199
The OR Operation
200
The OR Operation
201
202
PROBLEM STATEMENT
Two input port with eight switches (each port) at address 00H and OIH (Figure 6.9) is connected to the microcomputer to control the same appliances and lights from the bedroom as well as from the kitchen. Write instructions to turn on the devices from any of the input ports.
203
204
Illustrative Program:
ORing Data from Two Input Ports
PROBLEM ANALYSIS
To turn on the appliances from any one of the input ports, the microprocessor needs to read the switches at both ports and logically OR the switch positions. Assume that the switch positions in one input port (located in the bedroom) correspond to the data byte 9lH and the switch positions in the second port (located in the kitchen) correspond to the data byte A8H. The person in the bedroom wants to turn on the air conditioner, the radio, and the bedroom light; and the person in the kitchen wants to turn on the air-conditioner, the coffeepot, and the kitchen light. By ORing these two data bytes, the MPU can turn ON the necessary appliances.
Thava kumar A/L Devanayagam 205
Illustrative Program:
ORing Data from Two Input Ports
206
Exclusive OR (XOR)
207
ROTATE INSTRUCTIONS
208
SHIFT INSTRUCTIONS
209
Instruction Types
Program Control Instructions
Jump/branch instruction similar to GOTO
-absolute(always taken)/conditional
Branching Instructions Jump Instructions: JMP 16-bit There are some conditional jump instructions Call and Return: CALL 16-bit RET There are some conditional jump instructions Restart Instructions:
Machine Control Instructions HLT NOP
Thava kumar A/L Devanayagam 211
Branching Instructions
the 8085 code to perform this algorithm MVI MOV XRA Loop: ADD DCR JNZ STA A,5 B,A A B B Loop 2000
212
Branching Instructions
Execution trace of the 8085 loop summation
213
Control Instructions
Allow computers to make decisions and change the flow of the programme based on the results outcome. Two main forms:
JUMP instructions:
Allow programme to jump to any memory locations.
CALL instructions
Allow a group of instructions (subroutine) to be reused by the program in many different places.
Thava kumar A/L Devanayagam 214
CONDITIONAL JUMP
Conditional JUMP instructions:
Allow the programmer or programme to make a choice based on conditional terms. A condition is tested by the microprocessor to decide whether a jump occurs. The conditions tested by the conditional jumps are the same conditions held in the flag bits. The terms are :
Zero / not zero Carry set / cleared Positive / minus Parity odd / even
Thava kumar A/L Devanayagam 215
216
217
218
SUBROUTINES
A subroutine is a short sequence of instructions that performs a single task. One advantage of using a subroutine is a significant savings of memory space. Subroutines also simplify the task of writing a program because subroutines only appear in a program once, but are used often. CALL instruction allows the programmer to use (link to) a subroutine. When the 8O85 executes a CALL instruction, two events occur: The contents of the PC are pushed onto the stack, and The program continues at the address stored with the CALL instruction. The CALL instruction is a combination of the PUSH and the JMP instructions.
219
SUBROUTINES
220
SUBROUTINES
The RET(return) instruction returns to the main program at the instruction that follows the CALL. This can be accomplished because the address of this instruction is stored on the stack because the CALL placed it there as a return address. The RET command POPs a number from the stack and places it into the program counter.
221
SUBROUTINES
? ?
AFTER CALL COMP STACK
20 05
REGISTERS
FFFF
FFFE
01
PC 2040 SP FFFE
Thava kumar A/L Devanayagam 222
Instruction Size
1-byte instructions: Opcode and operand in the same byte. MOV C,A Opcode= Hex code = 4FH ADD B
2-byte instructions: First byte = Opcode; Second byte = Operand; MVI A,32H Opcode= Hex code = 3EH = 1st byte; 32H = 2nd byte 3-byte instructions: First byte = Opcode; Second byte = Low order address; Third byte = High order address JMP 3035H Opcode= Hex code = C3H = 1st byte; 35H = 2nd byte; 30H = 3rd byte.
Thava kumar A/L Devanayagam 223
Chapter 4
MOD-MOD PENGALAMATAN & TEKNIK PENGATURCARAAN Addressing Modes & Programming technique
225
Definition
The procedure of fetching and sending data between source and destinations is carried out by various addressing approaches
226
Microprocessor needs memory address to access data from the memory. Assembly language may use several addressing modes to implement this task.
227
228
231
232
234
Assembly Language
Assembly language: Assembly language is used for most programming because it is extremely difficult to program a microprocessor in its native, that is hexadecimal machine language. Assembler: An assembler is a program that converts software written in symbolic machine language (the source programme) into hexadecimal machine language (object programme). The primary reason to use assembler is because development and modification are always difficult in machine language.
Thava kumar A/L Devanayagam 235
Assembly Language
The Two-pass Assembler : Read programme two times.
1. Generate a table of the labels/symbols within the source programme. 2. Develop hexadecimal version of the source programme.
Allow forward addressing (the software can jump ahead to an instruction in a program).
236
Assembly Language
237
Assembly Language
The assembler always assumes that the first instruction of the programme is stored at memory address 0000H unless otherwise directed by the ORG command.
238
Assembly Language
Pass One:
The assembler scans the source programme during the first pass and generates a table of the labels found within the source programme. Each entry in the label table contains the label and the address where the label appears in the programme. During the first pass the assembler determines the length of each instruction by updating an internal programme counter. This internal programme counter allows the assembler to complete the label table by equating each label with the counter. Once the label table is complete the second pass begin.
Thava kumar A/L Devanayagam 239
Assembly Language
Pass Two: During the second pass of the source programme, the assembler forms the object programme. This occurs by referring to the label table for any labels that appear in the programme and to an instruction table. The instruction table contains all the opcodes in both symbolic and machine language forms. The tables help convert the source programme into the object programme.
Thava kumar A/L Devanayagam 240
Assembly Language
241
Assembly Language
Assembly Language Statement: Format :
Label Field. Contains a symbolic memory address that refers to the statement in a programme. Labels are optional and must end with a colon in some Intel 8085A ( : ). Labels are constructed from alphanumeric characters and must begin with any letter of the alphabet. Thava kumar A/L Devanayagam 242
Assembly Language
243
Assembly Language
Opcode field:
This field must contain opcodes.
Operand field:
May contain register name, data or labels. If more than one of these is present, they must be separated with comma. Data must be encoded as decimal, binary, octal, hexadecimal, or ASCII. ASCII must appear as one of more letters surrounded by apostrophe.
244
Assembly Language
Operand arithmetic operations.
245
Assembly Language
Comment field. Must begin with semicolon in most 8085 assemblers and may continue to the end of the line only. Use asterisk * or semicolon ; if the comment should continue into the next line. Example :
246
Assembly Language
Assembler pseudo operations. Directives to the assembler programme that may or may not generate machine code. Examples :
END, DB, DW, DS, ORG, EQU, IF, ENDIF, SET, GLB, EXT, TITLE, SPC.
247
Assembly Language
Define Byte (DB). Defines 8-bit memory data for a programme. Multiple one byte data, comma ( , ) as a separator.
248
249
Assembly Language
Origin (ORG). Changes the starting location of the programme to another address besides 0000H. Can be used at any place in a programme to change the location of the assembled machine language instructions or data.
Thava kumar A/L Devanayagam 250
251
Assembly Language
Define Word (DW). Pseudo operation stores a 16-bit number in the memory for use by a programme. Defines no only numeric data but also memory addresses and label.
252
253
Assembly Language
Define Storage (DS). Reserves space in a programme for variable data. Does not place any specific data into the reserved area of memory.
254
255
Assembly Language
Equate (Equ). Equates a label to another label or value. Note that the EQU statement label does not contain a colon ( : ).
256
Assembly Language
257
258
Flow Chart
Flow chart is a flow design structured programme to solve the problems. Flow chart also helps to correct and modify developed software. There are symbols to use in designing flow chart to ease programmer. These symbols consists of following process:
Process, predefined process, input/output, decision, connector and terminal.
260
Connector: Eliminates crisscrossed connecting lines in complicated flowcharts. Ease in understanding the developed programme. Terminal Symbol: Programmes all start somewhere and require a symbol to show where they start.
262
Flow chart
Flow chart example: mean calculation of a set of numbers
263
If-Then-Else
264
If-Then-Else
The solution.
265
Repeat-Until
Allows process to be executed or repeated until an event occurs. Whenever this construct appears, the process first executes a task and then a test checks for a true or a false condition. The following figures shows the repeat-until-true and repeat-until-false.
266
Repeat-Until: Example
Reads the keyboard until a CR (carriage return) is detected.
267
Do-While
Is comparable to the repeat-until except for one basic difference.
The do-while construct checks the condition and then, if required, performs the process and repeats the check. There are two forms: do-while-false and do-while-true.
268
Do-While
269
2. MEREKEBENTUK Merekabentuk aturcara yang hendak ditulis, sama ada dalam bentuk algoritma LOGIKAL
270
3. PENGATURCARAAN
Dgn bantuan algoritma dan carta alir, penulis boleh mula menulis aturcara yang diperlukan dengan menggunakan penyunting (text editor) untuk bahasa penghimpun atau secara terus untuk bahasa tahap tinggi. Aturcara ini adalah aturcara punca (source program) Contoh program :
271
4.
Penghimpun (assembler) akan menghimpunkan aturcara bahasa penghimpun. Penghimpun akan mengeluarkan fail senarai (list file) yang digunakan untuk mencari kesilapan di peringkat ini. Bagi bahasa tahap tinggi, pengkompil dan pentafsir akan menyatakan sebarang kesilapan yang telah dilakukan. Kesilapan atau error biasanya ralat sintaks iaitu penggunaan bahasa pengaturcaraan yang salah Jika tiada ralat, penghimpun akan mengeluarkan fail objek dan fail heksadesimal. Jika tiada ralat sintaks, aturcara boleh dijalankan untuk mengesan ralat logikal atau ralat semantik. Ralat logikal adalah kesilapan yang menyebabkan aturcara yang tidak berfungsi seperti yang dikehendaki iaitu tidak menepati tujuan yang ditetapkan.
Thava kumar A/L Devanayagam 272
Contohnya suatu aturcara ditulis untuk mengira markah penilaian pelajar di dalam kelas. Namun, aturcara yang ditulis tidak dapat mengira dengan tepat, maka aturcara ini ada ralat logikal iaitu penggunaan bahasa pengaturcaraan yang betul tetapi fungsinya tidak tepat. Jika ini berlaku, pengaturcara perlu kembali ke langkah yang kedua (merekabentuk logikal) dan mengulangi prosesproses seterusnya hingga aturcara beroperasi seperti yang dikehendaki. Proses pencarian ralat ini juga dikenali proses nyahpepijat atau debugging. Bg bhs penghimpun, pengujian boleh dilakukan dengan memuat-turunkan (download) aturcara tersebut pada simulator.
5.
Pengaturcara boleh mencetak aturcara fail punca DOKUMENTA sebagai dokumentasi dan mencatat komen yang SI PROGRAM sesuai pada aturcara sebagai panduan kepada pengguna lain.
Thava kumar A/L Devanayagam 273
LOOPING
The programming technique used to instruct the MPU to repeat task. Continuous loop Conditional loop
Repeat task until certain conditions are met.
Some loop include indexing along with counter. Indexing: pointing or referencing objects with sequential numbers, i.e. data in memory are accessed by referencing to their memory locations.
Thava kumar A/L Devanayagam 274
COUNTER
Counter. Counter is constructed by loading a number to any register. Then use INR or DCR to increment or decrement the number respectively. Loop is used to update counter value and every iteration the number is inspected to check whether the number is at maximum or Thava kumar A/L Devanayagam minimum.
275
276
A more efficient way to transfer a block of data uses the programmed-loop and counter.
Thava kumar A/L Devanayagam 277
Flowchart
Flowchart required to transfer a block of bytes from one area of memory to another .
278
279
Chapter 5
SISTEM INGATAN Memory System
280
SISTEM INGATAN
Ingatan adalah peranti yang digunakan untuk menyimpan data dan maklumat. Merupakan salah satu peranti yang penting didalam sistem komputer. Data yang disimpan didalam sistem ingatan berbentuk nombor perduaan iaitu '0' atau '1'. Jenis ingatan dalam sistem ingatan ialah ingatan semikonduktor (separa pengalir) Ingatan semikonduktor mempunyai masa capaian yang pendek berbanding dengan jenis ingatan lain. Sesuai digunakan didalam sistem mikropemproses untuk operasi kerja pantas
281
Kategori ingatan
Data digit boleh disimpan sebagai cas dalam kapasitans dan sejenis ingatan separa pengalir yang penting menggunakan prinsip bagi mendapatkan simpanan ketumpatan tinggi pada aras keperluan kuasa rendah. Ingatan utama juga dikenali sebagai ingatan bekerja yang saling bertindak balas dengan CPU. Ingatan Bantu adalah mempunyai muatan untuk simpan jumlah data yang banyak tanpa memerlukan kuasa elektrik yang berkelajuan rendah seperti CD,disket.
Thava kumar A/L Devanayagam 282
ALU
KAWALAN
(semiconductor)
283
PERBEZAAN
Memori
INGATAN UTAMA
Memori dalaman komputer
INGATAN KEDUA
Memori luaran komputer
Menyimpan
Program Boot up (BIOS) Program dan data tidak dikendalikan oleh CPU, hanya berlaku permindahan bila diperlukan. Perisian aplikasi seperti Microsoft Word.
RAM and ROM floppy disk CDROM magnetic disk/tape.
Contoh
284
MEMORI SEMIKONDUKTOR
ROM
RAM
PROGRAMABLE
SRAM
DRAM
MROM
UV
ERASABLE
ELECTRIC ERASABLE
EPROM
EEPROM
EAROM
285
Nonvolatile Memories
Nonvolatile memories retain value even if powered off. Generic name is read-only memory (ROM). Misleading because some ROMs can be read and modified. Types of ROMs Programmable ROM (PROM) Erasable programmable ROM (EPROM) Electrically erasable PROM (EEPROM) Flash memory Firmware Program stored in a ROM Boot time code, BIOS (basic input/ouput system) graphics cards, disk controllers.
286
JENIS-JENIS ROM
ROM ( Read Only Memory )
PROM (Programmable Read Only Memory) EPROM (Erasable Programmable Read Only Memory) EEPROM (Electrically Erasable Programmable Read Only Memory)
287
PROM
Diatur cara Keburukan
Setiap sambungan
290
PERBEZAAN
Ingatan Baca
EPROM
Yang boleh diaturcara dan dipadam menggunakan EPROM eraser (didedahkan kepada cahaya ultraviolet selama 12 minit atau dijemur di bawah sinaran matahari selama 1 hari)
EEPROM
Yang boleh diaturcara dan dipadam menggunakan isyarat (denyut) elektrik.Proses hanya 10ms
Pengguna
Tidak boleh memilih untuk memadamkan kandungan tertentu sahaja (boleh mempengaruhi bahagian lain)
Mesti dikeluarkan dari litar untuk diaturcara semula Di dlm makmal pembangunan produk, makmal kajian (research & development) dan dalam penghasilan prototaip.
Thava kumar A/L Devanayagam
Boleh memilih lokasi tertentu sahaja untuk dipadamkan tanpa mempengaruhi bahgaian lain.
Tidak perlu dikeluarkan dari litar untuk diaturcara Di dlm BIOS sistem komputer (basic input/ Output system)
291
292
Cost 100x 1X
294
PERBEZAAN
Sel ingatan terdiri drp
RAM STATIK
flip-flop
RAM DINAMIK
kapasitor
Data
Yang disimpan akan hilang walaupun bekalan kuasa masih ada apabila kapasitor dicas. Oleh itu, data perlu direfresh atau dicas semula pada sela masa tertentu
Tinggi- (4 kali ganda SRAM). Saiz unitnya lebih ringkas dan boleh dipadatkan di dalam 1 cip Rendah- (1/6 atau dr kuasa SRAM)
Ketumpatan
Penggunaan kuasa
Tinggi
295
PERBEZAAN
Format
RAM STATIK
RAM DINAMIK
Terdapat pelbagai Hanya terdapat dlm 1 format(1 bit, 1 byte, format 1 bit byte)- ini memudahkan sistem ingatan dibina dengan pantas
Kos perbit lebih tinggi Kos perbit rendah (1/4 atau 1/5 kos SRAM) Dalam bentuk cas-cas pada kapasitor Lebih rumit krn memerlukan litar tambahan utk refreshkan data
296
Kos
Maklumat disimpan Dlm bentuk bit-bit pada flip-flop Penggunaan kendalian Lebih mudah digunakan krn tidak memerlukan litar tambahan
Thava kumar A/L Devanayagam
PERBEZAAN
Kepantasan Litar
RAM STATIK
Lebih pantas Tidak kompleks
RAM DINAMIK
sederhana kompleks
297
0 1
addr
rows
memory controller (to CPU)
8 bits /
2 3
supercell (2,1)
data
0 0 1
rows 2 3
data
0 0 1
To CPU
memory controller supercell (2,1)
addr
rows
2
8 /
3 internal buffer
data
supercell (2,1)
Memory Modules
addr (row = i, col = j) : supercell (i,j)
DRAM 0
DRAM 7
bits bits bits bits bits bits bits 56-63 48-55 40-47 32-39 24-31 16-23 8-15
bits 0-7
63
56 55
48 47
40 39
32 31
24 23 16 15
8 7
Memory controller
64-bit doubleword
301
Enhanced DRAMs
All enhanced DRAMs are built around the conventional DRAM core. Fast page mode DRAM (FPM DRAM) Access contents of row with [RAS, CAS, CAS, CAS, CAS] instead of [(RAS,CAS), (RAS,CAS), (RAS,CAS), (RAS,CAS)]. Extended data out DRAM (EDO DRAM) Enhanced FPM DRAM with more closely spaced CAS signals. Synchronous DRAM (SDRAM) Driven with rising clock edge instead of asynchronous control signals. Double data-rate synchronous DRAM (DDR SDRAM) Enhancement of SDRAM that uses both clock edges as control signals. Video RAM (VRAM) Like FPM DRAM, but output is produced by shifting row buffer Dual ported (allows concurrent reads and writes)
302
PERBEZAAN
Data
ROM
Dibaca sahaja
RAM
boleh dibaca atau ditulis. Digunakan bagi menyimpan data secara sementara (ketika CPU memproses).
Penggunaan
Digunakan untuk menyimpan aturcara sistem yang telah di tulis secara kekal dan tidak boleh di ubah.
Jenis ingatan
tidak meruap iaitu kandungannya tidak hilang walaupun bekalan kuasa di putuskan.
Thava kumar A/L Devanayagam
303
bus interface
I/O bridge
Thava kumar A/L Devanayagam
main memory
304
F100
F100
305
F100
306
F100
307
CPU places address F100 on bus. Main memory reads it and waits for the corresponding data word to arrive.
register file ALU main memory 0 F100 Store operation: mov M, r
F100
308
309
Main memory read data word y from the bus and stores it at address F100.
register file Store operation: mov M, r
ALU
main memory F100 0
y
I/O bridge
bus interface
310
CONTROL BUS
CS
W/R
RD PROCESSOR
A2 0 0 0
A1 0 0 1
A0 0 1 0
A0
8X8
A1 A2
1 0
1 0
D0
D7
Address bus
D0
D7
1 0 1
Data bus
311
Read Transaction
(PC) (MAR) (MAR)
(Address bus) Select a particular memory location Issues RD control signals Reads instruction present in memory via database Will be placed in IR
313
Instruction present in IR will be decoded by which processor understand what operation it has to perform
Increments the contents of PC by 1, so that it points to the next instruction address
314
Write Transaction
Cont:-
MDR
From MDR data can be directly routed to ALU or it can be placed in register and then operation can be performed
Results of the operation can be directed towards output device, memory or register
Thava kumar A/L Devanayagam 315
KITAR AMBIL
1. 2.
KITAR BACA
Cpu hantar isyarat Bas tidak sibuk
Melalui bas kawalan, jika bas dlm keadaan sibuk, CPU akan berada dlm keadaan tunggu CPU akan letakkan alamat arahan pada bas alamat
Oleh litar dalam memori atau Alamat dinyahkod/terjemah antaramuka input/output Ditempatkan pada bas data Data pada alamat yg didapati
Thava kumar A/L Devanayagam 316
BAS ALAMAT
BAS DATA BAS KAWALAN
2
MEMORI
SISTEM BAS
1
PERMINTAAN LANGKAH 1 : BACA PERMINTAAN LANGKAH 2 : KIRIM ALAMAT
RAM
ROM
MPU
SISTEM BAS
PERMINDAHAN DATA
MPU
KITAR BACA
Thava kumar A/L Devanayagam 317
KITAR TULIS
Boleh Isyarat Jika bas data tidak sibuk CPU menghantar data kpd memori atau alat input/output. CPU akan kirim isyarat (meminta utk menulis) pada bas kawalan Data diletakkan pada bas data, di mana lokasi alamat akan ditempatkan pada bas alamat. CPU akan kirim data ke destinasi (alamat yang telah ditetapkan)
318
SISTEM BAS
MPU
PERMINTAAN
LANGKAH 1 : PERMINTAAN TULIS
Bas Alamat
3
Bas Data
SISTEM BAS
Bas kawalan
4 MEMORi
PEMINDAHAN DATA
MPU
RAM ROM
KITAR TULIS
Thava kumar A/L Devanayagam 319
KOMPONEN
JULAT (DECIMAL)
Jumlah
64K
0000 - FFFF
0 - 65535
320
KITAR PUNGUT
KITAR LAKSANA
322
KITAR PUNGUT
Mikropemproses mengambil satu suruhan dari ingatan dan mengisikannya ke dalam daftar suruhan (instruction register- IR). Daftar ini tidak kelihatan pada pengaturcara tetapi digunakan oleh Unit Kawalan untuk menentukan operasi yang perlu dilaksanakan.
323
KITAR NYAHKOD
Mikropemproses akan menentukan jenis suruhan yang terkandung di dalam daftar suruhan. Maklumat yang didapati dalam kitar ini diserahkan kepada kitar seterusnya.
324
KITAR LAKSANA
Mikropemroses melakukan apa yang disuruh oleh suruhan yang dipungut
325
Chapter 6
Masukan / Keluaran & Pengantaramukaan Input / Output & Interfacing
326
Masukan / Keluaran
327
1. Pemindahan terus
Peranti I/O Tidak perlu Pemindahan data Bersedia untuk menerima/memberi data Apa-apa isyarat keluaran sblm pemindahan data dilakukan Di bawah kawalan aturcara iaitu dgn bantuan arahan khusus spt IN atau OUT Mesin NC (numerical Controller) yang digunakan utk menggerudi. Masukan dalah bentuk kod berangka mudah dan keluaran adalah disambung terus ke penggerak
Contoh Penggunaan
328
2. Sampukan
Definisi sampukan Satu isyarat yang boleh dihantar pada bila-bila masa dan menyebabkan mikropemproses berhenti melakukan kerja untuk melayan isyarat sampukan tersebut. Perkakasan (hardware) yang mengizinkan peranti luar utk mendapatkan perhatian mikropemproses
Konsep
Contoh
Apabila kekunci komputer ditekan, mikropemproses akan memaksa operasi dalaman bercabang melompat ke suatu lokasi di mana terdapat satu susunan tatacara utk membaca papan kekunci tsbt.
Thava kumar A/L Devanayagam 329
Jenis sampukan
1. Maskable Interrupt Isyarat sampukan yand boleh diterima atau tidak oleh mikropemproses bergantung pada keutamaan menjalankan proses. 2. Nonmaskable Interrupt Isyarat sampukan mesti diterima oleh mikropemproses. 1. Utk memastikan alat I/O atau alat persisian menyampuk mikropemproses. 2. Utk mengurangkan masa dan kos dgn cara sampukan terjadi apabila mikropemproses menerima isyarat sampukan.
Kebaikan sampukan
330
INTERRUPTS IN 8085
Interrupt is a process where an external device can get the attention of the microprocessor.
The process starts from the I/O device The process is asynchronous.
Classification of Interrupts
INTERRUPTS IN 8085
Interrupts can also be classified into: Vectored (the address of the service routine is hard-wired) Non-vectored (the address of the service routine needs to be supplied externally by the device) An interrupt is considered to be an emergency signal that may be serviced.
332
INTERRUPTS IN 8085
The 8085 has 5 interrupt inputs. The INTR input. The INTR input is the only non-vectored interrupt. INTR is mask-able using the EI/DI instruction pair.
RST 5.5, RST 6.5, RST 7.5 are all automatically vectored. RST 5.5, RST 6.5, and RST 7.5 are all mask-able.
TRAP is the only non-mask-able interrupt in the 8085 TRAP is also automatically vectored.
333
INTERRUPTS IN 8085
Non vectored interrupts: The 8085 recognizes 8 RESTART instructions: RST0 RST7 . Each of these would send the execution to a predetermined hard-wired memory location:
Restart Instruction RST0 RST1 RST2 RST3 RST4 Equivalent to CALL 0000H CALL 0008H CALL 0010H CALL 0018H CALL 0020H
RST5
RST6 RST7
CALL 0028H
CALL 0030H CALL 0038H
334
INTERRUPT PRIORITY
Interrupt name TRAP RST 7.5 RST 6.5 RST 5.5 INTR Mask-able No Yes Yes Yes YES
Thava kumar A/L Devanayagam
SOD SDE XXX R7.5 MSE M7.5 M6.5 M5.5 RST5.5 Mask RST6.5 Mask RST7.5 Mask
0 - Available 1 - Masked
Mask Set Enable 0 - Ignore bits 0-2 1 - Set the masks according to bits 0-2
Not Used
SIM Instruction helps activate a particular interrupt. It can also mask a maskable interrupt.
Thava kumar A/L Devanayagam 336 336
SIM INSTRUCTION
Example: Set the interrupt masks so that RST5.5 is enabled, RST6.5 is masked, and RST7.5 is enabled. First, determine the contents of the accumulator.
- Enable 5.5 - Disable 6.5 - Enable 7.5 - Allow setting the masks - Dont reset the flip flop - Bit 5 is not used - Dont use serial data - Serial data is ignored bit 0 = 0 bit 1 = 1 bit 2 = 0 bit 3 = 1 bit 4 = 0 bit 5 = 0 bit 6 = 0 bit 7 = 0
EI MVI A, 0A SIM
; Enable interrupts including INTR ; Prepare the mask to enable RST 7.5, and 5.5, disable 6.5 ; Apply the settings RST masks
337
SDI P7.5 P6.5 P5.5 IE M7.5 M6.5 M5.5 RST5.5 Mask RST6.5 Mask RST7.5 Mask
Serial Data In RST5.5 Interrupt Pending RST6.5 Interrupt Pending RST7.5 Interrupt Pending
0 - Available 1 - Masked
Using the RIM instruction, it is possible to can read the status of the interrupt lines and find if there are any pending interrupts. Since the 8085 has five interrupt lines, interrupts may occur during an ISR and remain pending.
Thava kumar A/L Devanayagam 338
Kebaikan DMA
i.
ii.
Pemindahan data berlaku dgn pantas krn ia tidak perlu melalui mikropemproses. Kadar pemindahan data menggunakan DMA adalah di antara 10-50 Mbyte/sesaat. Mikropemproses boleh digunakan utk menjalankan fungsi/tugas lain semasa pemindahan data secara DMA dijalankan. INi menjimatkan masa pengguna.
Thava kumar A/L Devanayagam 339
iii. Dapat menghantar byk data dlm blok yang besar iv. Pemindahan data boleh dilakukan dgn cepat dari satu blok ingatan ke blok ingatan yang lain. v. Pemindahan data boleh dilakukan dari peranti terus ke ingatan tanpa melalui mikropemproses Keburukan DMA i. Perlu perkakasan tambahan iaitu DMAC untuk memantau pemindahan data antara alat persisian dengan ingatan Kos perkakasan tinggi Prestasi CPU akan sedikit terganggu krn penggunaan sistem bas CPU
ii. iii.
Contoh DMA
Menghubungkan pemacu cakera liut( floppy disk drive) dan sistem ingatan sekunder lain dgn ingatan utama RAM. IC DMA yang biasa digunakan untuk kawalan pemacu cakera liut ialah 8271. Bg mikropemproses 68000 ialah M68450.
340
I/O Bus
system bus
memory bus
bus interface
I/O bridge
main memory
I/O bus
USB controller
mouse keyboard
disk controller
disk
Thava kumar A/L Devanayagam 341
CPU chip
bus interface
CPU initiates a disk read by writing a command, logical block number, and destination memory address to a port (address) associated with disk controller.
main memory
I/O bus
disk controller
disk
Thava kumar A/L Devanayagam 342
Disk controller reads the sector and performs a direct memory access (DMA) transfer into main memory.
bus interface
main memory
I/O bus
USB controller
mouse keyboard
disk controller
disk
Thava kumar A/L Devanayagam 343
CPU chip
register file
When the DMA transfer completes, the disk controller notifies the CPU with an interrupt (i.e., asserts a special interrupt pin on the CPU)
bus interface
main memory
I/O bus
USB controller
mouse keyboard
disk controller
disk
Thava kumar A/L Devanayagam 344
DMA
345
8257 DMA
It is a 4 Channel DMA containing 4 individual I/P ,O/P Channels. CH0,CH1,CH2,CH3 It is compatible with Intel processors. The maximum frequency is 3 MHz. It executes 3 cycles: 1. DMA read 2. DMA write. 3. DMA verify. The external device can terminate DMA Operation
346
3. 4. 5.
Fixed priority mode: Each channel has a fixed priority and if higher priority channels are busy then smaller priority will get to serve. Extended write mode: This mode is used to interface slower devices to the system. TC stop mode: If this bit is set the channel whose terminal count is reached is disabled. Auto reload mode: If this bit is set data is transferred by channel 2 only. All other channels are not used.
347
Operasi
iii. iv.
Teknik memasukkan dan mengeluarkan data dari komputer selari atau siri
349
SERIAL COMMUNICATION
Serial Communications systems are of three types: Simplex: This is a one way communication. Only one party can speak. The other party only hears to the first one but cant communicate. System A System B
Transmitter
unidirectional
Receiver
350
SERIAL COMMUNICATION
System A
Transmitter/ Receiver
System B OR
Receiver/ Transmitter
Half Duplex: It is a two way communication between two ports provided that only party can communicate at a time.
SERIAL COMMUNICATION
Transmitter/ Receiver Receiver/ Transmitter.
OR/AND.
Full Duplex: It is a two way communication between two ports and both parties can communicate at same time. Thus here efficient communication can be established.
352
Perhantaran data
Kabel
Lebih cepat
Perlu kabel banyak, maka kos tinggi, oleh itu, hanya sesuai untuk jarak dekat < 100 kaki, contoh: sambungan antara komputer ke printer, monitor atau keyboard.
Digunakan bagi penghantaran data di dalam komputer iaitu di antara: CPU ke peranti I/O secara terus
353
Keburukan
1.
2.
3.
Kos yang tinggi disebabkan banyak wayar dan daftar-daftar Terjana noise (gangguan) jika penghantaran selari digunakan di antara komputer dengan peranti persisian. Sukar mengesan talian yang rosak
354
Keburukan
PENGHANTARAN SIRI
Teknik terbahagi 2: i. Teknik tak segerak ii. Teknik segerak Terdapat kod mula dan henti Penghantaran blok dalam satu masa
356
apabila menggunakan satu bit mula untuk penerima mengenal pasti permulaan aksara dan 1 atau 2 bit berhenti untuk tanda akhiran aksara
357
Apabila berhubung secara segerak alat penerima dan penghantaran disegerakkan oleh clock yang sama fasa dan kelajuannya. Data akan dihantar dalam bentuk blok. Penghantaran data segerak digunakan untuk penghantaran berhalaju tinggi, tanpa lengahan antara setiap elemen aksara.
Thava kumar A/L Devanayagam 358
TRANSMISSION FORMATS
Asynchronous 1. Synchronous It transfers group of characters at a time.
2. Used for transfer data rates <20KBPS 3. Start and stop bit for each character which forms a frame.
2. Used for transfer data rates >20KBPS 3. No start and stop bit for each character.
PERANTARAMUKA
Definisi perantaramuka Mengawal pergerakan data antara komputer dan peranti persisian (peripherals devices) seperti keyboard, printer, switches, display lamps dan plotter 1. 2. 3. PIA (Programmable Interface Adapter) PPI (Programmable Peripheral interface) PIT ( Parallel Interface Timer) UART (Universal asynchronous receiver/transmitter) ACIA (Asynchronous Communication Interface Adapter)
360
Fungsi UART
Menukarkan data selari yang dihasilkan oleh CPU pertama ke bentuk bersiri yang kemudiannya dihantar ke peranti penerima. Data bersiri ini perlu ditukar semula ke selari sebelum dihantar ke CPU kedua 1. Daftar anjakan, menukarkan data selari ke siri dan sebaliknya.
361
Fungsi ACIA
Pengkalan data siri di mana ia berfungsi sebagai perantaramuka di antara data siri dan selari 1. 2. Data masuk adalah siri Data disimpan di dlm daftara data sebelum dihantar serentak secara selari.
Data series input 7 6 5 4 3 2 1 0
Ciri-ciri ACIA
Contoh
1.
Isyarat dari peranti persisian adalah siri. Oleh krn pergerakan data dalam sistem mikropemproses adalah selari maka isyarat yang masuk ini perlulah ditukar ke bentuk selari sebelum diproses oleh CPU
362
Kabel penyambungan data bersiri yang digunakan secara meluas bagi menyambungkan peranti persisian dengan komputer. 1. 2. 3. Mempunyai 20 talian Biasanya hanya sedikit daripada talian-talian ini digunakan Menghubungkan peralatan pengkalan data (DTE Data terminal equipment) dengan peralatan penamatan litar data (DCE Data Communication Equipment). DCE ialah computer , DTE biasanya modem
Ciri-ciri ACIA
Contoh Rajah
1.
363
Generally EPROMS are used as program memory and RAM as data memory.
We can interface Multiple RAMs and EPROMS to single P .
A15
1
14 0
13 0
12 0
11 0
10 0
9 0
8 0
7 0
6 0
5 0
4 0
3 0
2 0
1 0
0 0
ADD 8000H
87FFH
365
366
8085
A15-A8
ALE
CS
A10- A0
AD7-AD0 Latch
A7- A0
WR RD
IO/M
D7- D0
RD WR
367
In partial decoding wastage of address takes place but it requires less hardware and cost is also less as compared with absolute one.
Thava kumar A/L Devanayagam 368
WR
A0-A1 CS Vcc , Gnd
I
I I I
Write input
Address pins Chip select +5volt supply
Thava kumar A/L Devanayagam 369
370
371
0
1 1
1
0 1
Port B
Port C Control Register
372
373
8255 MODES
Mode 0 : Simple I/O Any of A, B, CL and CH can be programmed as input or output Mode 1: I/O with Handshake A and B can be used for I/O C provides the handshake signals Mode 2: Bi-directional with handshake A is bi-directional with C providing handshake signals B is simple I/O (mode-0) or handshake I/O (mode-1) BSR (Bit Set Reset) Mode Only C is available for bit mode access. Allows single bit manipulation for control applications
375
CW
376
Then,we give A11,A12,A13 pins to A,B,C inputs of Decoder to enable 8255 or Chip Select. A15 is logic 1 so it is given to active HIGH G1 pin& A14 ,IO/M are given to active low G2B ,G2A pins. Output from Latch is given as A0,A1 pins to 8255 while D0D7 are given as data inputs.
Thava kumar A/L Devanayagam 377
A B C
PA
/CS
8085
ALE
(AD0-AD7)
3:8 decoder
8255 PB
O0 74373O1
A0-A7
A0 A1
O7 D7-D0
PC
RD WR
RD WR
378
379
380
8253 PIT
381
8253 Features
Three independent 16 bit counters. 24 pin Dual in line Package. Counting facility in Both BCD and Binary modes. Dc to 2 MHz operating Frequency. Can be used as a clock generator.
382
CONTROL WORD
D7 D0
M1
M0
RL0
BCD
Read/Load
0
0 1 1
0
1 0 1
Counter0
Counter1 Counter2
0 0
1
0 1
0
ILLEGAL 1
Thava kumar A/L Devanayagam
CONTROL WORD
M2
0 0 X X 1
M1
0 0 1 1 0
M0
0 1 0 1 0 Mode 0 Mode 1 Mode 2 Mode 3 Mode 4 BCD =0 Binary counter BCD =1 BCD counter
Mode 5
384
385
386
387
MICPROCESSOR 8 BIT (Intel 8085) I byte CPU and ALU architecture are those that are based on registers, address buses, or data buses of data size 8 bit data bus
MICPROCESSOR 16 BIT (Intel 8086) 2 byte CPU and ALU architecture are those that are based on registers, address buses, or data buses of data size 16 bit data bus
388