任意输入5个整数,输出所有正数的平方和。 汇编代码 :
MOV R3,0H ;R0累计和 MOV R1,5H ;R1计数器,从5开始降到0,计数5次L1:TEST R1 ;判断R1为0则跳转 JZ L2 ;跳转L2 INT R2 ;R2输入数据 TEST R2 ;测试R2是否为负数 JB L1 ;如果小于0,跳转L1继续输入 MUL R2,R2 ;R2自乘 ADD R2,R3 ;R3=R3+R2 DEC R1 ;计数减1 JMP L1 L2:OUT R3 ;输出累加和 JMP L2 2、计组理论基础
(1)嵌入式 CISI 模型机系统总体设计
(2)嵌入式 CISC 系统控制器的逻辑结构框图
(3)指令系统设计
对Rs和Rd的规定
(4)微程序流程图设计
(5)地址转移逻辑
地址转移逻辑电路是根据微程序流程图3-2中的棱形框部分及多个分支微地址,利用微地址寄存器的异步置“1”端,实现微地址的多路转移。由于微地址寄存器中的触发器异步置“1”端低电平有效,与µA4~µA0对应的异步置“1”控制信号SE5~SE1的逻辑表达式为:(µA5的异步置“1”端SE6实际未使用)。
SE5<=NOT(CF AND P2 AND T4);SE4<=NOT(ZF AND P2 AND T4); SE3<=NOT(I15 AND P1 AND T4);SE2<=NOT(I14 AND P1 AND T4);SE1<=NOT(I13 AND P1 AND T4);SE0<=NOT(I12 AND P1 AND T4); (6)设计微指令格式和微指令代码
这些微程序代码是写在controm中,代码如下:
LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_ARITH.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY CONTROM ISPORT(ADDR: IN STD_LOGIC_VECTOR(5 DOWNTO 0); UA:OUT STD_LOGIC_VECTOR(5 DOWNTO 0); O:OUT STD_LOGIC_VECTOR(19 DOWNTO 0) );END CONTROM;ARCHITECTURE A OF CONTROM ISSIGNAL DATAOUT: STD_LOGIC_VECTOR(25 DOWNTO 0);BEGIN PROCESS BEGIN CASE ADDR IS WHEN "000000" => DATAOUT<="11010010001111110110000000";--取地址 WHEN "000001" => DATAOUT<="10001010001111111000000000";--MOV WHEN "000010" => DATAOUT<="10001010001011111100000000";--INT WHEN "000011" => DATAOUT<="10000110011111111100000000";--TEST WHEN "000100" => DATAOUT<="10000010001111111101000000";--JB WHEN "000101" => DATAOUT<="10001111000111111100000000";--MUL WHEN "000110" => DATAOUT<="10001110000111111100000000";--ADD WHEN "000111" => DATAOUT<="10001110110111111100000000";--DEC WHEN "001000" => DATAOUT<="10000010000111111101000000";--JZ WHEN "001001" => DATAOUT<="10000000001101111100000000";--OUT WHEN "001010" => DATAOUT<="01000010001111111000000000";--JMP WHEN "010000" => DATAOUT<="01000010001111111000000000";--jz WHEN "100000" => DATAOUT<="01000010001111111000000000";--*** WHEN OTHERS => DATAOUT<="10000110010011100000000000"; END CASE; UA(5 DOWNTO 0)<=DATAOUT(5 DOWNTO 0); O(19 DOWNTO 0)<=DATAOUT(25 DOWNTO 6); END PROCESS;END A; 自己设计的汇编代码是写在rom里面,代码如下:
LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_ARITH.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY ROM IS PORT( DOUT:OUT STD_LOGIC_VECTOR(15 DOWNTO 0); ADDR:IN STD_LOGIC_VECTOR(7 DOWNTO 0); CS_I:IN STD_LOGIC);END ROM;ARCHITECTURE A OF ROM IS-- 注记符号 指令格式(OP) Rs Rd addr -- MOV 0001 XX Rd XXXXXXXX-- INT 0010 XX Rd XXXXXXXX-- TEST 0011 Rs XX XXXXXXXX-- JB 0100 XX XX addr-- MUL 0101 Rs Rd XXXXXXXX-- ADD 0110 Rs Rd XXXXXXXX-- DEC 0111 XX Rd XXXXXXXX-- JZ 1000 XX XX addr-- OUT 1001 Rs XX XXXXXXXX-- JMP 1010 XX XX addrBEGIN DOUT<="0001001100000000" WHEN ADDR=x"00" AND CS_I='0' ELSE --MOV R3,0H "0001000100000101" WHEN ADDR=x"01" AND CS_I='0' ELSE --MOV R1,5H "0011010000000000" WHEN ADDR=x"02" AND CS_I='0' ELSE --L1:TEST R1 "1000000000001011" WHEN ADDR=x"03" AND CS_I='0' ELSE --JZ L2 "0010001000000000" WHEN ADDR=x"04" AND CS_I='0' ELSE --INT R2 "0011100000000000" WHEN ADDR=x"05" AND CS_I='0' ELSE --TEST R2 "0100000000000010" WHEN ADDR=x"06" AND CS_I='0' ELSE --JB L1 "0101101000000000" WHEN ADDR=x"07" AND CS_I='0' ELSE --MUL R2,R2 "0110101100000000" WHEN ADDR=x"08" AND CS_I='0' ELSE --ADD R2,R3 "0111000100000000" WHEN ADDR=x"09" AND CS_I='0' ELSE --DEC R1 "1010000000000010" WHEN ADDR=x"0A" AND CS_I='0' ELSE --JMP L1 "1001110000000000" WHEN ADDR=x"0B" AND CS_I='0' ELSE --L2:OUT R3 "1010000000001011" WHEN ADDR=x"0C" AND CS_I='0' ELSE --JMP L2 "0000000000000000";END A; 3、maxplus2使用:
任意输入5个整数,输出所有正数的平方和。 汇编代码 :
MOV R3,0H ;R0累计和 MOV R1,5H ;R1计数器,从5开始降到0,计数5次L1:TEST R1 ;判断R1为0则跳转 JZ L2 ;跳转L2 INT R2 ;R2输入数据 TEST R2 ;测试R2是否为负数 JB L1 ;如果小于0,跳转L1继续输入 MUL R2,R2 ;R2自乘 ADD R2,R3 ;R3=R3+R2 DEC R1 ;计数减1 JMP L1 L2:OUT R3 ;输出累加和 JMP L2 2、计组理论基础
(1)嵌入式 CISI 模型机系统总体设计
(2)嵌入式 CISC 系统控制器的逻辑结构框图
(3)指令系统设计
对Rs和Rd的规定
(4)微程序流程图设计
(5)地址转移逻辑
地址转移逻辑电路是根据微程序流程图3-2中的棱形框部分及多个分支微地址,利用微地址寄存器的异步置“1”端,实现微地址的多路转移。由于微地址寄存器中的触发器异步置“1”端低电平有效,与µA4~µA0对应的异步置“1”控制信号SE5~SE1的逻辑表达式为:(µA5的异步置“1”端SE6实际未使用)。
SE5<=NOT(CF AND P2 AND T4);SE4<=NOT(ZF AND P2 AND T4); SE3<=NOT(I15 AND P1 AND T4);SE2<=NOT(I14 AND P1 AND T4);SE1<=NOT(I13 AND P1 AND T4);SE0<=NOT(I12 AND P1 AND T4); (6)设计微指令格式和微指令代码
这些微程序代码是写在controm中,代码如下:
LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_ARITH.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY CONTROM ISPORT(ADDR: IN STD_LOGIC_VECTOR(5 DOWNTO 0); UA:OUT STD_LOGIC_VECTOR(5 DOWNTO 0); O:OUT STD_LOGIC_VECTOR(19 DOWNTO 0) );END CONTROM;ARCHITECTURE A OF CONTROM ISSIGNAL DATAOUT: STD_LOGIC_VECTOR(25 DOWNTO 0);BEGIN PROCESS BEGIN CASE ADDR IS WHEN "000000" => DATAOUT<="11010010001111110110000000";--取地址 WHEN "000001" => DATAOUT<="10001010001111111000000000";--MOV WHEN "000010" => DATAOUT<="10001010001011111100000000";--INT WHEN "000011" => DATAOUT<="10000110011111111100000000";--TEST WHEN "000100" => DATAOUT<="10000010001111111101000000";--JB WHEN "000101" => DATAOUT<="10001111000111111100000000";--MUL WHEN "000110" => DATAOUT<="10001110000111111100000000";--ADD WHEN "000111" => DATAOUT<="10001110110111111100000000";--DEC WHEN "001000" => DATAOUT<="10000010000111111101000000";--JZ WHEN "001001" => DATAOUT<="10000000001101111100000000";--OUT WHEN "001010" => DATAOUT<="01000010001111111000000000";--JMP WHEN "010000" => DATAOUT<="01000010001111111000000000";--jz WHEN "100000" => DATAOUT<="01000010001111111000000000";--*** WHEN OTHERS => DATAOUT<="10000110010011100000000000"; END CASE; UA(5 DOWNTO 0)<=DATAOUT(5 DOWNTO 0); O(19 DOWNTO 0)<=DATAOUT(25 DOWNTO 6); END PROCESS;END A; 自己设计的汇编代码是写在rom里面,代码如下:
LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;USE IEEE.STD_LOGIC_ARITH.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY ROM IS PORT( DOUT:OUT STD_LOGIC_VECTOR(15 DOWNTO 0); ADDR:IN STD_LOGIC_VECTOR(7 DOWNTO 0); CS_I:IN STD_LOGIC);END ROM;ARCHITECTURE A OF ROM IS-- 注记符号 指令格式(OP) Rs Rd addr -- MOV 0001 XX Rd XXXXXXXX-- INT 0010 XX Rd XXXXXXXX-- TEST 0011 Rs XX XXXXXXXX-- JB 0100 XX XX addr-- MUL 0101 Rs Rd XXXXXXXX-- ADD 0110 Rs Rd XXXXXXXX-- DEC 0111 XX Rd XXXXXXXX-- JZ 1000 XX XX addr-- OUT 1001 Rs XX XXXXXXXX-- JMP 1010 XX XX addrBEGIN DOUT<="0001001100000000" WHEN ADDR=x"00" AND CS_I='0' ELSE --MOV R3,0H "0001000100000101" WHEN ADDR=x"01" AND CS_I='0' ELSE --MOV R1,5H "0011010000000000" WHEN ADDR=x"02" AND CS_I='0' ELSE --L1:TEST R1 "1000000000001011" WHEN ADDR=x"03" AND CS_I='0' ELSE --JZ L2 "0010001000000000" WHEN ADDR=x"04" AND CS_I='0' ELSE --INT R2 "0011100000000000" WHEN ADDR=x"05" AND CS_I='0' ELSE --TEST R2 "0100000000000010" WHEN ADDR=x"06" AND CS_I='0' ELSE --JB L1 "0101101000000000" WHEN ADDR=x"07" AND CS_I='0' ELSE --MUL R2,R2 "0110101100000000" WHEN ADDR=x"08" AND CS_I='0' ELSE --ADD R2,R3 "0111000100000000" WHEN ADDR=x"09" AND CS_I='0' ELSE --DEC R1 "1010000000000010" WHEN ADDR=x"0A" AND CS_I='0' ELSE --JMP L1 "1001110000000000" WHEN ADDR=x"0B" AND CS_I='0' ELSE --L2:OUT R3 "1010000000001011" WHEN ADDR=x"0C" AND CS_I='0' ELSE --JMP L2 "0000000000000000";END A; 3、maxplus2使用: