Article Directory
- First, the experiment content
- Second, the experimental principle
- Third, the overall design
- Fourth, the experimental procedures
- 1. FIG. 6 is connected by line experiments, experimental box opened carefully check the power connection.
- 2. Write the experimental procedure, and verified.
- 3. Run the program
- Fifth, the experimental results
- Sixth, the problems encountered in the experiment and analysis
First, the experiment content
1. The experiment
The integrated use of computer composition principle knowledge, design and implement a more complete computer.
2. Experimental target
Model Machine in the full understanding of the principles of the complex, the preparation of their own machine instructions and microprograms corresponding to achieve the target computing model Helen using complex formula.
3. laboratory equipment
PC machine, one Taiwan, TD-CMA experimental system set.
Second, the experimental principle
1) Data Format
The machine model uses a predetermined fixed-point complement notation data word length is 8 bits, 8 bits used to represent the whole data (the most significant bit does not represent a symbol), represented by the numerical ranges: 0 ≦ x ≦ . 8 -1 .
2) design instruction
Helen formula according to the instruction as required, the design model three categories were fifteen native instructions including arithmetic instructions, control transfer instructions, the data transfer type instructions.
Class of instructions contains three arithmetic operations, arithmetic operations, logical operations, and shift operations, designed with six arithmetic instructions, are: ADD, AND, DEC, SUB, OR, SAR, all operations are single-byte instruction class , using the addressing mode register direct addressing.
Control transfer instruction has three classes HLT, the JMP, BZC, and for transferring the control program branches, wherein HLT instruction is a single byte, double-byte BZC and the JMP instruction.
Load Instructions have IN, OUT, MOV, LDI, LAD, STA total of 6 to complete the exchange of data between the registers and the registers, registers and I / O, and memory registers, in addition to single-byte instruction MOV instruction the rest are double-byte instructions.
3) instruction format
All single-byte instruction (ADD, AND, DEC, SUB, OR, SAR, HLT, and MOV) format is as follows:
7 6 4 5 | 3 2 | 1 0 |
---|---|---|
OP-CODE | RS | RD |
Wherein, OP-CODE opcode, RS is the source register, the destination register of the RD, which provides:
RS or RD | Selected register |
---|---|
00 | R0 |
01 | R1 |
10 | R2 |
11 | R3 |
IN and OUT instruction format is:
7 6 5 4 (1) | 3 2 (1) | 1 0 (1) | 7-0(2) |
---|---|---|---|
OP-CODE | RS | RD | P |
Wherein the first 1 byte in parentheses represent the instruction, the instruction represented by the second byte 2, OP-CODE opcode, RS is the source register, the destination register is the RD, P is the I / O port number, a word occupies section, the system I / O address decoder principle shown in Figure 1 (the address bus unit).
FIG 1 I / O address decoder Schematic
Since the most significant bits with the decoded address bus, I / O address space is divided into four regions, as shown in Table 1:
TABLE 1 I / O address space allocation
A7 A6 | Selected | Address space |
---|---|---|
00 | IOY0 | 00-3F |
01 | IOY1 | 40-7F |
10 | IOY2 | 80-BF |
11 | IOY3 | C0-FF |
System addressing five kinds of data, i.e., immediate, direct, indirect, and relative addressing index, LDI instruction is addressed immediately, LAD, STA, JMP instructions, and BZC are provided with direct, indirect, and relative addressing Indexed ability.
LDI instruction format, the first byte of the same content as the above, the second byte literal.
7 6 5 4 (1) | 3 2 (1) | 1 0 (1) | 7-0(2) |
---|---|---|---|
OP-CODE | RS | RD | data |
LAD, STA, JMP instruction format and BZC.
7 6 5 4 (1) | 3 2 (1) | 1 0 (1) | 7-0(2) |
---|---|---|---|
OP-CODE | M | RD | data |
Wherein M is an addressing mode, are detailed in Table 2, as the index register R2 to RI.
Addressing modes Table 2
Addressing mode M | E valid address | Explanation |
---|---|---|
00 | E = D | Direct addressing |
01 | E = (D) | Indirect addressing |
10 | E = (RI) + D | RI indexed addressing |
11 | E=(PC)+D | Relative addressing |
4) Instruction
The experiment calculated target Heron's formula, 15 design follows the basic instruction, the instruction format includes an assembly symbol, command functions.
Instruction Descriptions Table 3
Third, the overall design
Model Machine datapath block diagram shown in Figure 2.
2 block diagram of a data path
Model Machine experiments using multiple instruction, multiple addressing mode, the instruction decoding circuit requires a complicated design. Figure 3 implemented in the INS-DEC IR unit.
Instruction decode FIG 3 Schematic
To use in this experiment four general register R3 ~ R0, the register is selected through the lower four bits of the instruction, designed for this purpose have a register decoding circuit, implemented in REG_DEC (GAL16V8) IR units, such as 4 shown in FIG.
FIG 4 Schematic decoding register
The machine instruction design requirements, determine the design of micro program flow and micro-address, as shown in FIG.
按照系统建议的微指令格式,见表4,参照微指令流程图,将每条微指令代码化,译成二进制代码表,如表5,并将二进制代码表转化为联机操作时的十六进制格式文件。
表4 微指令格式
图5 微指令流程图
表5 二进制码表
地址 | 十六进制表示 | 高五位 | S3-S0 | A字段 | B字段 | C字段 | UA5-UA0 |
---|---|---|---|---|---|---|---|
00 | 000001 | 00000 | 0000 | 000 | 000 | 000 | 000001 |
01 | 006D43 | 00000 | 0000 | 110 | 110 | 101 | 000011 |
03 | 107070 | 00010 | 0000 | 111 | 000 | 001 | 110000 |
04 | 002405 | 00000 | 0000 | 010 | 010 | 000 | 000101 |
05 | 04B201 | 00000 | 1001 | 011 | 001 | 000 | 000001 |
06 | 002407 | 00000 | 0000 | 010 | 010 | 000 | 000111 |
07 | 013201 | 00000 | 0010 | 011 | 001 | 000 | 000001 |
08 | 106009 | 00010 | 0000 | 110 | 000 | 000 | 001001 |
09 | 183001 | 00011 | 0000 | 011 | 000 | 000 | 000001 |
0A | 106010 | 00010 | 0000 | 110 | 000 | 000 | 010000 |
0B | 000001 | 00000 | 0000 | 000 | 000 | 000 | 000001 |
0C | 103001 | 00010 | 0000 | 011 | 000 | 000 | 000001 |
0D | 200601 | 00100 | 0000 | 000 | 011 | 000 | 000001 |
0E | 005341 | 00000 | 0000 | 101 | 001 | 101 | 000001 |
0F | 0000CB | 00000 | 0000 | 000 | 000 | 011 | 001011 |
10 | 280401 | 00101 | 0000 | 000 | 010 | 000 | 000001 |
11 | 103001 | 00010 | 0000 | 011 | 000 | 000 | 000001 |
12 | 063201 | 00000 | 1100 | 011 | 001 | 000 | 000001 |
13 | 002414 | 00000 | 0000 | 010 | 010 | 000 | 010100 |
14 | 05B201 | 00000 | 1011 | 011 | 001 | 000 | 000001 |
15 | 002416 | 00000 | 0000 | 010 | 010 | 000 | 010110 |
16 | 01B201 | 00000 | 0011 | 011 | 001 | 000 | 000001 |
17 | 002418 | 00000 | 0000 | 010 | 010 | 000 | 011000 |
18 | 033201 | 00000 | 0110 | 011 | 001 | 000 | 000001 |
1B | 005341 | 00000 | 0000 | 101 | 001 | 101 | 000001 |
1C | 10101D | 00010 | 0000 | 001 | 000 | 000 | 011101 |
1D | 10608C | 00010 | 0000 | 110 | 000 | 010 | 001100 |
1E | 10601F | 00010 | 0000 | 110 | 000 | 000 | 011111 |
1F | 101020 | 00010 | 0000 | 001 | 000 | 000 | 100000 |
20 | 10608C | 00010 | 0000 | 110 | 000 | 010 | 001100 |
28 | 101029 | 00010 | 0000 | 001 | 000 | 000 | 101001 |
29 | 00282A | 00000 | 0000 | 010 | 100 | 000 | 101010 |
2A | 04E22B | 00000 | 1001 | 110 | 001 | 000 | 101011 |
2B | 04928C | 00000 | 1001 | 001 | 001 | 010 | 001100 |
2C | 10102D | 00010 | 0000 | 001 | 000 | 000 | 101101 |
2D | 002C2E | 00000 | 0000 | 010 | 110 | 000 | 101110 |
2E | 04E22F | 00000 | 1001 | 110 | 001 | 000 | 101111 |
2F | 04928C | 00000 | 1001 | 001 | 001 | 010 | 001100 |
30 | 001604 | 00000 | 0000 | 001 | 011 | 000 | 000100 |
31 | 001606 | 00000 | 0000 | 001 | 011 | 000 | 000110 |
32 | 006D48 | 00000 | 0000 | 110 | 110 | 101 | 001000 |
33 | 006D4A | 00000 | 0000 | 110 | 110 | 101 | 001010 |
34 | 003401 | 00000 | 0000 | 011 | 010 | 000 | 000001 |
35 | 000035 | 00000 | 0000 | 000 | 000 | 000 | 110101 |
36 | 006D51 | 00000 | 0000 | 110 | 110 | 101 | 010001 |
37 | 001612 | 00000 | 0000 | 001 | 011 | 000 | 010010 |
38 | 001613 | 00000 | 0000 | 001 | 011 | 000 | 010011 |
39 | 001615 | 00000 | 0000 | 001 | 011 | 000 | 010101 |
3A | 001617 | 00000 | 0000 | 001 | 011 | 000 | 010111 |
3B | 000001 | 00000 | 0000 | 000 | 000 | 000 | 000001 |
3C | 006D5C | 00000 | 0000 | 110 | 110 | 101 | 011100 |
3D | 006D5E | 00000 | 0000 | 110 | 110 | 101 | 011110 |
3E | 006D68 | 00000 | 0000 | 110 | 110 | 101 | 101000 |
3F | 006D6C | 00000 | 0000 | 110 | 110 | 101 | 101100 |
根据实验计算海伦公式的目标,以及基于此设计的机器指令,在模型机实现以下运算:从IN单元读入三角形三边(要求输入三边一定能构成三角形),求此三角形的面积平方,将所求结果存于61H单元,机器指令流程图如图6。
图6 机器指令流程图
根据流程图设计表6程序,地址和内容均为二进制。
表6 机器指令程序
地址 | 内容 | 助记符 | 说明 |
---|---|---|---|
00000000 | 00100000 | IN R0,00H | 读入a |
00000001 | 00000000 | ||
00000010 | 00100001 | IN R1,00H | 读入b |
00000011 | 00000000 | ||
00000100 | 00100010 | IN R2,00H | 读入c |
00000101 | 00000000 | ||
00000110 | 11010000 | STA 60H,R0 | 将a存入60H |
00000111 | 01100000 | ||
00001000 | 00000100 | ADD R0,R1 | a+b存入R0 |
00001001 | 00001000 | ADD R0,R2 | a+b+c存入R0 |
00001010 | 01100011 | LDI R3,01H | 将1存入R3 |
00001011 | 00000001 | ||
00001100 | 10101100 | SAR R0,R3 | a+b+c向右移一位,R0=P |
00001101 | 01000011 | MOV R3,R0 | 将p移入R3 |
00001110 | 10000100 | SUB R0,R1 | R0=P-B |
00001111 | 01001101 | MOV R1,R3 | 将P存入R1 |
00010000 | 10001001 | SUB R1,R2 | P-C存入R1 |
00010001 | 01000010 | MOV R2,R0 | 将R0移入R2,作为乘数准备 |
00010010 | 01110001 | DEC R1 | 将另一个乘数减1,做好准备 |
00010011 | 11110000 | BZC RESULT | 判断 |
00010100 | 00011011 | ||
00010101 | 00001000 | LOOP:ADD R0,R2 | 开始乘法 |
00010110 | 01110001 | DEC R1 | |
00010111 | 11110000 | BZC RESULT | 判断 |
00011000 | 00011011 | ||
00011001 | 11100000 | JMP LOOP | 回到LOOP开始 |
00011010 | 00010101 | ||
00011011 | 01001101 | MOV R1,R3 | 将P存回R1 |
00011100 | 01110001 | DEC R1 | 将另一个乘数减1,做好准备 |
00011101 | 11110000 | BZC RESULT | 判断 |
00011110 | 00100110 | ||
00011111 | 01000010 | MOV R2,R0 | 将R0移入R2,作为乘数准备 |
00100000 | 00001000 | LOOP:ADD R0,R2 | 开始乘法 |
00100001 | 01110001 | DEC R1 | |
00100010 | 11110000 | BZC RESULT | 判断 |
00100011 | 00100110 | ||
00100100 | 11100000 | JMP LOOP | 回到LOOP开始 |
00100101 | 00100000 | ||
00100110 | 11000001 | LAD 00 R1,60H | 将a重新放入R1 |
00100111 | 01100000 | ||
00101000 | 10000111 | SUB R3,R1 | R3=P-A |
00101001 | 01001101 | MOV R1,R3 | R3->R1 |
00101010 | 01000010 | MOV R2,R0 | R0->R2 |
00101011 | 01110001 | DEC R1 | |
00101100 | 11110000 | BZC RESULT | 判断 |
00101101 | 00110100 | ||
00101110 | 00001000 | LOOP:ADD R0,R2 | 开始乘法 |
00101111 | 01110001 | DEC R1 | |
00110000 | 11110000 | BZC RESULT | 判断 |
00110001 | 00110100 | ||
00110010 | 11100000 | JMP LOOP | 回到LOOP开始 |
00110011 | 00101110 | ||
00110100 | 11010000 | STA 61H,R0 | 将所得结果存入61H |
00110101 | 01100001 | ||
00110110 | 00110000 | OUT 40H,R0 | 将所得结果输出 |
00110111 | 01000000 |
四、实验步骤
1. 按图6连接实验线路,仔细检查连线后打开实验箱电源。
图7 实验连线图
2. 写入实验程序,并进行校验。
联机软件提供了微程序和机器程序下载功能,以代替手动读写微程序和机器程序,但是微程序和机器程序得以指定的格式写入到以TXT为后缀的文件中,本次实验程序如下,程序中分号';'为注释符,分号后面的内容在下载时将被忽略掉。 TXT文件如下:
; //*************************************** //
; // //
; // 复杂模型机实验指令文件 //
; // //
; // By TangDu CO.,LTD //
; // //
; //*************************************** //
; //****** Start Of Main Memory Data ****** //
$P 00 20 ;IN R0,00H
$P 01 00
$P 02 21 ;IN R1,00H
$P 03 00
$P 04 22 ;IN R2,00H
$P 05 00
$P 06 D0 ;STA 60H,R0
$P 07 60
$P 08 04 ;ADD R0,R1
$P 09 08 ;ADD R0,R2
$P 0A 63 ;LDI R3,01H
$P 0B 01
$P 0C AC ;SAR R0,R3
$P 0D 43 ;MOV R3,R0
$P 0E 84 ;SUB R0,R1
$P 0F 4D ;MOV R1,R3
$P 10 89 ;SUB R1,R2
$P 11 42 ;MOV R2,R0
$P 12 71 ;DEC R1
$P 13 F0 ;BZC RESULT
$P 14 1B
$P 15 08 ;LOOP:ADD R0,R2
$P 16 71 ;DEC R1
$P 17 F0 ;BZC RESULT
$P 18 1B
$P 19 E0 ;JMP LOOP
$P 1A 15
$P 1B 4D ;MOV R1,R3
$P 1C 71 ;DEC R1
$P 1D F0 ;BZC RESULT
$P 1E 26
$P 1F 22 ;MOV R2,R0
$P 20 08 ;LOOP:ADD R0,R2
$P 21 71 ;DEC R1
$P 22 F0 ;BZC RESULT
$P 23 26
$P 24 E0 ;JMP LOOP
$P 25 20
$P 26 C1 ;LAD 00 R1,60H
$P 27 60
$P 28 87 ;SUB R3,R1
$P 29 4D ;MOV R1,R3
$P 2A 42 ;MOV R2,R0
$P 2B 71 ;DEC R1
$P 2C F0 ;BZC RESULT
$P 2D 34
$P 2E 08 ;LOOP:ADD R0,R2
$P 2F 71 ;DEC R1
$P 30 F0 ;BZC RESULT
$P 31 34
$P 32 E0 ;JMP LOOP
$P 33 2E
$P 34 D0 ;STA 61H,R0
$P 35 61
$P 36 30 ;OUT 40H,R0
$P 37 40
; //***** End Of Main Memory Data *****//
; //** Start Of MicroController Data **//
$M 00 000001 ; NOP
$M 01 006D43 ; PC->AR, PC加1
$M 03 107070 ; MEM->IR, P<1>
$M 04 002405 ; RS->B
$M 05 04B201 ; A加B->RD
$M 06 002407 ; RS->B
$M 07 013201 ; A与B->RD
$M 08 106009 ; MEM->AR
$M 09 183001 ; IO->RD
$M 0A 106010 ; MEM->AR
$M 0B 000001 ; NOP
$M 0C 103001 ; MEM->RD
$M 0D 200601 ; RD->MEM
$M 0E 005341 ; A->PC
$M 0F 0000CB ; NOP, P<3>
$M 10 280401 ; RS->IO
$M 11 103001 ; MEM->RD
$M 12 063201 ; A减1->RD
$M 13 002414 ; RS->B
$M 14 05B201 ; A减B->RD
$M 15 002416 ; RS->B
$M 16 01B201 ; A或B->RD
$M 17 002418 ; RS->B
$M 18 033201 ; A右移->RD
$M 1B 005341 ; A->PC
$M 1C 10101D ; MEM->A
$M 1D 10608C ; MEM->AR, P<2>
$M 1E 10601F ; MEM->AR
$M 1F 101020 ; MEM->A
$M 20 10608C ; MEM->AR, P<2>
$M 28 101029 ; MEM->A
$M 29 00282A ; RI->B
$M 2A 04E22B ; A加B->AR
$M 2B 04928C ; A加B->A, P<2>
$M 2C 10102D ; MEM->A
$M 2D 002C2E ; PC->B
$M 2E 04E22F ; A加B->AR
$M 2F 04928C ; A加B->A, P<2>
$M 30 001604 ; RD->A
$M 31 001606 ; RD->A
$M 32 006D48 ; PC->AR, PC加1
$M 33 006D4A ; PC->AR, PC加1
$M 34 003401 ; RS->RD
$M 35 000035 ; NOP
$M 36 006D51 ; PC->AR, PC加1
$M 37 001612 ; RD->A
$M 38 001613 ; RD->A
$M 39 001615 ; RD->A
$M 3A 001617 ; RD->A
$M 3B 000001 ; NOP
$M 3C 006D5C ; PC->AR, PC加1
$M 3D 006D5E ; PC->AR, PC加1
$M 3E 006D68 ; PC->AR, PC加1
$M 3F 006D6C ; PC->AR, PC加1
3. 运行程序
进入软件界面,选择菜单命令"【实验】—【CISC 实验】",打开相应的数据通路图,选择相应的功能命令,即可联机运行、监控、调试程序。
按动CON单元的总清按钮CLR,然后通过软件运行程序,当模型机执行完OUT指令后,检查OUT单元显示的数是否正确。在数据通路图和微程序流中观测指令的执行过程,并观测软件中地址总线、数据总线以及微指令显示和下位机是否一致。
五、实验结果
考虑到模拟机的硬件约束,因此采用边长分别为3、4、5的三角形来测试程序。
After the step of sequentially input 3,4,5 programmed, the program 24H the final output (i.e. decimal 36), a result in line with expectations, and the corresponding machine instructions may be considered micro-programming is correct, the machine according to the model formula Helen square area of a triangle.
Results Figure 8
Sixth, the problems encountered in the experiment and analysis
Heron's formula is used to achieve the multiplication needed, the programs using multiplication cumulative manner, but beginning from a multiplier starts accumulating the number of the original, rather than accumulating from 0, it is necessary to need before the other multiplier multiplying Save 1, otherwise it will pay more once the implementation of multiplication.