first commit

This commit is contained in:
Jingfan Ke 2025-05-27 16:03:52 +08:00
commit 2d22d07f60
223 changed files with 5842 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,57 @@
# 1
1. 类型不匹配
2. 不能同时为内存单元
3. 寻址方式错误,\[变址][变址]是错误的,只能搭配\[基址][变址]
4. AX寄存器不能用于寄存器间接寻址
5. 不能使用MOV指令修改CSCS只能用JMP指令修改
# 2
1. 非法 OPR1不能是立即数
2. 合法
3. OPR1和OPR2不能同时为存储器
4. 合法
# 3
1. 非法 类型不匹配
2. 合法
3. 非法 DST和SRC不能同时为存储器寻址因为不能确定两者位宽是否匹配
4. 非法 DX寄存器不能用于寄存器间接寻址
5. 非法 DS无变址与其搭配
6. 合法
7. 合法
# 4
1. MOV AX, OFFSET LNAME
2. MOV SI, WORD PTR CODE_LIST
3. CODE_LENGHT EQU $-CODE_LIST
# 5
1. 不需要
2. 需要
3. 需要
4. 需要
5. 不需要
# 6
1. 1234H
2. 0032H
# 7
| Instruction | AX | CF | SF | ZF |
| ------------- | ----- | ---- | ---- | ---- |
| MOV AX, 1234H | 1234H | | | |
| MOV CL, 4 | 1234H | | | |
| ROL AX, CL | 2341H | 1 | | |
| DEC AX | 2340H | 1 | 0 | 0 |
| MOV CX, 4 | 2340H | | | |
| MUL CX | 8D00H | | | |
CX = 0004H

BIN
Assignment/答案/1.1.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 KiB

BIN
Assignment/答案/1.2.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 KiB

BIN
Assignment/答案/1.3.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 KiB

BIN
Assignment/答案/1.4.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 KiB

BIN
Assignment/答案/2.1.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 KiB

BIN
Assignment/答案/2.2.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 KiB

BIN
Assignment/答案/3.1.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 KiB

BIN
Assignment/答案/3.2.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 KiB

BIN
Assignment/答案/3.3.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 KiB

BIN
Assignment/答案/4.1.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 460 KiB

BIN
Assignment/答案/4.2.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 389 KiB

BIN
Assignment/答案/4.3.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 436 KiB

BIN
Assignment/答案/4.4.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 KiB

BIN
Assignment/答案/4.5.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 KiB

BIN
Assignment/答案/4.6.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,23 @@
DATA SEGMENT
NUM1 DD 11451400H
NUM2 DD 19198100H
SUM DD ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
start:
MOV AX, DATA
MOV DS, AX
MOV AX, WORD PTR NUM1
MOV WORD PTR SUM, AX
MOV BX, WORD PTR NUM2
ADD WORD PTR SUM, AX
MOV AX, WORD PTR NUM1+2
ADC WORD PTR SUM+2, AX
MOV AX, WORD PTR NUM2+2
ADD WORD PTR SUM+2, AX
MOV AH, 4CH
INT 21H
CODE ENDS
END start

View File

@ -0,0 +1,36 @@
DSEG SEGMENT
XXX DW 1234H
YYY DW 5678H
ZZZ DD ?
DSEG ENDS
CSEG SEGMENT
ASSUME CS:CSEG,DS:DSEG
START:MOV AX,DSEG
MOV DS,AX
MOV AX,XXX
XOR DX,DX
ADD AX,AX
ADC DX,0
ADD AX,AX
ADC DX,0
ADD AX,AX
ADC DX,0
ADD AX,AX
ADC DX,0
ADD AX,YYY
ADC DX,0
MOV WORD PTR ZZZ,AX
MOV WORD PTR ZZZ+2,DX
MOV AH,4CH
INT 21H
CSEG ENDS
END START

Binary file not shown.

BIN
Lab/Lab1/material/1-1.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

BIN
Lab/Lab1/material/1-2.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
Lab/Lab1/material/1-3.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

BIN
Lab/Lab1/material/1-4.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

23
Lab/Lab1/material/1.asm Executable file
View File

@ -0,0 +1,23 @@
DATA SEGMENT
NUM1 DD 11451400H ; 被加数
NUM2 DD 19198100H ; 加数
SUM DD ? ; 结果
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
start:
MOV AX, DATA
MOV DS, AX
MOV AX, WORD PTR NUM1 ; 将NUM1低位赋给AX
MOV WORD PTR SUM, AX ; 将AX赋给SUM低位(MOV指令不能直接在两个内存单元间赋值)
MOV AX, WORD PTR NUM2 ; 将NUM2低位赋给AX
ADD WORD PTR SUM, AX ; 将AX加到SUM的低位上
MOV AX, WORD PTR NUM1+2 ; 将NUM1高位赋给AX
ADC WORD PTR SUM+2, AX ; ADC(Add with Carry)将AX加到SUM的高位(初始为零)上再加上CF存着的低位进位
MOV AX, WORD PTR NUM2+2 ; 将NUM2高位赋给AX
ADD WORD PTR SUM+2, AX ; 将AX加到SUM的高位上
MOV AH, 4CH ; 退出程序
INT 21H
CODE ENDS
END start

BIN
Lab/Lab1/material/2-1.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

BIN
Lab/Lab1/material/2-2.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

BIN
Lab/Lab1/material/2-3.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

37
Lab/Lab1/material/2.asm Executable file
View File

@ -0,0 +1,37 @@
DSEG SEGMENT
XXX DW 1234H
YYY DW 5678H
ZZZ DD ?
DSEG ENDS
CSEG SEGMENT
ASSUME CS:CSEG, DS:DSEG
START:
MOV AX, DSEG
MOV DS, AX
MOV AX, XXX ; 将XXX赋给AX
XOR DX, DX ; 异或DX和DX即将DX置0
ADD AX, AX ; AX *= 2, AX = 2 * XXX
ADC DX, 0 ; 把进位保存在DX中
ADD AX, AX ; AX *= 2, AX = 4 * XXX
ADC DX, 0 ; 更新DX中的进位信息
ADD AX, AX ; AX *= 2, AX = 8 * XXX
ADC DX, 0 ; 更新DX中的进位信息
ADD AX, AX ; AX *= 2, AX = 16 * XXX
ADC DX, 0 ; 更新DX中的进位信息
ADD AX, YYY ; AX += YYY, AX = 16 * XXX + YYY
ADC DX, 0 ; 更新DX中的进位信息
MOV WORD PTR ZZZ, AX ; ZZZ的低位 = AX = 16 * XXX + YYY
MOV WORD PTR ZZZ+2, DX ; ZZZ的高位 = DX = 进位数, ZZZ = 16 * XXX + YYY(完整)
MOV AH, 4CH
INT 21H
CSEG ENDS
END START

View File

@ -0,0 +1,178 @@
![cover](cover.png)
# 一、实验目的
1. 进一步学习汇编语言基本指令使用方法;
2. 学习DEBUG调试工具的基本使用方法掌握debug调试命令a、u、r、d、t、g等
3. 逐条观察程序指令的执行过程,理解指令的功能,理解程序自动、顺序地执行的概念,实践其过程(重点)。
# 二、实验内容
1. 编写、输入一个32位二进制数相加程序逐条执行指令观察指令执行情况。
1. 使用已经过汇编和连接的小程序(t3-2.exe)将其装入内存逐条执行指令观察执行过程和结果。在实验过程中使用E命令修改XXX和YYY单元中的数据再重新计算其结果。
# 三、流程图
第一题:
![graph1.drawio](graph1.drawio.svg)
# 四、实验过程与分析
第一题:
进入调试, -U
![1-1](1-1.png)
-T
![1-2](1-2.png)
载入数据段后:
![1-3](1-3.png)
程序执行完毕后:
![1-4](1-4.png)
第二题:
<img src="2-1.png" alt="2-1" style="zoom:50%;" />
修改后:
<img src="2-2.png" alt="2-2" style="zoom:50%;" />
最终:
<img src="2-3.png" alt="2-3" style="zoom:50%;" />
程序实际效果计算a:b的物理地址。
# 五、实验总结
熟练掌握了各种指令以及调试步骤,收获颇丰。
# 六、思考题
> 程序中的指令、数据是如何在存储器中存储的?
分别在不同的段中按顺序存储
> 如何理解程序执行过程的顺序性?
程序按指令在代码段内存储的顺序执行。如需人为改变执行顺序可以指定ip为要执行的指令的地址。
> 如何理解标志位寄存器中的数据?
标志寄存器在CPU内部用于存储算术逻辑运算后的结果特征和控制CPU的工作方式或工作状态。
| 位数 | 符号 | 含义 |
| :--: | :--: | :--------: |
| 0 | CF | 进位标志 |
| 2 | PF | 奇偶标志 |
| 4 | AF | 半进位标志 |
| 6 | ZF | 零标志 |
| 7 | SF | 符号标志 |
| 8 | TF | 溢出标志 |
| 9 | IF | 方向标志 |
| 10 | DF | 中断标志 |
| 11 | OF | 跟踪标志 |
# 源代码附录
第一题:
```assembly
DATA SEGMENT
NUM1 DD 11451400H ; 被加数
NUM2 DD 19198100H ; 加数
SUM DD ? ; 结果
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
start:
MOV AX, DATA
MOV DS, AX
MOV AX, WORD PTR NUM1 ; 将NUM1低位赋给AX
MOV WORD PTR SUM, AX ; 将AX赋给SUM低位(MOV指令不能直接在两个内存单元间赋值)
MOV AX, WORD PTR NUM2 ; 将NUM2低位赋给AX
ADD WORD PTR SUM, AX ; 将AX加到SUM的低位上
MOV AX, WORD PTR NUM1+2 ; 将NUM1高位赋给AX
ADC WORD PTR SUM+2, AX ; ADC(Add with Carry)将AX加到SUM的高位(初始为零)上再加上CF存着的低位进位
MOV AX, WORD PTR NUM2+2 ; 将NUM2高位赋给AX
ADD WORD PTR SUM+2, AX ; 将AX加到SUM的高位上
MOV AH, 4CH ; 退出程序
INT 21H
CODE ENDS
END start
```
第二题:
```assembly
DSEG SEGMENT
XXX DW 1234H
YYY DW 5678H
ZZZ DD ?
DSEG ENDS
CSEG SEGMENT
ASSUME CS:CSEG, DS:DSEG
START:
MOV AX, DSEG
MOV DS, AX
MOV AX, XXX ; 将XXX赋给AX
XOR DX, DX ; 异或DX和DX即将DX置0
ADD AX, AX ; AX *= 2, AX = 2 * XXX
ADC DX, 0 ; 把进位保存在DX中
ADD AX, AX ; AX *= 2, AX = 4 * XXX
ADC DX, 0 ; 更新DX中的进位信息
ADD AX, AX ; AX *= 2, AX = 8 * XXX
ADC DX, 0 ; 更新DX中的进位信息
ADD AX, AX ; AX *= 2, AX = 16 * XXX
ADC DX, 0 ; 更新DX中的进位信息
ADD AX, YYY ; AX += YYY, AX = 16 * XXX + YYY
ADC DX, 0 ; 更新DX中的进位信息
MOV WORD PTR ZZZ, AX ; ZZZ的低位 = AX = 16 * XXX + YYY
MOV WORD PTR ZZZ+2, DX ; ZZZ的高位 = DX = 进位数, ZZZ = 16 * XXX + YYY(完整)
MOV AH, 4CH
INT 21H
CSEG ENDS
END START
```

