Documente Academic
Documente Profesional
Documente Cultură
at Behavioral Level
We use the Intel 8085 all time popular 8-bit processor as an
example.
A complete functional Verilog model for the Intel 8085 will be
presented.
Lecture outline
1. review the architecture, chip layout, pin definition
2. instruction set
3. 8085 Verilog models
4. 8085 Verilog test bench.
1
S0, S1 (Output)
READY (Input)
If Ready is high during a read or write cycle, it indicates that the memory
or peripheral is ready to send or receive data.
If Ready is low, the CPU will wait for Ready to go high before
completing the read or write cycle.
S1 S0
0 0
0 1
1 0
1 1
HALT
WRITE
READ
FETCH
HOLD (Input)
RD (Output 3state)
HOLD; indicates that another Master is requesting the use of the Address
and Data Buses. The CPU, upon receiving the Hold request. will relinquish
the use of buses as soon as the completion of the current machine cycle.
Internal processing can continue. The processor can regain the buses only
after the Hold is removed.
When the Hold is acknowledged, the Address, Data, RD, WR, and IO/M lines
are 3stated.
HLDA (Output)
TRAP (Input)
HOLD ACKNOWLEDGE; indicates that the CPU has received the Hold request
and that it will relinquish thebuses in the next clock cycle.
HLDA goes low after the Hold request is removed.
The CPU takes the buses one half clock cycle after HLDA goes low.
RESTART INTERRUPTS;
These three inputs have the same timing as INTR except they cause
an internal RESTART to be automatically inserted.
Name
TRAP
RST 5.5
RST 6.5
RST 7.5
2416
2C16
3416
3C16
RESET IN (Input)
Reset sets the Program Counter to zero and resets the Interrupt Enable
and HLDA flip flops.
IO/M (Output)
reg [8:1]
dflags;
initial
dflags = 0;
// diag flags:
// 1 = printmem
// 2 = dump state at end
// 3 = test reset control
// 4 = monitor the transmit and receive lines
wire
tri[7:0]
tri1
ad, a;
read, write, iomout;
reg
CLK (Output)
Clock Output for use as a system clock
module intel_8085a
(clock, x2, resetff, sodff, sid, trap,
rst7p5, rst6p5, rst5p5, intr, intaff,
ad, a, s0, aleff, writeout, readout, s1,
iomout, ready, nreset,
clockff, hldaff, hold);
reg [8:1]
dflags;
initial
dflags = 'b000;
// diag flags:
// 1 = trace instructions
// 2 = trace IN and OUT instructions
// 3 = trace instruction count
output
resetff, sodff, intaff, s0, aleff,
writeout, readout, s1, iomout, clockff, hldaff;
initial
begin
$write("\n");
..
..
endmodule
10
11
12
reg[15:0]
pc,
sp,
addr;
reg[8:0]
intmask;
reg[7:0]
acc,
regb,
regc,
regd,
rege,
regh,
regl,
ir,
data;
reg
aleff,
s0ff,
s1ff,
hldaff,
holdff,
// program counter
// stack pointer
// address output
intaff,
trapff,
trapi,
inte,
int,
validint,
haltff,
resetff,
clockff,
sodff,
read,
write,
iomff,
acontrol,
dcontrol,
s,
cs,
cz,
cac,
cp,
cc;
// accumulator
// general
// general
// general
// general
// general
// general
// instruction
// data output
// address latch enable
// status line 0
// status line 1
// hold acknowledge
// internal hold
13
14
Registers: A, B, C, D, E, H, L
Register pairs: BC, DE, HL
Symbols and abbreviations used in Assembly language
accumulator
Register A
addr
16-bit address
data
8-bit data
data 16
16-bit data
byte 2
the second byte of the instruction
byte 3
the third byte of the instruction
port
8-bit address of an I/O device
r, r1, r2
one of the registers A, B, C, D, E, H, L
DDD, SSS
destination, source
rp
register pair
( )
the contents of the memory location or register
enclosed in the parentheses
// interrupt acknowledge
// trap interrupt request
// trap execution for RIM instruction (RIM:read interrupt mask)
// previous state of interrupt enable flag
// interrupt acknowledge in progress
// interrupt pending
// halt request
// reset output
// clock output
// serial output data
// read request signal
// write request signal
// i/o memory select
// address output control
// data output control
// data source control
// sign condition code
// zero condition code
// aux carry condition code
// parity condition code
// carry condition code
For examples
IN 5
OUT 1
15
16
LDA addr
(A) ((byte 3) (byte 2))
STA addr
((byte 3)(byte 2)) (A)
example:
LDA First
STA First
LHLD addr
//load H and L direct
(L) ((byte3) (byte 2))
(H) ((byte 3) (byte 2) + 1)
SHLD addr
//store H and L direct
((byte 3)(byte 2)) (L)
((byte 3)(byte 2) + 1) (H)
MOV r, M
(r) ((H)(L))
example
MOV B, M
MOV M, r
//store r in memory
LDAX rp
(A) ((rp))
STAX rp
((rp)) (A)
MVI r, data
(r) (byte 2)
//move immediate
MVI M, data
((H)(L)) (byte 2)
17
18
19
20
7: doinc(acc); // INR A
endcase
endtask
22
/* calculate cp cs and cz */
task calpsz;
input[7:0] tr;
begin
cp = ^tr;
//parity, ^Exclusive or all bits of tr
cz = tr == 0; //zero flag
cs = tr[7];
//sign flag
end
endtask
23
24
6: // STA
begin
adread(ra);
memwrite(acc, ra);
end
7: // LDA
begin
adread(ra);
memread(acc, ra);
end
endcase
endtask
/* fetch address from pc+1, pc+2 */
task adread;
output[15:0] address;
begin
memread(address[7:0], pc);
pc = pc + 1;
memread(address[15:8], pc);
if(!int) pc = pc + 1; // if interrupt is not true, pc = pc+1
end
endtask
/* memory read */
task memread;
output[7:0] rdata;
input[15:0] raddr;
begin
@(posedge clock)
addr = raddr;
s = 0;
acontrol = 1;
dcontrol = 1;
iomff = int;
s0ff = int;
s1ff = 1;
aleff = 1;
@(posedge clock)
aleff = 0;
@(posedge clock)
dcontrol = 0;
if(int)
intaff = 0;
else
read = 0;
@(posedge clock)
ready_hold;
checkint;
@(posedge clock)
intaff = 1;
read = 1;
rdata = ad;
if(holdff) holdit;
end
endtask
25
26
CMA
(A) (A)
CMC
(CY) (CY)
@(posedge clock)
data = wdata;
write = 0;
s = 1;
@(posedge clock)
ready_hold;
checkint;
STC
ANI data
ANA r
ANA M
ORI
ORA r
ORA M
XRI data
XRA r
XRA M
CPI data
CMP r
CMP M
@(posedge clock)
write = 1;
if(holdff) holdit;
end
endtask
27
RLC
rotate accumulator left
(CY) A7;
A0 A7;
An+1 An
RRC
rotate accumulator right
(CY) A0;
A7 A0;
An An+1
RAL
RAR
SBI data
INR r
INR M
DCR r
DCR M
INX rp
DCX rp
increment register
increment memory
decrement register
decrement memory
increment register pair
decrement register pair
DAD rp
DAA
29
/* operate on accumulator */
task doacci;
input[7:0] sr;
reg[3:0] null4;
reg[7:0] null8;
case(ir[5:3])
0: // ADD ADI
begin
{cac, null4} = acc + sr;
{cc, acc} = {1'b0, acc} + sr;
calpsz(acc);
end
1: // ADC ACI
begin
{cac, null4} = acc + sr + cc;
{cc, acc} = {1'b0, acc} + sr + cc;
calpsz(acc);
end
30
5: // XRA XRI
begin
acc = acc ^ sr;
cac = 0;
cc = 0;
calpsz(acc);
end
2: // SUB SUI
begin
{cac, null4} = acc - sr;
{cc, acc} = {1'b0, acc} - sr;
calpsz(acc);
end
3: // SBB SBI
begin
{cac, null4} = acc - sr - cc;
{cc, acc} = {1'b0, acc} - sr - cc;
calpsz(acc);
end
4: // ANA ANI
begin
acc = acc & sr;
cac = 1;
cc = 0;
calpsz(acc);
end
31
6: // ORA ORI
begin
acc = acc | sr;
cac = 0;
cc = 0;
calpsz(acc);
end
7: // CMP CPI
begin
{cac, null4} = acc - sr;
{cc, null8} = {1'b0, acc} - sr;
calpsz(null8);
end
endcase
endtask
32
3: // RAR
{acc, cc} = {cc, acc};
4: // DAA, decimal adjust
begin
if((acc[3:0] > 9) || cac) acc = acc + 6;
if((acc[7:4] > 9) || cc) {cc, acc} = {1'b0, acc} + 'h60;
end
1: // RRC
begin
acc = {acc[0], acc[7:1]};
cc = acc[0];
end
5: // CMA
acc = ~acc;
6: // STC
cc = 1;
2: // RAL
{cc, acc} = {acc, cc};
7: // CMC
cc = ~cc;
endcase
endtask
33
34
// INX B
// DCX B
// INX D
// DCX D
// INX H
// DCX H
// INX SP
// DCX SP
// LXI B
// LXI D
// LXI H
// LXI SP
35
36