Documente Academic
Documente Profesional
Documente Cultură
Computer
5. HLT
-stops clock
-Load 25 in accumulator
-Subtract 9 from 25
-Add 10 with the result
-Subtract 18
-Show output
= 00 1 1 1 1 1 0 0011
=3E3 H
T2:Increment State
NOP
Simple As Possible
Computer
(SAP-2)
Block Diagram
1
3/14/2016
Input Port
Two input ports, numbered 1 & 2
Hexadecimal keyboard encoder is
connected to port 1 and also sends READY
signal to bit 0 of port 2 and SERIAL_IN to bit
7 of port 2
Program Counter
PC has 16 bits
Can count from
PC=0000 0000 0000 0000 (0000H)
to
PC=1111 1111 1111 1111 (FFFFH)
2
3/14/2016
3
3/14/2016
Instruction Register
• SAP-2 has total 42 (101010) instructions.
So we will use 8 bit op-codes
Controller/Sequencer
4
3/14/2016
Accumulator
Two state output goes to ALU and three state
output to W bus
5
3/14/2016
Output Port
Two output ports, numbered 3 & 4
Contents of accumulator is loaded into
port 3, which drives a hexadecimal
display
Port 4 has SERIAL_OUT signal to its 0 bit
and ACKNOWLEDGE signat to its 7 bit
6
3/14/2016
7
3/14/2016
LDA address
LDA 8000H : Load the accumulator with the
content of address 8000H
LDA 8000H
T1 State: Address State
Output of PC is
2000H
2000H is sent to the
W bus
MAR loads 2000H
The content of
address 2000H of
RAM is available
Md. Shafiqul Islam
EEE 315: MICROPROCESSOR & INTERFACING
3/13/2016 Lecturer, Dept of EEE, BUET
8
3/14/2016
LDA 8000H
T2 state: Increment
State
PC has increased its
value to 2001H
2001H is now
available at PC’s
output
LDA 8000H
T3 State: Memory State
MDR enables the
content of RAM
address to W bus
IR loads the content
9
3/14/2016
LDA 8000H
Execution Cycle: T4
LDA 8000H
Execution Cycle: T5
PC increases its
output to 2002H
Content of address
2001H is enabled to
W bus and loaded to
B register
10
3/14/2016
LDA 8000H
Execution Cycle: T6
PC’s output 2002H is
enabled to W bus
Content of W bus is
loaded to MAR
LDA 8000H
Execution Cycle: T7
PC increases its
value to 2003H
Content of 2002H is
enabled to W bus
and loaded to C
register
11
3/14/2016
LDA 8000H
Execution Cycle: T8
Contents of B & C
registers are enabled
to W bus to create
the 16 bit address
8000H
16 bit address is then
loaded to MAR
LDA 8000H
Execution Cycle: T9
Content of memory
address 8000H is
enabled to W bus
Content of W bus is
loaded to the
Accumulator
12
3/14/2016
JUMP Instruction
Instead of fetching
the next instruction
in the usual way,
jumps to another part
of program, e.g.
JMP 3000H
Unconditional Jump
JUMP Instruction
JM 3000H : Jump to
address 3000H if the
sign flag is 1 (content
of accumulator is -ve)
Otherewise fetch the
next instruction at
2006H
Conditional Jump
13
3/14/2016
14
3/14/2016
Thank You
15
3/15/2016
Simple As Possible
Computer
(SAP-3)
1
3/15/2016
SAP-2 Stack
Stack is a portion of
memory set assigned
primarily for saving
return address
2
3/15/2016
Stack Instructions
Instructions that are read and write into the stack
are called stack instruction
CALL address and RET
PUSH register: Contents of the register have to
be stored in the stack
POP register: Contents of a specific stack
memory have to be restored in the register
Stack Pointer
16-bit register that
holds the desired
memory location of
20FC H stack which is
20FD H available is called
20FE H
SP Stack pointer (SP)
20FF H
SP points 20FF H,
means we can write
address at that
location
Md. Shafiqul Islam
EEE 315: MICROPROCESSOR & INTERFACING
3/15/2016 Lecturer, Dept of EEE, BUET
3
3/15/2016
Stack Pointer
00H is stored in 20FF
H memory
20FC H
20FD H
20FE H
SP
20FF H 00 H
Stack Pointer
SP now points 20FE
H, means 20FE H is
available to store a
20FC H new value
20FD H
SP
20FE H
20FF H 00 H
4
3/15/2016
Stack Pointer
20H is then stored in
20FE H address
20FC H
20FD H
SP
20FE H 20 H
20FF H 00 H
Stack Pointer
20FC H
SP
20FD H
20FE H 20 H
20FF H 00 H
5
3/15/2016
20FC H
20FD H
SP
20FE H 20 H
20FF H 00 H
Stack Pointer
20FC H
20FD H
SP
20FE H
20FF H 00 H
6
3/15/2016
Stack Pointer
20FC H
20FD H
20FE H
SP
20FF H 00 H
Stack Pointer
20FC H
20FD H
20FE H
SP
20FF H
7
3/15/2016
Thank You
8
Intel 8086
Architecture
Fourth Generation
During 1980s
Third Generation Low power version of HMOS technology
During 1978 (HCMOS)
HMOS technology Faster speed, Higher 32 bit processors
packing density Physical memory space 224 bytes = 16 Mb
16 bit processors 40/ 48/ 64 pins Virtual memory space 240 bytes = 1 Tb
Easier to program Floating point hardware
Dynamically relatable programs Supports increased number of addressing
Processor has multiply/ divide arithmetic modes
hardware
More powerful interrupt handling Intel 80386
capabilities
Flexible I/O port addressing Second Generation
During 1973
Intel 8086 (16 bit processor) NMOS technology Faster speed, Higher
density, Compatible with TTL
4 / 8/ 16 bit processors 40 pins
First Generation Ability to address large memory spaces
Between 1971 – 1973 and I/O ports
PMOS technology, non compatible with TTL Greater number of levels of subroutine
4 bit processors 16 pins nesting
8 and 16 bit processors 40 pins Better interrupt handling capabilities
Due to limitations of pins, signals are
multiplexed Intel 8085 (8 bit processor)
2
Md. Ayaz Masud
EEE 315: MICROPROCESSOR & INTERFACING
4/4/2016 Lecturer, Dept of EEE, BUET
Key Features
• First introduced in 1978
• 16 bit microprocessor with 16 bit bus
• Main memory of 1 MB
• 5 MHz
• 6 Byte instruction cache
• 117 instructions
• 64kB i/o ports
Instruction decoding
unit
Flag Register
Timing and
control unit PC/ IP
15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
U U U U OF DF IF TF SF ZF CF AF U PF U CF
• Machine Language
• Assembly Language
• High-Level Language
Example:
MYLABEL : MOV AX,BX ; abrakadabra
MYBYTE DB 15
MYWORD DW ?
MYARRAY DB 4,5,6,?,?,?
MYSTRING DB ‘abrakadabra’
Md. Ayaz Masud
EEE 315: MICROPROCESSOR & INTERFACING
4/4/2016 Lecturer, Dept of EEE, BUET
Named Constant
MYCONSTANT EQU 5
• EQU is a pseudo-opcode
• Constant can be a string as well
Source Destination
Operand Operand
General Memory
Register Location
General
Register
Memory X
Location
INC AX ; ax++
DEC MYBYTE; mybyte - -
Md. Ayaz Masud
EEE 315: MICROPROCESSOR & INTERFACING
4/4/2016 Lecturer, Dept of EEE, BUET
NEG
• Single operand instruction
• NEG destination
• Destination is either a register or a
memory location.
• Updates all flags
CF=1 unless result is 0
OF=1 if word destination is 8000h or
byte destination is 80h
Md. Ayaz Masud
EEE 315: MICROPROCESSOR & INTERFACING
4/4/2016 Lecturer, Dept of EEE, BUET
Type Agreement of Operands
• The operands of preceding two operand
instructions must be of the same type
ORG 1000H
ORG $+1000H
ORG 1600H
MYWARRAY DW 1,2,0ABCDH,?
ORG 1000H
MYWARRAY DW 1,2,0ABCDH
-creates ambiguity
-PTR assembler directive is used to solve it
MY2DARRAY DB 1,2,3,4,5,6,7,8,9
MY2DARRAY DB 1,4,7,2,5,8,3,6,9
Md. Ayaz Masud
EEE 315: MICROPROCESSOR & INTERFACING
4/4/2016 Lecturer, Dept of EEE, BUET
2D Array
For a M x N array A declared in Row Major Format,
When the result of an operation falls beyond this range, an overflow occurs
• Signed Overflow
• Unsigned Overflow
Unsigned Signed
Interpretation Interpretation
8086 Operation:
Unsigned Signed
Interpretation Interpretation
1 1 0 1 1 0 1 1 0 0
1 0 1 1 0 1 1 0 0
0 1 1 0 1 1 0 0 0
1 1 0 1 1 0 1 1 0 0
1 0 1 1 0 1 1 0 0
0 1 1 0 1 1 0 0 0
Shift Right
CF
0 1 1 0 1 1 0 1 1
0 1 1 0 1 1 0 1 1
0 0 0 1 1 0 1 1 0 1
0 0 0 1 1 0 1 1 0
MSB 1 1 1 0 1 1 0 1 1
Retains 1 1 1 1 0 1 1 0 1
Value 1 1 1 1 1 0 1 1 0
CF 1 1 0 1 1 0 1 1
1 1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1 1
0 1 1 0 1 1 1 1 0
Rotate Right
1 1 0 1 1 0 1 1 CF
1 1 1 0 1 1 0 1 1
1 1 1 1 0 1 1 0 1
0 1 1 1 1 0 1 1 0
CF 1 1 0 1 1 0 1 1
0
1 1 0 1 1 0 1 1 0
1 0 1 1 0 1 1 0 1
0 1 1 0 1 1 0 1 1
0 1 1 0 1 1 0 1 1
1 0 1 1 0 1 1 0 1
1 1 0 1 1 0 1 1 0
CALL PROC1
next instruction
PROC1 PROC
first instruction
RET
AL=80 H, BL=FF H
Instruction Decimal Hex AH AL CF/OF
Product Product
MUL BL 32640 7F80 7F 80 1
IMUL BL 128 0080 00 80 1
Syntax:
DIV divisor (for unsigned multiplication)
IDIV divisor (for signed multiplication)
The quotient and the remainder have the same
size as the divisor.
All the flags are undefined
Divide Overflow: If the quotient is too long to fit
in the destination, program terminates and the
system displays the message “Divide Overflow”
NOT A+2
NOT A
ADD A, 1
ADC A+2, 0
1. AX ← A
2. DX:AX ← AX×BX
3. C ← AX
4. TEMP ← DX
5. AX ← A+2
6. DX:AX ← AX×BX
7. AX ← AX+TEMP
8. C+2 ← AX
9. DX ← DX+C (Carry)
10. C+4 ← DX
1. DX:AX ← A+4:A+2
2. Quotient AX, Remainder DX← DX:AX÷BX
3. Q+2 ← AX
4. AX ← A
5. Quotient AX, Remainder DX← DX:AX÷BX
6. Q ← AX, R ← DX
EEE 315: MICROPROCESSOR & INTERFACING
5/2/2016
Binary-Coded Decimal Numbers
The BCD (binary coded decimal) number
system uses four bits to code each decimal
digit, from 0000 to 1001. The combinations
1010 to 1111 are illegal in BCD.
Since only 4 bits are required to represent a
BCD, two digits can be placed in a byte. This
is known as packed BCD form(59=
01011001).
In unpacked BCD form, only one digit is
contained in a byte(59=
0000010100001001).
EEE 315: MICROPROCESSOR & INTERFACING
5/2/2016
BCD Addition
In BCD addition, we perform the addition on one
digit at a time.
When addition performed using ADD
instruction, it is possible to obtain a non-BCD
result.
For example if AL= 6d and BL=7d, the sum of 13
is in AL which is no longer a valid BCD digit.
To adjust it is required to subtract 10 from AL and
place 1 in AH, then AX will contain the correct
sum.
We can get the same result by adding 6 to AL
and clearing the high nibble.
EEE 315: MICROPROCESSOR & INTERFACING
5/2/2016
BCD Addition
This adjustment is performed in 8086 if we add
the instruction AAA (ASCII Adjust for addition).
AAA checks the lower nibble of AL. If it is greater
than 9 or the AF is set, then AAA adds 6 to AL,
clears the high nibble and adds 1 to AH.
The following assembly code performs decimal
addition on the unpacked BCD numbers in AL
and BL.
MOV AH, 0
ADD AL, BL
AAA
MOV AH, 0
SUB AL, BL
AAS
EEE 315: MICROPROCESSOR & INTERFACING
5/2/2016
BCD Multiplication
Two BCD digits can be multiplied to
produce one or two-digit product.
The product may not be a BCD digit.
AAM (ASCII Adjust for multiplication)
converts the result into BCD digits.
We put multiplicand in AL and multiplier
in BL, after multiplication AX contains the
product.
EEE 315: MICROPROCESSOR & INTERFACING
5/2/2016
BCD Multiplication
AAM divides the contents of AL by 10,
the quotient is placed in AH and
remainder is placed in AL
MOV AL, 9D
MOV BL, 8D
MUL BL ; AX=72D
AAM ; AH=07D and AL=02D
EEE 315: MICROPROCESSOR & INTERFACING
5/2/2016
BCD division
Convert the dividend in AX from to BCD
digits to their binary equivalent.
Do ordinary division, which puts quotient
in AL and remainder in AH.
Convert the binary quotient in AL to its
two digit equivalent in AX
AAD
DIV BL
MOV R, AH ; Remainder
AAM ; CONVERTING THE QUOTIENT TO BCD FOR
Example:
Example: