Notes On Microprocessor
Notes On Microprocessor
CHAPTER 1
MICROPROCESSORS, MICROCONTROLLERS, AND ASSEMBLY LANGUAGE
A microcontroller is a devices that has the functionalities of a microprocessor but also has on-chip
memory and i/o devices.
Microprocessors are typically used as CPUs of computers while microcontrollers are used in
embedded devices.
Each microprocessor has a fixed set of instructions in the form of binary patterns called a machine
language.
The binary instructions are given abbreviated names, called mnemonics, which form the assembly
language for a given microprocessor.
Microprocessors are classified according to their word length, viz. 8-bit microprocessors, 16-bit
microprocessors, 32-bit microprocessors, 64-bit microprocessors, etc.
Intel was developing a programmable calculator. The original design needed 12 different chips with
hardwired logic functions. Ted Hoff suggested a general-purpose chip that could perform various
logic functions which could be activated by providing patterns of 0s and 1s. Intel coined the term
microprocessor and in 1971 released the first microprocessor as the Intel 4004.
Evolution: 4004 4040 8008 8080 8085 8086 8088 80186 80188 80286
80386 80486 Pentium
[Section: 1.1]
2
CHAPTER 4
8085 MICROPROCESSOR ARCHITECTURE AND MEMORY INTERFACING
Address bus –
- A15-A8
Multiplexed address/data bus –
- AD7-AD0
Control and status signals –
- ALE - Address latch enable. A positive going pulse emitted at the beginning of
each operation (machine cycle) denoting that AD7-AD0 are now behaving as
address lines.
- !RD
- !WR
- IO/!M
- S1 and S0 - Status signals.
Machine cycle IO/!M S1 S0
Opcode fetch 0 1 1
Memory read 0 1 0
Memory write 0 0 1
I/O read 1 1 0
I/O write 1 0 1
Interrupt acknowledge 1 1 1
Halt Z 0 0
4
Flag register –
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
AC - If in an arithmetic operation a carry is generated by the bit D3 and passed onto the bit D4,
then the flag is set. The flag is used only internally for BCD operations and is not accessible
to the programmer.
P - If the result has even number of 1’s, then the flag is set.
Instruction cycle is defined as the time required to complete the execution of one instruction.
1 instruction cycle = 1 to 6 machine cycles.
Machine cycle is defined as the time required to complete one operation of accessing memory, i/o,
or acknowledging an external request.
1 machine cycle = 3 to 6 t-states.
T-state is defined as a subdivision of an operation performed in one clock period.
1 instruction = 4 to 18 t-states.
Exercise. Execution of the instruction MVI A, 32H stored in memory locations 2000-01H.
Solution. 2000H 3EH (opcode), 2001H 32H (operand).
Exercise. Execution of the instruction STA 2065H stored in memory locations 2010-12H.
Solution. 2010H 32H (opcode), 2011H 65H (low-order address), 2012H 20H (high-order
address).
M1: Opcode fetch.
M2: Memory read (low-order address).
M3: Memory read (high-order address).
M4: Memory write.
T1: Signal that it is a memory write cycle and place address on the address bus.
T2: Copy data from the accumulator and place it on data bus.
T3: Copy data to the memory.
Memory interfacing –
CHAPTER 5
INTERFACING I/O DEVICES
Exercise. Execution of the instruction OUT 01H stored in memory locations 2050-51H.
Solution. 2050H D3H (opcode), 2051H 01H (operand).
In memory-mapped i/o, the i/o devices are assigned and identified by 16-bit addresses.
To transfer data between the microprocessor and the i/o devices, memory-related instructions (LDA,
STA, MOV, etc.) and control signals (!MEMR and !MEMW) are used.
The microprocessor interacts with the i/o device as if it was one the memory locations.
CHAPTER 6
INTRODUCTION TO 8085 INSTRUCTIONS
Addressing modes –
- Implied e.g. - HLT, NOP, CMA
- Immediate e.g. - MVI, ADI, ANI
- Direct e.g. - LDA, STA
- Register e.g. - MOV, ADD, ANA
- Register indirect e.g. - LDAX, STAX, MOV, ADD
Exercise. Write a program to send the content of the register B to the output device with port address
FFH and then store the data 10H in the same register.
Arithmetic instructions –
ADD R 1-byte
ADI 8-bit 2-byte
SUB R 1-byte
SUI 8-bit 2-byte
INR R 1-byte
DCR R 1-byte
The arithmetic instructions affect the flag registers. However, INR and DCR do not affect the CY flag.
Exercise. Write a program to add 10H and 20H, increment the value by one, and then decrement the
value by two.
Logic instructions –
ANA R 1-byte
ANI 8-bit 2-byte
ORA R 1-byte
11
Exercise. Write a program to input a number using the device with port address FEH and output it
using the device with port address FFH only if the number is (a) equal to 10H and (b) greater than
10H.
CHAPTER 7
PROGRAMMING TECHNIQUES WITH ADDITIONAL INSTRUCTIONS
CHAPTER 8
COUNTERS AND TIME DELAYS
Exercise. Calculate the time delay inserted in a program by the following code.
MVI C, FFH
LOOP: DCR C
JNZ LOOP
Solution. Frequency = 3 MHz.
Instruction T-states Number of times executed Total clock periods
MVI 7 1 7
DCR 4 255 1020
JNZ (jump) 10 254 2540
JNZ (no jump) 7 1 7
Total 3574
Delay = 3574/(3x106) = 1.19 ms.
[Section: 8.1]
15
CHAPTER 9
STACK AND SUBROUTINES
The RST instructions are executed like call instructions. They are typically, but not always, used in
conjunction with interrupts.
RST0 1-byte Equivalent to CALL 0000H.
RST1 1-byte Equivalent to CALL 0008H.
RST2 1-byte Equivalent to CALL 0010H.
RST3 1-byte Equivalent to CALL 0018H.
RST4 1-byte Equivalent to CALL 0020H.
RST5 1-byte Equivalent to CALL 0028H.
RST6 1-byte Equivalent to CALL 0030H.
RST7 1-byte Equivalent to CALL 0038H.
Exercise. Write a subroutine to add three numbers and use it to write a program to add nine
numbers.
Exercise. Write a program to calculate the numbers of Fibonacci series less than hundred using
recursion.
CHAPTER 10
CODE CONVERSION, BCD ARITHMETIC, AND 16-BIT DATA OPERATIONS
ADC R/M
ACI 8-bit Add with carry
Add operand and CY to A
SBB R/M
SBI 8-bit Subtract with carry
Subtract operand and CY from A
Exercise. Write a program to copy a list stored in the memory locations 2001H through 200AH to
memory locations 2051H through 205AH using the XCHG instruction.
Exercise. Write a code fragment to jump to the address stored in the memory locations 2001-02H.
CHAPTER 12
INTERRUPTS
Interrupt-based I/O is a process of data transfer whereby an external device can inform the
processor that it is ready for communication and it requests attention.
The process is initiated by the external device.
The process is asynchronous, i.e. it can be initiated anytime without reference to the system clock.
The response to an interrupt is controlled by the microprocessor.
The microprocessor can ignore or delay a maskable interrupt request if it is performing some critical
task.
However, it has to respond to a non-maskable interrupt immediately.
The starting address of the interrupt service routine is implicitly defined in case of a vectored
interrupt.
The starting address has to be provided by external hardware in case of a non-maskable interrupt.
The Intel 8085 interrupt process is controlled by the Interrupt Enable flip-flop, which is internal to
the microprocessor and can be set or reset using software instructions.
If the Interrupt Enable flip-flop is enabled and the INTR pin (pin 10) goes high, then the
microprocessor is interrupted.
This is a maskable interrupt and can be disabled.
An RST instruction can be inserted by providing its opcode the low-order address bus.
For example, opcode of RST0 is C7H.
7 6 5 4 3 2 1 0
SOD SDE X R7.5 MSE M7.5 M6.5 M5.5
M7.5, M6.5 and M5.5: RST 7.5 mask, RST 6.5 mask and RST 5.5 mask. 0 = available and 1 = masked.
MSE: Mask set enable. 0 = bits 0-2 ignored and 1 = mask is set.
R7.5: Reset RST 7.5. 1 = ignore RST 7.5.
SDE: Serial data enable. 0 = ignore bit 7 and 1 = send bit 7 to serial output data latch.
SOD: Serial output data.
The interrupt process, except TRAP, can be disabled by resetting the Interrupt Enable flip-flop using
one of the follows.
- DI instruction
- System reset
- Recognition of an interrupt request
RST 7.5 is positive-edge sensitive and can be triggered with a short pulse.
The request is stored internally until the microprocessor responds to the request or until it is cleared
by reset or by bit 4 in SIM instruction.
When one interrupt is being served, other interrupt requests may occur and remain pending.
The RIM instruction is used to detect pending interrupts.
7 6 5 4 3 2 1 0
SID I7.5 I6.5 I5.5 IE M7.5 M6.5 M5.5
M7.5, M6.5 and M5.5: Interrupt masks. 0 = available and 1 = masked.
IE: Interrupt enable. 0 = disable and 1 = enable.
I7.5, I6.5 and I5.5: Pending interrupts. 0 = not pending and 1 = pending.
SID: Serial input data.
Exercise. The microprocessor is completing an RST 7.5 request. Check if RST 6.5 is pending. If yes, then
enable RST 6.5 else return to the main program.
Solution.
RIM
MOV B, A
ANI 20H ; check is RST 6.5 is pending
JNZ NEXT
EI
RET ; return to main program
NEXT: MOV A, B ; get bit pattern
ANI 0DH ; enables RST 6.5
ORI 08H ; enable mask
SIM
JMP SERV ; jump to RST 6.5 service routine
CHAPTER 14
PROGRAMMABLE INTERFACE DEVICES
Seven-segment display –
HP5082/7340
Components –
- 256 bytes R/W static RAM
- I/O ports
- Two 8-bit parallel ports (Port A and Port B)
- One 6-bit parallel port (Port C)
- Timer
- 14-bit down-counter
22
IO/!M: If high, then ports and timer selected, else memory is selected.
Addresses –
XXXXX000: Control/status register
XXXXX001: Port A
XXXXX010: Port B
XXXXX011: Port C
XXXXX100: Timer LSB
XXXXX101: Timer MSB
Control word –
D7 D6 D5 D4 D3 D2 D1 D0
D1, D0: Port B, Port A. 0 = input, 1 = output.
D3-D2: Port C. 00 = ALT1, 11 = ALT2, 01 = ALT3, 10 = ALT4.
D5, D4: Interrupt enable. Port B, Port A. 0 = disable, 1 = enable.
D7-D6: Timer command. 00 = no effect, 01 = stop, 10 = stop after terminal count, 11 = start.
PC5 PC4 PC3 PC2 PC1 PC0
ALT1 I I I I I I
ALT2 O O O O O O
ALT3 O O O !STBA BFA INTRA
ALT4 !STBB BFB INTRB !STBA BFA INTRA
Exercise. Display the number 1857H using four seven-segment displays connected to ports A and B.
Assume that Intel 8155 has an address 00100XXX.
Solution.
MVI A, 03H
OUT 20H
MVI A, 18H
OUT 21H
MVI A, 57H
23
OUT 22H
HLT
Timer –
MSB
M2 M1 T13 T12 T11 T10 T9 T8
LSB
T7 T6 T5 T4 T3 T2 T1 T0
Mode 0: !TIMER OUT = 1 for first N/2, = 0 for last N/2.
Mode 1: Continuous version of Mode 0. (Square wave)
Mode 2: !TIMER OUT = 1 for first N-1, = 0 for last 1.
Mode 3: Continuous version of Mode 2.
Output
Status word –
X TI INTEB BFB INTRB INTEA BFA INTRA
TI: Set on reaching terminal count. Reset on reading status word and by hardware reset.
Keyboard section
Can be connected to 64-contact key matrix with an interrupt generated for each key press.
RL0-RL7: Return lines. Connected to eight columns of keyboard.
The keys are automatically debounced.
The keyboard can operate in two modes –
- Two-key lockout mode: If two keys are pressed in quick succession, then only the first is
recognized.
- N-key rollover mode: Codes of simultaneously pressed keys are stored in buffer; it can be
specified that no other key is recognized till one key remains pressed.
8 byte FIFO RAM: Store eight keyboard entries.
Scan section
SL0-SL3: Scan lines. Decoded in 16 lines using a 4-to-16 decoder.
Those lines can be connected to rows of keyboard or drivers of displays.
Display section
Can be connected to a 16-character display interface with devices like LEDs.
The display can be set up in either left-entry or right-entry format.
OUT A0 - OUT A3 and OUT B0 - OUT B3: Can be used as together or separately.
!BD: Blank display.
16 byte R/W RAM.
Interface section
A0 is low for data, high for control or status.
IRQ goes high when there is data in FIFO RAM.
Port addresses
XXXXXXX0: Data port
XXXXXXX1: Command/status port
Control word –
- Keyboard/display mode set: 000DDKKK
DD = 00 for 8 character display – left entry
KKK = 000 for encoded scan keyboard – 2-key lockout
- Program clock: 001PPPPP
The external clock signal is divided by PPPPP, 2 < PPPPP < 31.
- Read FIFO RAM: 010[AI]XAAA
AI = autoincrement mode, AAA = address.
- Read Display RAM: 011[AI]AAAA
- Write Display RAM: 100[AI]AAAA
CHAPTER 15
GENERAL PURPOSE PROGRAMMABLE PERIPHERAL DEVICES
Modes –
- Bit Set/Reset (BSR) mode: set or reset bits in port C
- I/O mode –
- Mode 0: all ports function as simple i/o ports
- Mode 1: ports A and B use pits of port C for handshake
- Mode 2: port A is used as a bidirectional port using pits of port C and port B is used
in mode 0 or mode 1
27
Port addresses –
A1A0 = 00: Port A
A1A0 = 01: Port B
A1A0 = 10: Port C
A1A0 = 11: Control register or status register
Mode 0 –
Control word: D7 D6 D5 D4 D3 D2 D1 D0
D7: 0 = BSR mode, 1 = I/O mode
D6D5: Port A. 00 = mode 0, 01 = mode 1, 1x = mode 2
D4: Port A. 0 = output, 1 = input
D3: Port CU. 0 = output, 1 = input
D2: Port B. 0 = mode 0, 1 – mode 1
D1: Port B. 0 = output, 1 = input
D0: Port CL. 0 = output, 1 = input
Exercise. Write a program to copy from ports B and CL to ports A and CU, respectively.
Solution.
MVI A, 83H
STA 8003H
LDA 8001H
STA 8000H
LDA 8002H
ANI 0FH
RLC
RLC
RLC
RLC
STA 8002H
HLT
BSR Mode –
Control word: D7 X X X D3 D 2 D1 D0
D7: 0 = BSR mode
D3D2D1: Port C. 000 = bit 0, 001 = bit 2, … 111 = bit 7
D0: 0 = reset, 1 = set
Exercise. Write a program to set bits 0 and 2 and reset bits 1 and 3 of Port C.
Mode 1 –
Input mode Output mode
PC4 !STBA PC7 !OBFA
PC5 IBFA PC6 ACKA
PC3 INTRA PC3 INTRA
PC2 !STBB PC1 !OBFB
PC1 IBFB PC2 ACKB
PC0 INTRB PC0 INTRB
PC6,7 I/O PC4,5 I/O
Status word: Status word:
X X IBFA INTEA INTRA IBFB INTEB INTRB !OBFA INTEA X X INTRA INTEB !OBFB INTRB
28
Exercise. Write a program to accept inputs from a keyboard connected to port A and send outputs to
the printer connected to port B using handshaking.
Mode 2 –
Bidirectional data transfer.
PC3 INTRA
PC7 !OBFA
PC6 !ACKA
PC4 !STBA
PC5 IBFA
PC0-2 I/O
Port addresses –
A1A0 = 00: Counter 0
A1A0 = 01: Counter 1
A1A0 = 10: Counter 2
A1A0 = 11: Control register
Mode 0: Interrupt on terminal count. Initially OUT is low. A count is loaded and decremented every
cycle. When count reaches 0, OUT goes high. OUT remains high till a new count or control
word is loaded. Counting can be suspended by disabling Gate and resumed on enabling it.
Mode 1: Hardware re-triggerable one-shot. OUT is initially high. When Gate is triggered, OUT goes
low. At the end of the count, OUT goes high.
Mode 2. Rate generator. Used to generate a pulse equal to the clock period at a given interval.
Then a count is loaded. OUT stays high till count reaches 1 and then goes low for one clock
period. The count is reloaded automatically and pulse is generated continuously. A count =
1 is illegal.
Mode 3. Square-wave generator. When a count is loaded, OUT goes high. Count is decremented by
2 in every clock cycle. When count reaches zero, OUT goes low. The count is reloaded
automatically. Frequency of square wave is equal to clock frequency divided by count. If
count is odd, pulse stays high for the extra clock cycle.
Mode 4. Software-triggered strobe. OUT is initially high. It goes low for one clock period at the end
of the count. The count has to be reloaded.
Mode 5. Hardware-triggered strobe. Same as mode 4 except triggered by rising pulse at gate.
Exercise. Write code to generate a pulse every 50 µs. Assume frequency of 8254 be 2 MHz.
Solution. Count = 50 x 10-6 x 2 x 106 = 100 = 64H.
MVI A, 14H
30
OUT 83H
MVI A, 64H
OUT 80H
Exercise. Write code to generate 1 KHz square-wave. Assume frequency of 8254 be 2 MHz.
Solution. Count = (2 x 106) / (1 x 103) = 2000 = 07D0H.
MVI A, 76H
OUT 83H
MVI A, D0H
OUT 81H
MVIA, 07H
OUT 81H
Working –
The opcode of the CALL instruction is written on the lower-order data bus.
The microprocessor decodes the opcode and understands that it is a CALL instruction.
The address is then placed on the data bus.
The program control is transferred to the given address.
CHAPTER 16
SERIAL I/O AND DATA COMMUNICATION
Exercise. Input an ASCII character through the serial input port. If the character is a lower case letter,
then convert it to higher case and send it to the serial output port. Enter a delay between reading or
writing two consecutive bits.
Sample interfacing –
Intel 8085 Intel 8051
D0-D7 ↔ D0-D7
A0 ↔ C/!D
A1-A7 ↔ !CS
!IOW ↔ !WR
!IOR ↔ !RD
!IOW ↔ !WR
RESET OUT ↔ RESET
CLK (OUT) ↔ CLK
Exercise. Write a program to transmit a message using Intel 8251. The number of bytes in the
message is stored in 2070H and the message is stored in memory locations starting at 2071H.
Solution.
LXI H, 2070H
MVI A, CAH ; initialize 8251
OUT FFH
MVI A, 11H
OUT FFH
LOOP: IN FFH ; check if transmitter ready
ANI 01H
JZ LOOP
INX H
MOV A, M
OUT FEH
DCR C
35
JNZ LOOP
HLT
[Full version]
[Last revised on 31 March 2016]