Binary file not shown.

BIN
Lab/Lab1/material/cover.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 KiB

43
Lab/Lab1/material/graph1.drawio Executable file
View File

@ -0,0 +1,43 @@
<mxfile host="Electron" modified="2023-04-02T07:41:48.312Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.1.2 Chrome/106.0.5249.199 Electron/21.4.3 Safari/537.36" etag="5hIqR4LNWa8fX__H5m1n" version="21.1.2" type="device">
<diagram name="第 1 页" id="5szQxJ_d8_ub9XAW-9oE">
<mxGraphModel dx="1001" dy="744" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="NDtPPReygzJqEH5N9WcK-5" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="NDtPPReygzJqEH5N9WcK-1" target="NDtPPReygzJqEH5N9WcK-2">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="NDtPPReygzJqEH5N9WcK-1" value="载入数据段" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="360" y="240" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="NDtPPReygzJqEH5N9WcK-6" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="NDtPPReygzJqEH5N9WcK-2" target="NDtPPReygzJqEH5N9WcK-3">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="NDtPPReygzJqEH5N9WcK-2" value="将NUM1和NUM2的低字段内容相加填入SUM的低字段" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="340" y="320" width="160" height="40" as="geometry" />
</mxCell>
<mxCell id="NDtPPReygzJqEH5N9WcK-7" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="NDtPPReygzJqEH5N9WcK-3" target="NDtPPReygzJqEH5N9WcK-4">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="NDtPPReygzJqEH5N9WcK-3" value="将NUM1的高字段内容与上次相加结果的进位相加填入SUM的高字段" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="320.5" y="400" width="199" height="40" as="geometry" />
</mxCell>
<mxCell id="NDtPPReygzJqEH5N9WcK-13" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="NDtPPReygzJqEH5N9WcK-4" target="NDtPPReygzJqEH5N9WcK-9">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="NDtPPReygzJqEH5N9WcK-4" value="将NUM2的高字段内容与SUM的高字段内容相加填入SUM的高字段" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="320.5" y="480" width="200" height="40" as="geometry" />
</mxCell>
<mxCell id="NDtPPReygzJqEH5N9WcK-9" value="结束程序" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="360" y="560" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="NDtPPReygzJqEH5N9WcK-11" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="NDtPPReygzJqEH5N9WcK-10" target="NDtPPReygzJqEH5N9WcK-1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="NDtPPReygzJqEH5N9WcK-10" value="开始执行程序段" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="360" y="160" width="120" height="40" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,55 @@
DATA SEGMENT
CHAR DB 'A'
HINT1 DB 'Please enter a string: $'
HINT2 DB 10, 27H, 'A', 27H, ' occured time: $'
TIMES DB 0
MAXLEN DB 100
LEN DB 0
TABLE DB 100 DUP (0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV AH, 9
MOV DX, OFFSET HINT1
INT 21H
LEA DX, MAXLEN
MOV AH, 0AH
INT 21H
CALL CNT
MOV AH, 9
MOV DX, OFFSET HINT2
INT 21H
MOV AL, TIMES
ADD AL, '0'
MOV DL, AL
MOV AH, 02
INT 21H
MOV AH,4CH
INT 21H
CNT PROC NEAR
MOV CX, 0
MOV CL, LEN
MOV SI, -1
MOV AL, CHAR
LP:
INC SI
CMP AL, TABLE[SI]
JNZ BACK
INC TIMES
BACK:
LOOP LP
RET
CNT ENDP
CODE ENDS
END START

View File

@ -0,0 +1,105 @@
<mxfile host="Electron" modified="2023-04-11T14:21:32.543Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.1.2 Chrome/106.0.5249.199 Electron/21.4.3 Safari/537.36" etag="QNq7u-1bCWMLLsHMlqsS" version="21.1.2" type="device">
<diagram name="第 1 页" id="Hp0mWjxMjnIu5b5PPHpT">
<mxGraphModel dx="1098" dy="820" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="Hisepnijn4ny8SH6L1L8-29" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-1" target="Hisepnijn4ny8SH6L1L8-2">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-1" value="程序开始" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="280" y="320" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-30" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-2" target="Hisepnijn4ny8SH6L1L8-3">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-2" value="载入数据段" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="120" y="400" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-31" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-3" target="Hisepnijn4ny8SH6L1L8-4">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-3" value="输出提示信息" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="280" y="400" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-44" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-4" target="Hisepnijn4ny8SH6L1L8-37">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-4" value="读取字符串" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="440" y="400" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-48" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-6" target="Hisepnijn4ny8SH6L1L8-17">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-6" value="将字符串当前位数加1" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="120" y="720" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-11" value="N" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-10" target="Hisepnijn4ny8SH6L1L8-6">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-46" value="Y" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0.75;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-10" target="Hisepnijn4ny8SH6L1L8-37">
<mxGeometry x="-0.8824" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-10" value="循环次数是否用尽?" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="120" y="640" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-19" value="Y" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-17" target="Hisepnijn4ny8SH6L1L8-20">
<mxGeometry relative="1" as="geometry">
<mxPoint x="440" y="740" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-49" value="N" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-17" target="Hisepnijn4ny8SH6L1L8-10">
<mxGeometry x="-0.9167" relative="1" as="geometry">
<Array as="points">
<mxPoint x="340" y="800" />
<mxPoint x="80" y="800" />
<mxPoint x="80" y="660" />
</Array>
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-17" value="字符串的当前位与指定字符比较是否一样" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="280" y="720" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-50" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-20" target="Hisepnijn4ny8SH6L1L8-10">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="500" y="800" />
<mxPoint x="80" y="800" />
<mxPoint x="80" y="660" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-20" value="结果加1" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="440" y="720" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-35" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-25" target="Hisepnijn4ny8SH6L1L8-27">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-25" value="输出答案" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="440" y="480" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-27" value="程序结束" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="440" y="560" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-42" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-28" target="Hisepnijn4ny8SH6L1L8-10">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-28" value="指定循环次数为字符串长度" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="120" y="560" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-45" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.25;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-37" target="Hisepnijn4ny8SH6L1L8-28">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-47" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-37" target="Hisepnijn4ny8SH6L1L8-25">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-37" value="调用CNT子程序" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="200" y="480" width="120" height="40" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

View File

@ -0,0 +1,105 @@
<mxfile host="Electron" modified="2023-04-11T14:22:21.464Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.1.2 Chrome/106.0.5249.199 Electron/21.4.3 Safari/537.36" etag="kXFsj5GcRiazvZ2mTRHP" version="21.1.2" type="device">
<diagram name="第 1 页" id="Hp0mWjxMjnIu5b5PPHpT">
<mxGraphModel dx="1098" dy="820" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="Hisepnijn4ny8SH6L1L8-29" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-1" target="Hisepnijn4ny8SH6L1L8-2">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-1" value="程序开始" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="280" y="320" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-30" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-2" target="Hisepnijn4ny8SH6L1L8-3">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-2" value="载入数据段" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="120" y="400" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-31" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-3" target="Hisepnijn4ny8SH6L1L8-4">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-3" value="输出提示信息" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="280" y="400" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-44" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-4" target="Hisepnijn4ny8SH6L1L8-37">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-4" value="读取字符串" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="440" y="400" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-48" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-6" target="Hisepnijn4ny8SH6L1L8-17">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-6" value="将字符串当前位数加1" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="120" y="720" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-11" value="N" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-10" target="Hisepnijn4ny8SH6L1L8-6">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-46" value="Y" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0.75;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-10" target="Hisepnijn4ny8SH6L1L8-37">
<mxGeometry x="-0.8824" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-10" value="循环次数是否用尽?" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="120" y="640" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-19" value="Y" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-17" target="Hisepnijn4ny8SH6L1L8-20">
<mxGeometry relative="1" as="geometry">
<mxPoint x="440" y="740" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-49" value="N" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-17" target="Hisepnijn4ny8SH6L1L8-10">
<mxGeometry x="-0.9167" relative="1" as="geometry">
<Array as="points">
<mxPoint x="340" y="800" />
<mxPoint x="80" y="800" />
<mxPoint x="80" y="660" />
</Array>
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-17" value="字符串的当前位与指定字符比较是否一样" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="280" y="720" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-50" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-20" target="Hisepnijn4ny8SH6L1L8-10">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="500" y="800" />
<mxPoint x="80" y="800" />
<mxPoint x="80" y="660" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-20" value="结果加1" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="440" y="720" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-35" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-25" target="Hisepnijn4ny8SH6L1L8-27">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-25" value="输出答案" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="360" y="480" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-27" value="程序结束" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="360" y="560" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-42" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-28" target="Hisepnijn4ny8SH6L1L8-10">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-28" value="指定循环次数为字符串长度" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="120" y="560" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-45" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.25;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-37" target="Hisepnijn4ny8SH6L1L8-28">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-47" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-37" target="Hisepnijn4ny8SH6L1L8-25">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-37" value="调用CNT子程序" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="200" y="480" width="120" height="40" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

BIN
Lab/Lab2/material/1.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
Lab/Lab2/material/2.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

View File

@ -0,0 +1,155 @@
![cover](cover.png)
# 一、实验目的
1. 了解汇编语言子程序的概念。
2. 掌握汇编语言子程序的定义、调用和返回。
3. 掌握设计汇编语言子程序及过程的基本方法。
4. 清楚调用指令CALL及返回指令RET执行时堆栈内容及指针的变化。
5. 掌握子程序和主程序间的参数传递方法。
# 二、实验内容
试编写一个有主程序和子程序结构的程序模块。
主程序要求从键盘接收一串字符并存于字节数组TABLE中显示字符CHAR出现的次数。
子程序在以TABLE为首地址的字节数组中查找CHAR统计出现的次数。
# 三、流程图
![graph](graph.drawio.svg)
# 四、实验过程与分析
![1](1.png)
将源代码放入MASM路径下编译。
没有警告和报错。
![2](2.png)
LINK链接程序。
![3](3.png)
出现提示信息。
![4](4.png)
输入字符串,按下回车。
程序打印出指定字符“**A**”出现的次数。
# 五、实验总结
在本实验中,我了解了汇编语言子程序的概念,掌握了汇编语言子程序的定义、调用和返回,以及设计汇编语言子程序及过程的基本方法。
# 六、思考题
> 子程序和主程序之间的参数传递是通过什么方式实现的?
通常情况下,主、子程序之间传递参数可以通过以下四种方式实现:
1. 寄存器传送参数
2. 存储单元传送参数
3. 堆栈传送参数或参数地址
4. 多模块之间的参数传递
**本实验程序使用寄存器传递参数。**
> 在DEBUG环境下观察执行CALL指令时CS、IP寄存器是否变化。
![5](5.png)
执行CALL指令的时候
- 如果是段内近调用不会改变CS但是IP会改变。本实验程序是这种情况如图所示可见CS不变IP变
- 如果是远调用CS和IP都会改变。
> 在DEBUG环境下观察执行CALL、RET时堆栈的变化。
![6](6.png)
![7](7.png)
由执行CALL前后SP值的变化和对应地址记录的值可知由于是近调用将IP压入栈中记录SP记录了要返回的IP=0017H。
由于DEBUG环境无法输入字符串很难观测RET指令执行时的情况。实际上RET时SP会回退原来CS和IP的值会退栈然后赋值给当前的CS和IP。
# 源代码附录
```assembly
DATA SEGMENT
CHAR DB 'A'
HINT1 DB 'Please enter a string: $'
HINT2 DB 10, 27H, 'A', 27H, ' occured time: $'
TIMES DB 0
MAXLEN DB 100
LEN DB 0
TABLE DB 100 DUP (0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV DX, OFFSET HINT1 ; 将HINT1的偏移地址赋给DX准备输出
MOV AH, 9 ; 输出
INT 21H
LEA DX, MAXLEN ; 0AH功能会获取DS:[DX](已定义为MAXLEN)作为输入缓冲区最大容量
MOV AH, 0AH ; 调用0AH功能将输入的字符串长度存入DS:[DX+1](已定义为LEN)
INT 21H ; 将字符串存入从DS:DX+2开始的空间(已定义为TABLE)
CALL CNT ; 统计字符“A”的数量结果在TIMES中
MOV DX, OFFSET HINT2 ; 将HINT2的偏移地址赋给DX准备输出
MOV AH, 9 ; 输出
INT 21H
MOV AL, TIMES
ADD AL, '0' ; TIMES += '0' (将数字信息转换成字符)
MOV DL, AL
MOV AH, 02H ; 显示单个字符
INT 21H
MOV AH,4CH
INT 21H
CNT PROC NEAR
MOV CX, 0
MOV CL, LEN
MOV SI, -1 ; SI是遍历TABLE的下标
MOV AL, CHAR ; 要比较的字符移到AL中(CMP不能比较两个内存单元)
LP:
INC SI
CMP AL, TABLE[SI]
JNE BACK ; 不相等则跳过INC TIMES重新循环
INC TIMES
BACK:
LOOP LP ; LOOP先将CX -= 1然后判断是否为0为0就退出循环
RET
CNT ENDP
CODE ENDS
END START
```

Binary file not shown.

BIN
Lab/Lab2/material/3.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

BIN
Lab/Lab2/material/4.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

BIN
Lab/Lab2/material/5.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
Lab/Lab2/material/6.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
Lab/Lab2/material/7.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

56
Lab/Lab2/material/code.asm Executable file
View File

@ -0,0 +1,56 @@
DATA SEGMENT
CHAR DB 'A'
HINT1 DB 'Please enter a string: $'
HINT2 DB 10, 27H, 'A', 27H, ' occured time: $'
TIMES DB 0
MAXLEN DB 100
LEN DB 0
TABLE DB 100 DUP (0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV DX, OFFSET HINT1 ; 将HINT1的偏移地址赋给DX准备输出
MOV AH, 9 ; 输出
INT 21H
LEA DX, MAXLEN ; 0AH功能会获取DS:[DX](已定义为MAXLEN)作为输入缓冲区最大容量
MOV AH, 0AH ; 调用0AH功能将输入的字符串长度存入DS:[DX+1](已定义为LEN)
INT 21H ; 将字符串存入从DS:DX+2开始的空间(已定义为TABLE)
CALL CNT ; 统计字符“A”的数量结果在TIMES中
MOV DX, OFFSET HINT2 ; 将HINT2的偏移地址赋给DX准备输出
MOV AH, 9 ; 输出
INT 21H
MOV AL, TIMES
ADD AL, '0' ; TIMES += '0' (将数字信息转换成字符)
MOV DL, AL
MOV AH, 02H ; 显示单个字符
INT 21H
MOV AH,4CH
INT 21H
CNT PROC NEAR
MOV CX, 0
MOV CL, LEN
MOV SI, -1 ; SI是遍历TABLE的下标
MOV AL, CHAR ; 要比较的字符移到AL中(CMP不能比较两个内存单元)
LP:
INC SI
CMP AL, TABLE[SI]
JNE BACK ; 不相等则跳过INC TIMES重新循环
INC TIMES
BACK:
LOOP LP ; LOOP先将CX -= 1然后判断是否为0为0就退出循环
RET
CNT ENDP
CODE ENDS
END START

BIN
Lab/Lab2/material/cover.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

105
Lab/Lab2/material/graph.drawio Executable file
View File

@ -0,0 +1,105 @@
<mxfile host="Electron" modified="2023-04-11T14:22:18.173Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.1.2 Chrome/106.0.5249.199 Electron/21.4.3 Safari/537.36" etag="ppF0kxKw4kt9IrtH2h0O" version="21.1.2" type="device">
<diagram name="第 1 页" id="Hp0mWjxMjnIu5b5PPHpT">
<mxGraphModel dx="1098" dy="820" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="Hisepnijn4ny8SH6L1L8-29" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-1" target="Hisepnijn4ny8SH6L1L8-2">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-1" value="程序开始" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="280" y="320" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-30" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-2" target="Hisepnijn4ny8SH6L1L8-3">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-2" value="载入数据段" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="120" y="400" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-31" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-3" target="Hisepnijn4ny8SH6L1L8-4">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-3" value="输出提示信息" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="280" y="400" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-44" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-4" target="Hisepnijn4ny8SH6L1L8-37">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-4" value="读取字符串" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="440" y="400" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-48" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-6" target="Hisepnijn4ny8SH6L1L8-17">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-6" value="将字符串当前位数加1" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="120" y="720" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-11" value="N" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-10" target="Hisepnijn4ny8SH6L1L8-6">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-46" value="Y" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0.75;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-10" target="Hisepnijn4ny8SH6L1L8-37">
<mxGeometry x="-0.8824" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-10" value="循环次数是否用尽?" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="120" y="640" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-19" value="Y" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-17" target="Hisepnijn4ny8SH6L1L8-20">
<mxGeometry relative="1" as="geometry">
<mxPoint x="440" y="740" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-49" value="N" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-17" target="Hisepnijn4ny8SH6L1L8-10">
<mxGeometry x="-0.9167" relative="1" as="geometry">
<Array as="points">
<mxPoint x="340" y="800" />
<mxPoint x="80" y="800" />
<mxPoint x="80" y="660" />
</Array>
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-17" value="字符串的当前位与指定字符比较是否一样" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="280" y="720" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-50" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-20" target="Hisepnijn4ny8SH6L1L8-10">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="500" y="800" />
<mxPoint x="80" y="800" />
<mxPoint x="80" y="660" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-20" value="结果加1" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="440" y="720" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-35" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-25" target="Hisepnijn4ny8SH6L1L8-27">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-25" value="输出答案" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="360" y="480" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-27" value="程序结束" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="360" y="560" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-42" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-28" target="Hisepnijn4ny8SH6L1L8-10">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-28" value="指定循环次数为字符串长度" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="120" y="560" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-45" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.25;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-37" target="Hisepnijn4ny8SH6L1L8-28">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-47" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="Hisepnijn4ny8SH6L1L8-37" target="Hisepnijn4ny8SH6L1L8-25">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="Hisepnijn4ny8SH6L1L8-37" value="调用CNT子程序" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="200" y="480" width="120" height="40" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 22 KiB

BIN
Lab/Lab2/实验2 查找字符.doc Executable file

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,58 @@
<mxfile host="Electron" modified="2023-05-06T14:49:58.247Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.2.8 Chrome/112.0.5615.165 Electron/24.2.0 Safari/537.36" etag="gX_Ezp9wm0UEAzm5YIdF" version="21.2.8" type="device">
<diagram name="第 1 页" id="3iH2U7M1F-pdt02PPPwc">
<mxGraphModel dx="824" dy="768" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="LjnWuoztt-sNhJGu1yFB-8" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="LjnWuoztt-sNhJGu1yFB-1" target="LjnWuoztt-sNhJGu1yFB-2">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-1" value="程序开始" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="360" y="160" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-9" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="LjnWuoztt-sNhJGu1yFB-2" target="LjnWuoztt-sNhJGu1yFB-3">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-2" value="向命令口发送命令将PA口置为1方式输入PB口置为0方式输出" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="320" y="240" width="200" height="40" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-10" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="LjnWuoztt-sNhJGu1yFB-3" target="LjnWuoztt-sNhJGu1yFB-4">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-3" value="将PB口输出全零灭掉所有LED灯" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="360" y="320" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-11" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="LjnWuoztt-sNhJGu1yFB-4" target="LjnWuoztt-sNhJGu1yFB-5">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-4" value="通过PA口获取各个开关状态到AL" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="360" y="400" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-12" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="LjnWuoztt-sNhJGu1yFB-5" target="LjnWuoztt-sNhJGu1yFB-6">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-5" value="向PB口输出AL" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="360" y="480" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-13" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="LjnWuoztt-sNhJGu1yFB-6" target="LjnWuoztt-sNhJGu1yFB-7">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-6" value="进入延时子程序,延时一小段时间" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="360" y="560" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-14" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="LjnWuoztt-sNhJGu1yFB-7" target="LjnWuoztt-sNhJGu1yFB-5">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="420" y="700" />
<mxPoint x="320" y="700" />
<mxPoint x="320" y="500" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-7" value="使用ROR指令AL向右移一位" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="360" y="640" width="120" height="40" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

View File

@ -0,0 +1,58 @@
<mxfile host="Electron" modified="2023-05-06T15:21:41.040Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.2.8 Chrome/112.0.5615.165 Electron/24.2.0 Safari/537.36" etag="wLXNmcTcuL1nMTwf1z0g" version="21.2.8" type="device">
<diagram name="第 1 页" id="3iH2U7M1F-pdt02PPPwc">
<mxGraphModel dx="841" dy="768" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="LjnWuoztt-sNhJGu1yFB-8" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="LjnWuoztt-sNhJGu1yFB-1" target="LjnWuoztt-sNhJGu1yFB-2" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-1" value="程序开始" style="ellipse;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="360" y="160" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-9" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="LjnWuoztt-sNhJGu1yFB-2" target="LjnWuoztt-sNhJGu1yFB-3" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-2" value="向命令口发送命令将PA口置为0方式输入PB口置为0方式输出" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="320" y="240" width="200" height="40" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-10" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="LjnWuoztt-sNhJGu1yFB-3" target="LjnWuoztt-sNhJGu1yFB-4" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-3" value="将PB口输出全零灭掉所有LED灯" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="360" y="320" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-11" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="LjnWuoztt-sNhJGu1yFB-4" target="LjnWuoztt-sNhJGu1yFB-5" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-4" value="通过PA口获取各个开关状态到AL" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="360" y="400" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-12" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="LjnWuoztt-sNhJGu1yFB-5" target="LjnWuoztt-sNhJGu1yFB-6" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-5" value="向PB口输出AL" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="360" y="480" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-13" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="LjnWuoztt-sNhJGu1yFB-6" target="LjnWuoztt-sNhJGu1yFB-7" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-6" value="进入延时子程序,延时一小段时间" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="360" y="560" width="120" height="40" as="geometry" />
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-14" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="LjnWuoztt-sNhJGu1yFB-7" target="LjnWuoztt-sNhJGu1yFB-5" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="420" y="700" />
<mxPoint x="320" y="700" />
<mxPoint x="320" y="500" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="LjnWuoztt-sNhJGu1yFB-7" value="使用ROR指令AL向右移一位" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="360" y="640" width="120" height="40" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

View File

@ -0,0 +1,240 @@
![cover](cover.png)
<h1><center><strong>实验二 利用8255A实现LED的流水点亮实验</strong></center></h1>
### 一、实验目的
该实验的目的在于掌握8255A和微机接口的连接方法了解8255A的基本的工作原理和编程方法。
### 二、实验内容
**任务一:**PA口接8个拨动开关K1-K8PB口接8个LED。初始由开关K1-K8设定8位不同的值当执行程序后LED按K1-K8初始设定的值点亮并向右流动8255A工作在0方式
**任务二:**在数码管上显示“8255-A”。
### 三、流程图
**任务一:**
![task1.drawio](task1.drawio.svg)
**任务二:**
![task2.drawio](task2.drawio.svg)
### 四、实验过程与分析
**任务一:**
首先在实验箱中将接线连好。将8255A芯片的CS连到280H地址。因此命令口为283HPA口为280HPB口为281HPC口为282H。
将PA口连到开关上PB口连到LED灯上。
然后设置好开关。将代码编译后运行。运行效果如视频所示。
**任务二:**
首先在实验箱中将接线连好。将8255A芯片的CS连到280H地址。将PA口连到位码接口上PB口连到段码接口上。
<img src="task2.jpg" alt="task2" style="zoom:25%;" />
将代码编译后运行。运行效果如图所示。
### 五、实验总结
在本实验中我掌握了8255A和微机接口的连接方法了解了8255A的基本的工作原理和编程方法收获颇丰。
### 六、思考题
> 在本实验的硬件电路中能使用C口对LED指示灯控制码如果可以写出2种控制方法编程方法
**控制方法一:**使用命令口直接将PC口置位。
```assembly
MOV DX, 283H ; 设置命令口
MOV AL, 00000101B ; 0|xxx|010(指定PC2引脚)|1(置位)
OUT DX, AL ; 输出
```
**控制方法二:**使用方式0将PC口置为数据输出口。
```assembly
MOV DX, 283H
MOV AL, 10000000B ; 1|00(A组0方式)|0(PA输入)|0(PC4-7输出)|0(B组0方式)|0(PB输出)|0(PC0-3输出)
OUT DX, AL
MOV DX, 282H
MOV AL, 00000001B ; PC1为高电平
OUT DX, AL
```
### 源代码附录
**任务一:**
```assembly
DATA SEGMENT
T DW 0FFH
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV DX, 283H ; 命令口
MOV AL, 10010000B ; 1|00(A组0方式)|1(PA输入)|0(PC4-7输出)|0(B组0方式)|0(PB输出)|0(PC0-3输出)
OUT DX, AL
MOV DX, 281H ; B口
MOV AL, 00H ; LED全置0
OUT DX, AL
MOV DX, 280H ; A口
IN AL, DX ; 读入到AL
MOV DX, 281H ; B口
LP:
OUT DX, AL ; 从B口输出AL
CALL DELAY ; 延时
ROR AL, 1 ; ROR(Rotate Right)把AL向右移1位移出的位补到左边实现走马灯
JMP LP ; 无限循环
DELAY PROC
PUSH BX
PUSH AX
MOV BX, T
MOV AX, T
DL1:
DL2:
DEC BX
JNZ DL1
DEC AX
JNZ DL2
POP AX
POP BX
RET
DELAY ENDP
CODE ENDS
END START
```
**任务二:**
```assembly
DATA SEGMENT
EIGHT DB 7FH
TWO DB 5BH
FIVE DB 6DH
BAR DB 40H
A DB 77H
T DW 0FFH
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV DX, 283H ; 命令口
MOV AL, 10000000B ; 1|00(A组0方式)|0(PA输出)|0(PC4-7输出)|0(B组0方式)|0(PB输出)|0(PC0-3输出)
OUT DX, AL
LP:
MOV DX, 280H ; A口控制位码
MOV AL, 10000000B ; 第1位PA1置1
OUT DX, AL
MOV DX, 281H ; B口控制段码
MOV AL, EIGHT ; 输出数据段定义的字符“8”
OUT DX, AL
CALL DELAY ; 延时后清零
MOV DX, 280H
MOV AL, 01000000B ; 第2位PA2置1
OUT DX, AL
MOV DX, 281H
MOV AL, TWO ; 输出数据段定义的字符“2”
OUT DX, AL
CALL DELAY
MOV DX, 280H
MOV AL, 00100000B ; 第3位PA3置1
OUT DX, AL
MOV DX, 281H
MOV AL, FIVE ; 输出数据段定义的字符“5”
OUT DX, AL
CALL DELAY
MOV DX, 280H
MOV AL, 00010000B ; 第4位PA4置1
OUT DX, AL
MOV DX, 281H
MOV AL, FIVE ; 输出数据段定义的字符“5”
OUT DX, AL
CALL DELAY
MOV DX, 280H
MOV AL, 00001000B ; 第5位PA5置1
OUT DX, AL
MOV DX, 281H
MOV AL, BAR ; 输出数据段定义的字符“-”
OUT DX, AL
CALL DELAY
MOV DX, 280H
MOV AL, 00000100B ; 第6位PA6置1
OUT DX, AL
MOV DX, 281H
MOV AL, A ; 输出数据段定义的字符“A”
OUT DX, AL
CALL DELAY
JMP LP ; 无限循环
DELAY PROC
PUSH BX
MOV BX, T
DL1:
DEC BX
JNZ DL1
POP BX
; 将位码段码都置0否则前一位显示的字符会在显示下一位字符显示前在该位上显示
MOV DX, 280H
MOV AL, 00000000B
OUT DX, AL
MOV DX, 281H
MOV AL, 0
OUT DX, AL
RET
DELAY ENDP
CODE ENDS
END START
```

BIN
Lab/Lab3/material/cover.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Some files were not shown because too many files have changed in this diff Show More