一个简单CPU VHDL代码解析

本文详细解析了一个基于VHDL实现的简单CPU,重点探讨了运算输入aluinput和temp信号在CPU中的作用及流程,涉及vector、subroutine、signal、input和parameters等关键概念。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这些天一直在琢磨一个cpu是如何开机reset后运行,完成取指令,译码,计算,存储等操作,还是看一个简单的CPU代码,开始看了MC8051的VHDL代码,不过一头雾水。后来终于在网上找了一个TISC的模拟cpu代码,一共有200多行,不过麻雀虽小,却五脏俱全,而且作者对每行代码都做了详细的说明,下面仔细的分析一下。
先看看作者写的指令说明:
-- Vins VHDL Tisc CPU Core, 15th Nov 2001
-- My first attempt at processor design, thanks to :-
-- Tim Boscke - CPU8BIT2, Rockwell - 6502, Microchip - Pic
-- Jien Chung Lo - EL405 , Steve Scott - Tisc,
-- Giovanni Moretti - Intro to Asm
-- Uses 12 bit program word, and 8 bit data memory
 
-- 2 reg machine,accumulator based, with akku and index regs
-- Harvard architecture, uses return x so as to eliminate need of pmem
-- indirect instructions like 8051.
-- pc is 10 bits, akku and idx are 8 bit.
 
-- Has carry and zero flags,
-- three addressing modes:- immediate, indirect and reg.
-- seperate program and data memory for pipelining later...
 
-- Instructions coded as thus:-
 
 
-- Long instructions first - program jump.
-- Both store return address for subroutine calls, 1 deep stack.
-- 0 0 xxxxxxxxxx jc pmem10     ; if c==1, stack = pc, pc <- pmem10, fi
-- 0 1 xxxxxxxxxx jz pmem10     ; if z==1, stack = pc, pc <- pmem10, fi
 
-- Immediate ops
-- bits 9 and 8 select what to do
-- 1 00 0 xxxxxxxx       lda #imm8      ; a= imm8, c=0,
-- 1 00 1 xxxxxxxx       ret #imm8      ; a= imm8, pc = stack
 
-- 1 01 0 xxxxxxxx       adc #imm8      ; add with carry imm8, cy and z set
-- 1 01 1 xxxxxxxx       adx #imm8      ; add imm8 to idx reg, z=(a==0)
 
-- Indirect and alu ops
-- bit 9 selects indirect or alu ops
 
-- Indirect - bits 7 and 8 select what to do
-- 1 10 0 0 xxxxxxx lda [ix]   ; load a indirect data mem
-- 1 10 0 1 xxxxxxx sta [ix]   ; store a indirect data mem
 
-- register register
-- 1 10 1 0 xxxxxxx tax    ; x = a,
-- 1 10 1 1 xxxxxxx txa    ; a = x
 
-- Arithmetic ops use indirect addressing
-- all alu ops indirect, bits 7 and 8 select alu op.
-- 1 11 00 xxxxxxx add a,[ix] ; add with carry
-- 1 11 01 xxxxxxx sub a,[ix] ; a = a + ~[idx], inc a after for proper subtract
-- 1 11 10 xxxxxxx and a,[ix] ; and mem contents into a
-- 1 11 11 xxxxxxx nor a,[ix] ; nor
 
-- States.
-- 000 instruction decode
-- 010 load a indirect - lda [ix]
-- 011 stor a indirect - sta [ix]
-- 100 add a,[ix]
-- 101 sub a,[ix[
-- 110 and a,[ix]
-- 111 nor a,[ix]
 
1. 外部接口说明
1.1 处理机控制
Clock       --时钟信号   Reset --复位信号
1.2 总线信号
Data[11..0] --数据       address[9..0] --地址
1.3 控制信号
Rd --读信号    wr --写信号 psen --pmem
 
2. 内部信号及寄存器说明
2.1 程序控制
Stack --堆栈   PC --程序计数器
2.2 寄存器
Akku --累加寄存器 Idx --索引寄存器   Z --零标志寄存器
2.3 ALU 运算器

运算输入:aluinput,temp

操作 符:aluop
运算结果:aluout
存放目标选择:aludest
 
3 指令译码及运算
3.1 sub 指令译码
-- States.
-- 000 instruction decode
-- 010 load a indirect - lda [ix]
-- 011 stor a indirect - sta [ix]
-- 100 add a,[ix]
-- 101 sub a,[ix]
-- 110 and a,[ix]
-- 111 nor a,[ix]
如对101 sub a,[ix] 汇编指令译码,通过状态-States实现:
(1)        判断状态最高位—>如果为1则进行取数运算à及准备aluop,并设定目标akkuà转换到状态000,指令译码操作。
      
        if( states(2) = '1') then
            if( states(1 downto 0) = "01") then --sub add ind
 &n
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值