├── LICENSE ├── README.md └── code ├── Forec ├── t1.asm ├── t10.asm ├── t11.asm ├── t12.asm ├── t13.asm ├── t14.asm ├── t15.asm ├── t16.asm ├── t17.asm ├── t18.asm ├── t19.asm ├── t2.asm ├── t20(法1).asm ├── t20(法2).asm ├── t21.asm ├── t22.asm ├── t23.asm ├── t24.asm ├── t25.asm ├── t26.asm ├── t27.asm ├── t28.asm ├── t29.asm ├── t3.asm ├── t30.asm ├── t31.asm ├── t32.asm ├── t34.asm ├── t35.asm ├── t36.asm ├── t37.asm ├── t38.asm ├── t4.asm ├── t40.asm ├── t41.asm ├── t42.asm ├── t43.asm ├── t44.asm ├── t45.asm ├── t46.asm ├── t47.asm ├── t5.asm ├── t50.asm ├── t6.asm ├── t7.asm ├── t75.asm ├── t8.asm ├── t9(法1).asm └── t9(法2).asm ├── YeWenting ├── T11.asm ├── T13.asm ├── T15.asm ├── T17.asm ├── T19.asm ├── T21.asm ├── T23.asm ├── T25.asm ├── T27.asm ├── T29.asm ├── T31.asm ├── T4.asm ├── T5.asm ├── T9.asm ├── book4-16.asm ├── book4-28.asm ├── t1.asm ├── t2.asm └── t3.asm ├── dsryhh ├── 11.asm ├── 12.asm ├── 15.asm ├── 19.asm ├── 29.asm ├── 44.asm ├── 77.asm └── 9.asm ├── non1996 ├── 1-(1).asm ├── 1-(2).asm ├── 10.asm ├── 11.asm ├── 12.asm ├── 13.asm ├── 14.asm ├── 15.asm ├── 16.asm ├── 17.asm ├── 18.asm ├── 19.asm ├── 2.asm ├── 20.asm ├── 21.asm ├── 22.asm ├── 23.asm ├── 24.asm ├── 25.asm ├── 26.asm ├── 27.asm ├── 28.asm ├── 29.asm ├── 3.asm ├── 30.asm ├── 31.asm ├── 34.asm ├── 35.asm ├── 36.asm ├── 4.asm ├── 40.asm ├── 5.asm ├── 6.asm ├── 7.asm ├── 8.asm └── 9.asm ├── occupying └── t1.asm └── seagullbird ├── 4_16.asm ├── t10.asm ├── t11.asm ├── t13.asm ├── t15.asm ├── t17.asm ├── t19.asm ├── t21.asm ├── t23.asm ├── t25.asm ├── t27.asm ├── t29.asm ├── t31.asm ├── t6.asm ├── t7.asm ├── t8.asm └── t9.asm /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015-2017, Forec 2 | 3 | Permission to use, copy, modify, and/or distribute this code for any 4 | purpose with or without fee is hereby granted, provided that the above 5 | copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 汇编基础习题集 2 | 3 | > 此仓库中代码为我学习汇编过程中解决过的习题,如果你有其它相关练习打算分享,欢迎提 PR 补充。 **你可以将你的解法分享到此仓库中,如果你有此意愿,请 fork 后在 `code` 目录下新建一个以你名称命名的文件夹,将你的解法放置在该文件夹下,将你的名字添加到此 `README` 末尾的参与者列表,并提交 PR**。如果需要许可声明,请在你的目录下自行添加。 4 | 5 | ## 题目来源 6 | * 1 ~ 40 题:北京邮电大学,计算机学院,微机原理与接口技术课程补充习题(此部分习题的使用已告知相关课程老师) 7 | * 41 ~ 74 题:选自[中山市飞蛾软件工作室](http://www.feiesoft.com/asm/),此部分习题的实现可参考以下资料: 8 | * [中断列表](http://www.feiesoft.com/asm/appendix3.html) 9 | * [DOS和BIOS的宏定义](http://www.feiesoft.com/asm/appendix4.html) 10 | * [键盘按键各种编码对照表](http://www.feiesoft.com/asm/appendix5.html) 11 | * 75 ~ 77 题:电子工业出版社,《微机原理与接口技术》书后习题,ISBN 978-7-121-11602-5 12 | 13 | ## 环境配置 14 | * Windows 7 及以上版本:建议使用 `DOSBOX`,当前最新版本 `0.74`。需下载 `masm.exe`,`link.exe`,`debug.exe`。也可以选择 `emu8086`,但该软件使用的汇编语言标准与 MASM 有差异。`DOSBOX` 及配套的工具可以从[此处](http://7xktmz.com1.z0.glb.clouddn.com/dosbox-masm.rar)下载。安装 `DOSBOX` 后运行安装目录下的 `DOSBox 0.74 Options.bat`,在打开的 `dosbox-0.74.conf` 文件最后加上以下两句。其中 `path_to_your_tool` 需替换为你的 `masm.exe`等工具所在的目录。要运行代码,请将代码复制到 `path_to_your_tool` 目录下,之后启动 `DOSBOX`,在 `DOSBOX` 环境下编译、调试。 15 | ``` 16 | MOUNT C path_to_your_tool 17 | set PATH=$PATH$;path_to_your_tool 18 | ``` 19 | 20 | * Linux/Mac:请访问 `DOSBOX` 官网的 [Download](http://www.dosbox.com/download.php?main=1) 界面,寻找自己系统对应的版本安装。 21 | * 编译、链接,以 `test.asm` 为例。 22 | ``` 23 | masm test.asm 24 | link test.obj 25 | ``` 26 | 27 | ## 习题 28 | 29 | **建议:在解决问题本身的前提下,应尽量使程序有更好的容错性,能够尽可能处理非常规输入等可能引发异常的情况;应尽量使程序更好地面向用户,优化交互界面。** 30 | 31 | * 1、在 `ARRAY` 数组中依次存储了七个字数据,紧接着是名为 `ZERO` 的字单元,表示如下: 32 | (1) 如果 BX 包含数组 `ARRAY` 的初始地址,请编写指令将数据 0 传送给 `ZERO` 单元。 33 | (2) 如果 BX 包含数据 0 在数组中的位移量,请编写指令将数据 0 传送给 `ZERO` 单元。 34 | ```asm 35 | ARRAY DW 23, 36, 2, 100, 32000, 54, 0 36 | ZERO DW ? 37 | ``` 38 | 39 | * 2、请设置一个数据段 `DATASG`,其中定义以下字符变量或数据变量。 40 | (1) `FLD1B` 为字符串变量:`personal computer`; 41 | (2) `FLD2B` 为十进制数字节变量:`32`; 42 | (3) `FLD3B` 为十六进制数字节变量:`20`; 43 | (4) `FLD4B` 为二进制数字节变量:`01011001`; 44 | (5) `FLD5B` 为数字的ASCII字符字节变量:`32654`; 45 | (6) `FLD6B` 为10个零的字节变量; 46 | (7) `FLD7B` 为零件名(ASCII码)及其数量(十进制数)的表格: 47 | `PART1 20` 48 | `PART2 50` 49 | `PART3 14` 50 | (8) `FLD1W` 为十六进制数字变量:`FFF0`; 51 | (9) `FLD2W` 为二进制数的字变量:`01011001`; 52 | (10) `FLD3W` 为 (7) 零件表的地址变量; 53 | (11) `FLD4W` 为包括5个十进制数的字变量:`5, 6, 7, 8, 9`; 54 | (12) `FLD5W` 为5个零的字变量; 55 | (13) `FLD6W` 为本段中字数据变量和字节数据变量之间的地址差。 56 | 57 | * 3、假设程序中的数据定义如下: 58 | ``` 59 | PARTNO DW ? 60 | PNAME DB 16 DUP (?) 61 | COUNT DD ? 62 | PLENTH EQU $-PARTNO 63 | ``` 64 | 请问 `PLENTH` 的值为多少?它表示什么意义? 65 | 66 | * 4、有符号定义语句如下,问 L 的值是多少? 67 | ```asm 68 | BUFF DB 1, 2, 3, ‘123’ 69 | EBUFF DB 0 70 | L EQU EBUFF - BUFF 71 | ``` 72 | 73 | * 5、假设程序中的数据定义如下: 74 | (1) 用一条 `MOV` 指令将 `LNAME` 的偏移地址放入 AX 。 75 | (2) 用一条指令将 `CODE_LIST` 的头两个字节的内容放入 SI 。 76 | (3) 用一条伪操作使 `CODE_LENGTH` 的值等于 `CODE_LIST` 域的实际长度。 77 | ```asm 78 | LNAME DB 30 DUP (?) 79 | ADDRESS DB 30 DUP (?) 80 | CITY DB 15 DUP (?) 81 | CODE_LIST DB 1, 7, 8, 3, 2 82 | ``` 83 | 84 | * 6、试写出一个完整的数据段 `DATA_SEG` ,它把整数 5 赋予一个字节,并把整数 -1,0,2,5 和 4 放在 10 字数组 `DATA_LIST` 的头 5 个单元中。然后,写出完整的代码段,其功能为: 85 | 把 `DATA_LIST` 中头5个数中的最大值和最小值分别存入 `MAX` 和 `MIN` 单元中。 86 | 87 | * 7、按下面的要求写出程序的框架 88 | (1) 数据段的位置从 `0E000H` 开始,数据段中定义一个 100 字节的数组,其类型属性既是字又是字节; 89 | (2) 堆栈段从小段开始,段组名为 `STACK` ; 90 | (3) 代码段中指定段寄存器,指定主程序从 `1000H` 开始,给有关段寄存器赋值; 91 | (4) 程序结束。 92 | 93 | * 8、写一个完整的程序放在代码段 `C_SEG` 中,要求把数据段 `D_SEG` 中的 `AUGEND` 和附加段`E_SEG` 中的 `ADDEND` 相加,并把结果存放在 `D_SEG` 段中的 `SUM` 中。其中 `AUGEND` 、 `ADDEND` 和 `SUM` 均为双精度数,`AUGEND` 赋值为 99251 ,`ADDEND` 赋值为 -15962。 94 | 95 | * 9、试编写一个汇编语言程序,要求对键盘输入的小写字母用大写字母显示出来。 96 | 97 | * 10、编写程序,从键盘接收一个小写字母,然后找出它的前导字符和后续字符,再按顺序显示这三个字符。 98 | 99 | * 11、将 AX 寄存器中的 16 位数分成 4 组,每组 4 位,然后把这四组数分别放在 AL、 BL、 CL和 DL 中。 100 | 101 | * 12、试编写一程序,要求比较两个字符串 `STRING1` 和 `STRING2` 所含字符是否完全相同,若相同则显示 `MATCH`,若不相同则显示 `NO MATCH`。 102 | 103 | * 13、试编写一程序,要求能从键盘接收一个个位数 N ,然后响铃 N 次(响铃的 ASCII 码为 `07H` )。 104 | 105 | * 14、编写程序,将一个包含有 20 个数据的数组 M 分成两个数组:正数数组 P 和负数数组 N ,并分别把这两个数组中数据的个数显示出来。 106 | 107 | * 15、试编写一个汇编语言程序,求出首地址为 `DATA` 的 `100D` 字数组中的最小偶数,并把它存放在 AX 中。 108 | 109 | * 16、把 AX 中存放的 16 位二进制数 K 看作是 8 个二进制的 “四分之一字节”。试编写程序,数一下值为 3 (即 11B)的四分之一字节数,并将该数(即 11B 的个数)在终端上显示出来。 110 | 111 | * 17、试编写一个汇编语言程序,要求从键盘接收一个四位的 16 进制数,并在终端上显示与它等值的二进制数。 112 | 113 | * 18、设有一段英文,其字符变量名为 `ENG` ,并以 `$` 字符结束。试编写一程序,查对单词 `SUN` 在该文中的出现次数,并以格式 `SUN:xxxx` 显示出次数。 114 | 115 | * 19、从键盘输入一系列以 `$` 为结束符的字符串,然后对其中的非数字字符计数,并显示出计数结果。 116 | 117 | * 20、有一个首地址为 `MEM` 的 100D 字数组,试编制程序删除数组中所有为 0 的项,并将后续项向前压缩,最后将数组的剩余部分补上 0 。 118 | 119 | * 21、在 `STRING` 到 `STRING+99` 单元中存放着一个字符串,试编制一个程序测试该字符串中是否存在数字,如有则把 CL 的第 5 位置 1 ,否则将该位置0。 120 | 121 | * 22、在首地址为 `TABLE` 的数组中按递增次序存放着 100H 个 16 位补码数,试编写一个程序把出现次数最多的数及其出现次数分别存放于 AX 和 CX 中。 122 | 123 | * 23、数据段中已定义了一个有 n 个字数据的数组 M ,试编写一程序求出 M 中绝对值最大的数,把它放在数据段的 `M+2n` 单元中,并将该数的偏移地址存放在 `M+2(n+1)` 单元中。 124 | 125 | * 24、在首地址为 `DATA` 的字数组中存放着 100H 个 16 位补码数,试编写一个程序求出它们的平均值放在 AX 寄存器中;并求出数组中有多少个数小于此平均值,将结果放在 BX 寄存器中。 126 | 127 | * 25、试编制一个程序把 AX 中的 16 进制数转换为 ASCII 码,并将对应的 ASCII 码依次存放到 `MEM` 数组中的四个字节中。例如,当 `(AX)=2A49H` 时,程序执行完后, `MEM` 中的4个字节内容为`39H`,`34H`,`41H`,`32H`。 128 | 129 | * 26、把 0~100D 之间的 30 个数存入以 `GRADE` 为首地址的 30 字数组中,`GRADE+i` 表示学号为`i+1` 的学生的成绩。另一个数组 `RANK` 为 30 个学生的名次表,其中 `RANK+i` 的内容是学号为 `i+1` 的学生的名次。编写一程序,根据 `GRADE` 中的学生成绩,将学生名次填入 `RANK` 数组中。(提示:一个学生的名次等于成绩高于这个学生的人数加1。) 130 | 131 | * 27、已知数组 A 包含 15 个互不相等的整数,数组 B 包含 20 个互不相等的整数。试编制一程序把既在 A 中又在 B 中出现的整数存放于数组 C 中。 132 | 133 | * 28、设在 A、B 和 C 单元中分别存放着三个数。若三个数都不是 0,则求出三数之和存放在 D 单元中;若其中有一个数为 0,则把其它两单元也清 0。请编写此程序。 134 | 135 | * 29、试编写一程序,要求比较数组 `ARRAY中` 的三个 16 位补码数,并根据比较结果在终端上显示如下信息: 136 | 1. 如果三个数都不相等则显示0; 137 | 2. 如果三个数有二个数相等则显示1; 138 | 3. 如果三个数都相等则显示2。 139 | 140 | * 30、从键盘输入一系列字符(以回车符结束),并按字母、数字、及其它字符分类计数,最后显示出这三类的计数结果。 141 | 142 | * 31、已定义了两个整数变量 A 和 B ,试编写程序完成下列功能: 143 | 1. 若两个数中有一个是奇数,则将奇数存入A中,偶数存入B中; 144 | 2. 若两个数中均为奇数,则将两数加1后存回原变量; 145 | 3. 若两个数中均为偶数,则两个变量均不改变。 146 | 147 | * 32、假设已编制好 5 个歌曲程序,它们的段地址和偏移地址存放在数据段的跳跃表 `SINGLIST` 中。试编制一程序,根据从键盘输入的歌曲编号 1~5,转去执行五个歌曲程序中的某一个。 148 | 149 | * 33、下面的程序段有错吗?若有,请指出错误。 150 | ```asm 151 | CRAY PROC 152 | PUSH AX 153 | ADD AX, BX 154 | RET 155 | ENDP CRAY 156 | ``` 157 | 158 | * 34、写一段子程序 `SKIPLINES` ,完成输出空行的功能。空出的行数在 AX 寄存器中。 159 | 160 | * 35、设有 10 个学生的成绩分别是 76,69,84,90,73,88,99,63,100 和 80 分。试编制一个子程序统计 60~69 分,70~79 分,80~89 分,90~99 分和 100 分的人数,分别存放到 S6,S7,S8,S9 和 S10 单元中。 161 | 162 | * 36、编写一个有主程序和子程序结构的程序模块。子程序的参数是一个 N 字节数组的首地址 `TABLE`,数 N 及字符 `CHAR` 。要求在 N 字节数组中查找字符 `CHAR`,并记录该字符出现的次数。主程序则要求从键盘接收一串字符以建立字节数组 `TABLE`,并逐个显示从键盘输入的每个字符 `CHAR`以及它在 `TABLE` 数组中出现的次数。(为简化起见,假设出现次数 ≤ 15,可以用 16 进制形式把它显示出来。) 163 | 164 | * 37、编写一个子程序嵌套结构的程序模块,分别从键盘输入姓名及 8 个字符的电话号码,并以一定的格式显示出来。 165 | * 主程序 `TELIST`: 166 | * 显示提示符 `INPUT NAME:`; 167 | * 调用子程序 `INPUT_NAME` 输入姓名; 168 | * 显示提示符 `INPUT A TELEPHONE NUMBER:`; 169 | * 调用子程序 `INPHONE` 输入电话号码; 170 | * 调用子程序 `PRINTLINE` 显示姓名及电话号码。 171 | * 子程序 `INPUT_NAME`: 172 | * 调用键盘输入子程序 `GETCHAR` ,把输入的姓名存放在 `INBUF` 缓冲区中; 173 | * 把 `INBUF` 中的姓名移入输出行 `OUTNAME`。 174 | * 子程序 `INPHONE`: 175 | * 调用键盘输入子程序 `GETCHAR` ,把输入的 8 位电话号码存放在 `INBUF` 缓冲区中; 176 | * 把 `INBUF` 中的号码移入输出行 `OUTPHONE`。 177 | * 子程序 `PRINTLINE`: 178 | * 显示姓名及电话号码,格式为: 179 | ``` 180 | NAME TEL 181 | XXX XXXXXXXX 182 | ``` 183 | 184 | * 38、编写子程序嵌套结构的程序,把整数分别用二进制和八进制形式显示出来。 185 | 主程序 `BANDO` :把整数字变量 `VAL1` 存入堆栈,并调用子程序 `PAIRS` ; 186 | 子程序 `PAIRS` :从堆栈中取出 `VAL1`;调用二进制显示程序 `OUTBIN` 显示出与其等效的二进制数;输出 8 个空格;调用八进制显示程序 `OUTOCT` 显示出与其等效的八进制数;调用输出回车及换行符子程序。 187 | 188 | * 39、假定一个名为 `MAINPRO` 的程序要调用子程序 `SUBPRO`,试问: 189 | 1. `MAINPRO` 中的什么指令告诉汇编程序 `SUBPRO` 是在外部定义的? 190 | 2. `SUBPRO` 怎么知道 `MAINPRO` 要调用它? 191 | 192 | * 40、定义宏指令 `FINSUM`:比较两个数 X 和 Y (X、Y为数,而不是地址),若 X > Y 则执行 `SUM←X+2*Y`;否则执行 `SUM←2*X+Y`。 193 | 194 | * 41、把下列C语句的语句改写成功能相同的汇编语言程序片段(其中:变量都为整型变量)。 195 | ``` h = (key & 0XFF00) >> 8; 196 | k = (k + '1' – 0xabcd) / 56; 197 | for (i = s = 0; i < 100; i++) s += data[i]* 2; 198 | for (s = 0, i = 100; i > 0; i--) s += i *2; 199 | ``` 200 | * 42、把下列C语言的语句改写成等价的汇编语言程序段(不考虑运算过程中的溢出)。其中:变量a、b和c都是有符号的整型(int)变量。 201 | ```c 202 | if (a<1 || b/4 > 10 && c%8==5) { 203 | a = 20+b++; 204 | c <<= 2; 205 | } 206 | else { 207 | a = 21-(++c); 208 | b--; 209 | } 210 | ``` 211 | 212 | * 43、假设内存单元中有三个字 a、b和 c,编写一个程序,它可判断它们能否构成一个三角形,若能,CF 为 1,否则,CF 为 0。 213 | 214 | * 44、假设有二十个无符号字存放在以 `Buffer` 为开始的缓冲区中,编写一个程序把它们从低到高排序。 215 | 216 | * 45、编写一个程序,它把 CH 和 CL 中的二进制位依次交叉存入 AX 中。 217 | 218 | * 46、编写一个程序,求出从内存单元 `1000:0000` 开始的 1024 个字的 32 位累加和,并把该值存入程序中的变量 Data 中。 219 | 220 | * 47、用双重循环把下三角乘法表存入从 `product` 开始的 45 个字节中。 221 | 222 | * 48、表示源程序结束的伪指令是什么?在其后所编写的指令在被汇编吗? 223 | 224 | * 49、汇编语言程序一定会从代码段的第一条指令开始执行吗?如果不是,如何指定程序的入口地址? 225 | 226 | * 50、编写一个程序,它把字符串 `String` 两端的空格和数字字符删除(字符串以 `$` 结束)。 227 | 228 | * 51、编写子程序实现下列功能,参数的传递方式可自行决定(假设所有变量都是字类型)。 229 | `abs(x) = |x|` 230 | `f(x) = x^2+ 5x – 8` 231 | `strlen(String)` 232 | 233 | * 52、为什么要区分IRET指令与RET指令? 234 | 235 | * 53、编写一个控制光标位置和形状的程序,该程序具有以下功能: 236 | * 可用光标移动键 ↑ 、 ↓ 、 ← 和 → 来移动光标; 237 | * 当光标已在第 0 列,且按 ← 键时,光标定在上一行的最后一列;若已在屏幕的左上角,则光标不动,且给出响铃;按 → 键时的边界处理类似; 238 | * 当光标在第 0 行,且按 ↑ 键时,则光标不动,且给出响铃;按 ↓ 键时的边界处理类似; 239 | * 按 Home 或 End 键,则光标移到当前行的行首或行尾; 240 | * 若按下数字或字母键,则把该字符从当前位置依次显示到屏幕顶(在新位置显示字符时,原位置的符号被抹去); 241 | * 按 `Esc` 键,程序结束。 242 | 243 | * 54、假设显示器的显示模式设定为 12H ,编写实现下列功能的程序: 244 | * 在屏幕中间从上到下显示一条明亮的蓝色线,线宽为1个像素; 245 | * 在屏幕底下横向画一条绿色线,线宽为 2 个像素; 246 | * 在屏幕上垂直显示 16 种颜色,每种颜色宽 40 个像素; 247 | * 设定屏幕背景为白色,在屏幕中间画一条青色线,线宽为 10 个像素。 248 | 249 | * 55、编写程序,检测计算机是否已安装了鼠标,并以显示Yes/No来表示检测结果。 250 | 251 | * 56、编写程序,显示鼠标的按键,若按左键,显示 `Left` ,若按右键,显示 `Right` ,按 `Esc` 键,程序结束。 252 | 253 | * 57、编写一个程序,在图形模式下,打开鼠标,并显示鼠标的位置。 254 | 255 | * 58、编写一个程序,显示驱动器 C 根目录下所有 EXE 文件(提示:用通配符"*.exe"来查找与此匹配的文件名,找到后,显示之)。 256 | 257 | * 59、编写一个程序,显示驱动器 C 根目录下的所有子目录。 258 | 259 | * 60、编写一个程序,设置指定目录下的所有文件为只读文件。 260 | 261 | * 61、编写一个程序,创建一个隐含文件 `Data.TXT`。 262 | 263 | * 62、编写一个程序,把键盘上输入写入文件 `File.dat` 中,类似以下 DOS 命令: 264 | ``` 265 | COPY con File.dat 266 | ``` 267 | 268 | * 63、编写一个宏,它产生 n 条 NOP 指令,其中n是宏的形式参数。 269 | 270 | * 64、编写只有一个形式参数的宏PRINT,其具体功能如下(提示:用 IFB 或 IFNB 语句来测试是否有参数): 271 | * 若引用时带有参数,则在屏幕上显示其参数字符,如:`PRINT 'A'`,则显示字符 'A'; 272 | * 若引用时不带实参,则显示回车和换行,如:`PRINT`。 273 | 274 | * 65、编写一个在屏幕上连续显示 `Welcome…` 的信息,要求显示颜色和显示位置都是随机的。在新位置显示时,原位置的信息抹去。当按任意键时,程序结束运行。 275 | 276 | * 66、从键盘输入一个表示年份的正整数(1 ~ 65535),然后判断其是否为闰年。若是,则输出 `Yes`,否则,输出 `No`。 277 | 278 | * 67、编写一个带命令行参数的程序 Words ,输出指定正文文件中的单词,假设单词为连续的字母串。比如:`words file.txt`,显示文件 `file.txt` 中的每个单词 279 | 280 | * 68、编写一个建立双向链表的程序,每接受一个整数,链表增加一个结点,当遇到负数时,结束链表结点的增加,然后从表尾向前输出各结点中的数值。 281 | 282 | * 69、编写一个带命令行参数的程序 Calc ,其命令行参数是一些整数,程序输出它们之和。如果某参数为非法整数,则忽略之。比如:`Calc 120 +34 -56`,则程序显示 98。 283 | 284 | * 70、在 68 的基础上,在不考虑运算符优先级的情况下,实现一个可进行算术四则运算(只有加、减、乘和除,没有括号等)的计算器。 285 | 286 | * 71、编写一个简单的加密程序,它把一个文件中的所有字母字符按下列规律进行转换,非字母的字符保持不变。转换规律:'A' → 'Z','B' → 'Y',……。 287 | 288 | * 72、编写一个程序,它可显示 BMP 的图形文件。 289 | 290 | * 73、编写一个程序,它可显示 JPG 的图形文件。 291 | 292 | * 74、编写一个程序,求出 2 ~ 100 之内的所有素数。 293 | 294 | * 75、假设从变量 `Buff` 开始存放了 200 个字,编写一个程序统计出其正数、0和负数个数,并把它们分别存入 `N1`、`N2` 和 `N3` 中。 295 | 296 | * 76、给定一个正数 `n >= 1` 存放在 `num` 字变量,试编写递归子程序计算 `FIB(n)`,结果保存到 `RESULT` 变量中。 297 | 298 | * 77、一个学生的信息包括姓名、班级、学号、成绩,其中成绩需要精确到一位小数。是编写程序实现以下功能(提示,应该从上至下规划程序结构,划分各个子程序的功能和调用关系): 299 | - 可以录入学生成绩(十进制形式) 300 | - 可以按要求(如学号或成绩)进行排序显示 301 | - 可以统计平均成绩 302 | - 可以统计不及格、60 ~ 70、70 ~ 80、 80 ~ 90、 90 ~ 100 各分数段的人数 303 | 304 | ## 参与者列表 305 | 306 | **感谢以下成员对此习题集做出的分享和贡献!** 307 | * [Forec](https://github.com/Forec) 308 | * [non1996](https://github.com/non1996) 309 | * [Occupying](https://github.com/Occupying) 310 | * [YeWenting](https://github.com/YeWenting) 311 | * [seagullbird](https://github.com/seagullbird) 312 | * [dsryhh](https://github.com/DSRYhh) 313 | 314 | # License 315 | 316 | All codes in this repository are licensed under the terms you may find in the file named "LICENSE" in this directory. 317 | -------------------------------------------------------------------------------- /code/Forec/t1.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/Forec/t1.asm -------------------------------------------------------------------------------- /code/Forec/t10.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t10 19 | 20 | .model small 21 | .data 22 | helpinfo db 'Input: $' 23 | outputinfo db 0dh, 0ah, 'Output: $' 24 | errorinfo db 0dh, 0ah, 'Your input is not lowercase letter!$' 25 | 26 | .code 27 | start: 28 | mov ax, @data 29 | mov ds, ax 30 | 31 | mov dx, offset helpinfo 32 | mov ah, 9h 33 | int 21h 34 | 35 | mov ah, 1h 36 | int 21h 37 | cmp al, 0dh 38 | jz quit ;; 回车 39 | cmp al, 'a' 40 | jb quit ;; < 'a' 41 | cmp al, 'z' 42 | ja quit ;; > 'z' 43 | mov dx, offset outputinfo 44 | mov ah, 9h 45 | int 21h 46 | mov ah, 2h 47 | cmp al, 61h 48 | jz ia ;; 是 'a' 49 | cmp al, 7ah 50 | jz iz ;; 是 'z' 51 | ;; 不是 'a' 或 'z' 52 | dec al 53 | mov dl, al 54 | int 21h 55 | inc dl 56 | int 21h 57 | inc dl 58 | int 21h 59 | jmp quit 60 | ia: 61 | mov dl, 7ah 62 | int 21h 63 | mov dl, 61h 64 | int 21h 65 | inc dl 66 | int 21h 67 | jmp quit 68 | iz: 69 | mov dl, 79h 70 | int 21h 71 | inc dl 72 | int 21h 73 | mov dl, 61h 74 | int 21h 75 | jmp quit 76 | 77 | warning: 78 | mov dx, offset errorinfo 79 | mov ah, 9h 80 | int 21h 81 | quit: 82 | mov ah, 4ch 83 | int 21h 84 | end start -------------------------------------------------------------------------------- /code/Forec/t11.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t11 19 | 20 | .model small 21 | .code 22 | start: 23 | mov ax, 01234h ;; 假设 AX 中 16 位为 1234h 24 | mov bl, al 25 | mov dl, ah 26 | and al, 0fh ;; al 27 | and bl, 0f0h 28 | mov cl, 04h 29 | shr bl, cl ;; bl 30 | and dl, 0f0h 31 | shr dl, cl ;; dl 32 | mov cl, ah 33 | and cl, 0fh ;; cl 34 | mov ah, 00h ;; 此时 al, bl, cl, dl 为 04h, 03h, 02h, 01h 35 | mov ah, 4ch 36 | int 21h 37 | end start -------------------------------------------------------------------------------- /code/Forec/t12.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t12 19 | 20 | .model small 21 | .data 22 | output db 'ANS: $' 23 | matchinfo db 'MATCH$' 24 | nomatchinfo db 'NO MATCH$' 25 | warninginfo db 0dh, 0ah, 'You can input at most 100 chars!', 0dh, 0ah, '$' 26 | inputinfo db 'input str$' 27 | str1 db 100 dup(?) 28 | str2 db 100 dup(?) 29 | .code 30 | start: 31 | mov ax, @data 32 | mov ds, ax 33 | mov dx, offset inputinfo ;; 显示帮助信息 34 | mov ah, 9h 35 | int 21h 36 | mov dl, '1' 37 | mov ah, 2h 38 | int 21h 39 | mov dl, ':' 40 | int 21h 41 | ;; 输入str1 42 | mov si, 0h 43 | mov ah, 1h 44 | input1: 45 | int 21h 46 | mov str1[si], al 47 | inc si 48 | cmp al, 0dh 49 | jz pre2 50 | cmp si, 100 51 | jl input1 52 | mov dx, offset warninginfo ;; 超过100字符,提示警告 53 | mov ah, 9h 54 | int 21h 55 | 56 | pre2: 57 | mov dx, offset inputinfo ;; 显示帮助信息 58 | mov ah, 9h 59 | int 21h 60 | mov dl, '2' 61 | mov ah, 2h 62 | int 21h 63 | mov dl, ':' 64 | int 21h 65 | 66 | mov di, 0h 67 | mov ah, 1h 68 | input2: 69 | int 21h 70 | mov str2[di], al 71 | inc di 72 | cmp al, 0dh 73 | jz compare 74 | cmp di, 100 75 | jl input2 76 | mov dx, offset warninginfo ;; 超过100字符,提示警告 77 | mov ah, 9h 78 | int 21h 79 | compare: 80 | mov dx, offset output ;; 显示 "ANS: " 81 | mov ah, 9h 82 | int 21h 83 | cmp si, di 84 | jnz unmatch 85 | dec si 86 | cmpchar: 87 | cmp si, 0h 88 | jz match 89 | mov bh, str1[si] 90 | mov bl, str2[si] 91 | cmp bh, bl 92 | jnz unmatch 93 | dec si 94 | jmp cmpchar 95 | unmatch: 96 | mov dx, offset nomatchinfo 97 | jmp quit 98 | match: 99 | mov dx, offset matchinfo 100 | quit: 101 | int 21h 102 | 103 | mov ah, 4ch 104 | int 21h 105 | end start -------------------------------------------------------------------------------- /code/Forec/t13.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t13 19 | 20 | .model small 21 | .data 22 | inputinfo db 'Input: $' 23 | outputinfo db 0dh, 0ah, 'Output: $' 24 | .code 25 | start: 26 | mov ax, @data 27 | mov ds, ax 28 | mov dx, offset inputinfo 29 | mov ah, 9h 30 | int 21h 31 | mov ah, 01h 32 | int 21h 33 | mov cl, al 34 | sub cl, 030h 35 | mov dx, offset outputinfo 36 | mov ah, 9h 37 | int 21h 38 | mov ah, 02h 39 | mov dl, 'a' ;; 07h 用 a 代替 beep 观察输出 40 | beep: 41 | cmp cl, 00h 42 | jz quit 43 | dec cl 44 | int 21h 45 | jmp beep 46 | quit: 47 | mov ah, 4ch 48 | int 21h 49 | end start -------------------------------------------------------------------------------- /code/Forec/t14.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t14 19 | 20 | .model small 21 | .data 22 | positive db 'Positive numbers :$' 23 | negative db 0dh, 0ah, 'Negative numbers :$' 24 | M dw 1, 3, -2, 4, -9, -19, 32, 1, 0, 3, -4, 94, 1030, 32, -1, 13, -32, -12, 56, 7 25 | ;; 20 个数据, 7 个负数, 1个0, 12个正数 26 | .code 27 | start: 28 | mov ax, @data 29 | mov ds, ax 30 | 31 | mov si, 0h 32 | mov bx, 0h 33 | compare: 34 | cmp si, 40 35 | jz outputs 36 | mov ax, M[si] 37 | add si, 02h 38 | cmp ax, 0 39 | jz compare 40 | jl nega 41 | inc bl ;; bl 存正数个数 42 | jmp compare 43 | nega: 44 | inc bh ;; bh 为负数个数 45 | jmp compare 46 | 47 | outputs: 48 | mov ch, bh ;; ch 暂存负数个数 49 | mov bh, 00h 50 | mov cl, 0ah 51 | mov dx, offset positive 52 | mov ah, 09h 53 | int 21h ;; 输出帮助信息 54 | cmp bl, 00h 55 | jnz loopout1 56 | mov dl, '0' 57 | mov ah, 02h 58 | int 21h 59 | jmp prenega 60 | loopout1: 61 | mov ax, bx 62 | div cl 63 | mov bl, ah ;; 余数 64 | mov dl, al ;; 商 65 | cmp dl, 00h 66 | jz printmod1 67 | add dl, 30h 68 | mov ah, 02h 69 | int 21h 70 | jmp loopout1 71 | printmod1: 72 | mov ah, 02h 73 | mov dl, bl ;; 打印个位数 74 | add dl, 30h 75 | int 21h 76 | prenega: 77 | mov dx, offset negative 78 | mov ah, 09h 79 | int 21h 80 | 81 | mov bl, ch ;; 从 ch 取出负数个数 82 | mov bh, 00h 83 | cmp bl, 00h 84 | jnz loopout2 85 | mov dl, '0' 86 | mov ah, 02h 87 | int 21h 88 | jmp quit 89 | loopout2: 90 | mov ax, bx 91 | div cl 92 | mov bl, ah ;; 余数 93 | mov dl, al ;; 商 94 | cmp dl, 00h 95 | jz printmod2 96 | add dl, 30h 97 | mov ah, 02h 98 | int 21h 99 | jmp loopout2 100 | printmod2: 101 | mov ah, 02h 102 | mov dl, bl ;; 打印个位数 103 | add dl, 30h 104 | int 21h 105 | quit: 106 | mov ah, 4ch 107 | int 21h 108 | end start 109 | 110 | ;; 输出 111 | ;; Positive numbers :12 112 | ;; Negative numbers :7 -------------------------------------------------------------------------------- /code/Forec/t15.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t15 19 | 20 | .model small 21 | .data 22 | array dw 0100Dh dup(?) 23 | .code 24 | start: 25 | mov ax, @data 26 | mov ds, ax 27 | mov si, 02h 28 | mov ax, array[0] 29 | compare: 30 | cmp si, 0100Dh 31 | jz quit 32 | cmp ax, array[si] 33 | jng pass 34 | mov ax, array[si] 35 | pass: 36 | add si, 02h 37 | jmp compare 38 | quit: 39 | mov ah, 4ch 40 | int 21h 41 | end start -------------------------------------------------------------------------------- /code/Forec/t16.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t16 19 | 20 | .model small 21 | .data 22 | mes db 'The number of 11b in ax is : $' 23 | .code 24 | start: 25 | mov ax, @data 26 | mov ds, ax 27 | mov ax, 0111110111001101b ;; 4 个 11b, ax = 7dcdh 28 | mov bx, ax 29 | mov cl, 00h 30 | mov ch, 00h 31 | compare: 32 | cmp cl, 0010h 33 | jz print 34 | mov ax, bx 35 | shr ax, cl 36 | add cl, 02h 37 | test ax, 0001h 38 | jz compare 39 | test ax, 0002h 40 | jz compare 41 | inc ch 42 | jmp compare 43 | print: 44 | mov dx, offset mes 45 | mov ah, 09h 46 | int 21h 47 | mov dl, ch 48 | add dl, 30h 49 | mov ah, 02h 50 | int 21h 51 | quit: 52 | mov ah, 4ch 53 | int 21h 54 | end start 55 | 56 | ;; 输出 57 | ;; The number of l11b in ax is : 4 -------------------------------------------------------------------------------- /code/Forec/t17.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/11/18 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t17 19 | 20 | .model small 21 | .data 22 | store db 4 dup(?) 23 | errorinfo db 0dh, 0ah, 'Your input is not valid!$' 24 | inputinfo db 'Input : $' 25 | outputinfo db 0dh, 0ah, 'Output : $' 26 | .code 27 | start: 28 | mov ax, @data 29 | mov ds, ax 30 | mov dx, offset inputinfo 31 | mov ah, 09h 32 | int 21h 33 | mov si, 0h 34 | mov ah, 01h 35 | read: 36 | cmp si, 04h 37 | jge outputs ;; si >= 4 38 | int 21h 39 | 40 | cmp al, 30h ;; < '0' 41 | jl wrong 42 | cmp al, 66h ;; > 'f' 43 | jg wrong 44 | cmp al, 39h ;; <= '9' 45 | jle zero2nine 46 | cmp al, 41h ;; < 'A' 47 | jl wrong 48 | cmp al, 46h ;; <= 'F' 49 | jle upperCase 50 | cmp al, 61h ;; >= 'a' 51 | jge lowerCase 52 | jmp wrong 53 | zero2nine: 54 | sub al, 30h 55 | jmp finish 56 | upperCase: 57 | sub al, 37h 58 | jmp finish 59 | lowerCase: 60 | sub al, 57h 61 | finish: 62 | mov store[si], al 63 | inc si 64 | jmp read 65 | 66 | wrong: 67 | mov dx, offset errorinfo 68 | mov ah, 9h 69 | int 21h 70 | jmp quit 71 | 72 | outputs: 73 | mov ah, 02h 74 | mov dl, 'H' 75 | int 21h ;; 为用户输入补全 'H' 76 | mov ah, 09h 77 | mov dx, offset outputinfo 78 | int 21h 79 | mov ah, 02h 80 | mov si, 00h 81 | foreach: 82 | cmp si, 04h 83 | jge quit ;; si >= 4 84 | mov ch, store[si] 85 | mov cl, 04h 86 | shl ch, cl ;; 先左移 4 位 87 | mov cl, 00h 88 | print: 89 | cmp cl, 04h ;; 已左移 4 次,换下一个数 90 | jz breakpoint 91 | mov dl, 30h ;; 默认 0(30h) 92 | test ch, 80h 93 | jz pass1 ;; 高位为 0, 跳过输出 1 94 | mov dl, 31h 95 | pass1: 96 | int 21h 97 | shl ch, 1 98 | inc cl 99 | jmp print 100 | breakpoint: 101 | inc si 102 | test si, 01h 103 | jnz pass2 ;; 不输出空格 104 | mov dl, ' ' ;; 补全空格 105 | int 21h 106 | pass2: 107 | jmp foreach 108 | 109 | quit: 110 | mov ah, 4ch 111 | int 21h 112 | end start 113 | -------------------------------------------------------------------------------- /code/Forec/t18.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t18 19 | 20 | .model small 21 | .data 22 | eng db 1000 dup(0) 23 | tocmp db 'SUN$' 24 | inputinfo db 'Input:$' 25 | outputinfo db 'SUN:$' 26 | warninginfo db 0dh, 0ah, 'You can input at most 1000 chars!', 0dh, 0ah, '$' 27 | .code 28 | start: 29 | mov ax, @data 30 | mov ds, ax 31 | mov es, ax 32 | mov dx, offset inputinfo 33 | mov ah, 9h 34 | int 21h ;; 显示帮助信息 35 | 36 | mov ah, 1h 37 | mov si, 0h 38 | read: 39 | cmp si, 1000 40 | jge warning 41 | int 21h 42 | cmp al, 0dh 43 | jz filter ;; 用户输入回车 44 | mov eng[si], al 45 | inc si 46 | jmp read 47 | 48 | warning: 49 | mov dx, offset warninginfo 50 | mov ah, 9h 51 | int 21h 52 | 53 | filter: 54 | mov di, 0h 55 | foreach: 56 | cmp di, si 57 | jz work 58 | mov bl, eng[di] 59 | cmp bl, 61h ;; < 'a' 60 | jl pass1 61 | cmp bl, 7ah ;; > 'z' 62 | jg pass1 63 | and bl, 0dfh ;; 11011111 64 | mov eng[di], bl 65 | pass1: 66 | inc di 67 | jmp foreach 68 | 69 | work: 70 | mov ax, 0000h 71 | mov bx, si 72 | mov dx, 0000h 73 | curcmp: 74 | cmp dx, bx 75 | jz outputs 76 | mov si, offset eng ;; 当前待比较地址 77 | add si, dx 78 | mov di, offset tocmp ;; 'SUN' 地址 79 | mov cx, 0003h ;; 比较长度为3 80 | cld 81 | lp1: 82 | cmp cx, 0000h 83 | jnz stcmp ;; 尚未比较完成 84 | inc ax ;; 相等 85 | jmp lp2 86 | stcmp: 87 | cmpsb 88 | jnz lp2 ;; 不等,跳过 89 | dec cx ;; 待比较长度减1 90 | jmp lp1 91 | lp2: 92 | inc dx 93 | jmp curcmp 94 | 95 | outputs: 96 | mov bx, ax 97 | mov dx, offset outputinfo 98 | mov ah, 09h 99 | int 21h 100 | 101 | push bx 102 | call outputnumber 103 | jmp quit 104 | 105 | outputnumber proc near 106 | pop bp ;; bp <- ip 107 | pop ax 108 | push bp 109 | cmp ax, 0ah 110 | jl only1 111 | mov cl, 0ah 112 | div cl 113 | mov bl, ah ;; 余数 114 | mov dl, al ;; 商 115 | mov dh, 00h 116 | push bx 117 | push dx 118 | call outputnumber 119 | pop bx 120 | mov ah, 02h 121 | add bl, 30h 122 | mov dl, bl 123 | int 21h 124 | ret 125 | only1: 126 | mov dl, al 127 | add dl, 30h 128 | mov ah, 02h 129 | int 21h 130 | ret 131 | outputnumber endp 132 | 133 | quit: 134 | mov ah, 4ch 135 | int 21h 136 | end start 137 | -------------------------------------------------------------------------------- /code/Forec/t19.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/11/18 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t19 19 | 20 | .model small 21 | .data 22 | inputinfo db 'Input:$' 23 | outputinfo db 'Output:$' 24 | .stack 100h 25 | .code 26 | start: 27 | mov ax, @data 28 | mov ds, ax 29 | mov es, ax 30 | mov bx, 0h 31 | mov dx, offset inputinfo 32 | mov ah, 09h 33 | int 21h 34 | mov ah, 01h 35 | 36 | read: 37 | int 21h 38 | cmp al, '$' 39 | jz outputs ;; '$' 结束 40 | cmp al, 0dh 41 | jz outputs ;; 回车结束 42 | cmp al, 30h 43 | jl add1 ;; < '0' 44 | cmp al, 39h 45 | jle pass ;; '0' < al <= '9' 46 | add1: 47 | inc bx 48 | pass: 49 | jmp read 50 | 51 | outputs: 52 | mov dx, offset outputinfo 53 | mov ah, 09h 54 | int 21h 55 | 56 | push bx 57 | call outputnumber 58 | 59 | mov ah, 4ch 60 | int 21h 61 | 62 | outputnumber proc near 63 | pop bp ;; bp <- ip 64 | pop ax 65 | push bp 66 | cmp ax, 0ah 67 | jl only1 68 | mov cl, 0ah 69 | div cl 70 | mov bl, ah ;; 余数 71 | mov dl, al ;; 商 72 | mov dh, 00h 73 | push bx 74 | push dx 75 | call outputnumber 76 | pop bx 77 | mov ah, 02h 78 | add bl, 30h 79 | mov dl, bl 80 | int 21h 81 | ret 82 | only1: 83 | mov dl, al 84 | add dl, 30h 85 | mov ah, 02h 86 | int 21h 87 | ret 88 | outputnumber endp 89 | 90 | end start 91 | -------------------------------------------------------------------------------- /code/Forec/t2.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t2 19 | 20 | partial STRUC 21 | xname db 'default' 22 | xnumber db 0 23 | partial ends 24 | 25 | data segment 26 | fld1b db 'personal computer' 27 | fld2b db 32 28 | fld3b db 20h 29 | fld4b db 01011001b 30 | fld5b db '32654' 31 | fld6b db 10 dup(0) 32 | fld7b partial <'part1', 20>, <'part2', 50>, <'part3', 14> 33 | fld1w dw 0fff0h 34 | fld2w dw 01011001b 35 | fld3w equ offset fld7b 36 | fld4w dw 5, 6, 7, 8, 9 37 | fld5w dw 5 dup(0) 38 | fld6w equ ((offset fld1w) - (offset fld1b)) 39 | data ends 40 | 41 | code segment ;; code 段用于debug观察数据段 42 | assume cs:code, ds:data 43 | start: 44 | mov ax, data 45 | mov ds, ax 46 | lea ax, fld1b 47 | lea bx, fld5w 48 | let0: 49 | inc ax 50 | cmp ax, bx 51 | JL let0 52 | mov ah, 4ch 53 | int 21 54 | code ends 55 | end start 56 | -------------------------------------------------------------------------------- /code/Forec/t20(法1).asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t20(1) 19 | 20 | .model small 21 | .data 22 | mem dw 1, 0, 0, 0, 2, 0, 0, 3, 0, 4, 0, 5, 6, 1000h dup(?) 23 | ;; 13个确定的数用于检查, 重复1000h个随机数 24 | .code 25 | start: 26 | mov ax, @data 27 | mov ds, ax 28 | mov es, ax 29 | mov si, 0000h ;; 当前指针 30 | mov di, 0000h ;; 指向上一个不为 0 的后面的 0 的指针 31 | check: 32 | cmp si, 100dh 33 | jz quit 34 | cmp mem[si], 00h 35 | jz pass ;; 当前仍为0则跳过拷贝 36 | cmp si, di 37 | jz pass ;; di 和 si 相同则跳过拷贝 38 | mov cx, 100dh ;; 当前不为 0, 类似 xxx0000000x........ 39 | mov bx, si ;; di si 100dh 40 | sub cx, bx ;; xxxx........ 41 | mov bx, di ;; di,si 42 | add si, offset mem 43 | add di, offset mem 44 | cld 45 | cp: 46 | movsw 47 | dec cx 48 | jnz cp 49 | clear: 50 | cmp si, 100dh 51 | jz finish 52 | mov mem[si], 00h 53 | add si, 2h 54 | jmp clear 55 | finish: 56 | mov di, bx 57 | mov si, bx 58 | pass: 59 | add si, 2h 60 | cmp mem[di], 00h ;; 若当前 mem[di] 不为 0, 则更新 di 和 si 相同 61 | jz check 62 | mov di, si 63 | jmp check 64 | quit: 65 | mov ah, 4ch 66 | int 21h 67 | 68 | end start 69 | -------------------------------------------------------------------------------- /code/Forec/t20(法2).asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t20(2) 19 | 20 | .model small 21 | .data 22 | mem dw 1, 0, 0, 0, 2, 0, 0, 3, 0, 4, 0, 5, 6;;, 1000h dup(?) 23 | ;; 13个确定的数用于检查, 重复1000h个随机数 24 | temp dw 100dh dup(?) 25 | ;; 用 temp 缓存非零数 26 | .code 27 | start: 28 | mov ax, @data 29 | mov ds, ax 30 | mov es, ax 31 | mov si, offset mem 32 | mov di, offset temp 33 | mov bx, offset mem 34 | add bx, 201ch ;;100dh * 2 + 2 35 | cld 36 | check: 37 | cmp si, bx 38 | jz clear 39 | cmp word ptr [si], 0000h 40 | jz pass 41 | movsw 42 | pass: 43 | add si, 2h 44 | jmp check 45 | clear: 46 | mov cx, di 47 | mov di, offset mem 48 | sub cx, offset temp 49 | mov si, offset temp 50 | cld 51 | rep movsw 52 | sub di, offset mem 53 | mov cx, 201ch ;; 100dh * 2 + 2 54 | sub cx, di 55 | l: 56 | mov mem[di], 00h 57 | add di, 2h 58 | dec cx ;; 字,cx每次要减2 59 | loop l 60 | quit: 61 | mov ah, 4ch 62 | int 21h 63 | 64 | end start -------------------------------------------------------------------------------- /code/Forec/t21.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t21 19 | 20 | .model small 21 | .data 22 | string db 100 dup(?) 23 | .code 24 | start: 25 | mov ax, @data 26 | mov ds, ax 27 | mov si, 00h 28 | check: 29 | cmp si, 100 30 | jz quit 31 | cmp string[si], 30h 32 | jl pass ;; < '0' 33 | cmp string[si], 39h 34 | jg pass ;; > '9' 35 | or cl, 00010000b 36 | jmp quit 37 | pass: 38 | inc si 39 | jmp check 40 | quit: 41 | cmp si, 100 42 | jl final 43 | and cl, 11101111b 44 | final: 45 | mov ah, 4ch 46 | int 21h 47 | end start -------------------------------------------------------------------------------- /code/Forec/t22.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/25 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t22 19 | 20 | .model small 21 | .data 22 | table dw 100h dup(?) 23 | ;; 此题也可用栈处理,但所需空间增大 24 | .code 25 | start: 26 | mov ax, @data 27 | mov ds, ax 28 | mov es, ax 29 | mov si, 00h 30 | mov ax, 00h ;; ax 暂存出现次数最多的数 31 | mov bx, 00h ;; bx 暂存最多出现次数 32 | mov cx, 100h 33 | check: 34 | cmp si, 100h 35 | jz quit 36 | mov di, 00h ;; 下标 37 | mov cx, 00h ;; 次数 38 | mov dx, table[si] 39 | inside: 40 | cmp di, 100h 41 | jz quitloop ;; 比较完成 42 | cmp dx, table[di] 43 | jnz pass1 44 | inc cx 45 | pass1: 46 | add di, 2h 47 | jmp inside 48 | quitloop: 49 | cmp cx, bx ;; 比较当前次数与最大次数 50 | jle pass2 51 | mov bx, cx ;; 更新最大次数和数 52 | mov ax, dx 53 | pass2: 54 | add si, 2h 55 | jmp check 56 | 57 | quit: 58 | mov cx, bx 59 | mov ah, 4ch 60 | int 21h 61 | end start -------------------------------------------------------------------------------- /code/Forec/t23.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/25 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t23 19 | 20 | .model small 21 | 22 | .data 23 | M dw -4, 8, 9, 123, -9873, 23, 123, 43, 1, 0, 93, 13, 45, 15, 61, -88, ?, ? 24 | ;; 16个数,2个空位 25 | n equ $ - M - 4 26 | .code 27 | start: 28 | mov ax, @data 29 | mov ds, ax 30 | mov es, ax 31 | mov si, 00h 32 | mov ax, 00h 33 | mov bx, 00h 34 | check: 35 | cmp si, n 36 | jz quit 37 | mov cx, M[si] 38 | cmp cx, 0h 39 | jge positive 40 | neg cx 41 | positive: 42 | cmp ax, cx 43 | jge pass 44 | mov ax, cx 45 | mov bx, si 46 | pass: 47 | add si, 2h 48 | jmp check 49 | 50 | quit: 51 | mov M[si], ax 52 | add bx, offset M 53 | add si, 2h 54 | mov M[si], bx 55 | mov ah, 4ch 56 | int 21h 57 | end start -------------------------------------------------------------------------------- /code/Forec/t24.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/25 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t24 19 | 20 | .model small 21 | .data 22 | array dw 100h dup (?) 23 | 24 | .code 25 | start: 26 | mov ax, @data 27 | mov ds, ax 28 | mov es, ax 29 | mov ax, 00h 30 | mov bx, 00h 31 | mov cx, 100h 32 | mov dx, 00h 33 | mov si, 00h 34 | mov di, 00h 35 | calc: 36 | cmp si, 200h ;; dw * 2 37 | jz average 38 | add ax, array[si] 39 | adc dx, 00h 40 | add si, 02h 41 | jmp calc 42 | average: 43 | idiv cx ;; (DX:AX) div (SRC) = AX ... mod DX 44 | compare: 45 | cmp ax, array[di] 46 | jle pass 47 | inc bx 48 | pass: 49 | add di, 2h 50 | loop compare 51 | quit: 52 | mov ah, 4ch 53 | int 21h 54 | end start -------------------------------------------------------------------------------- /code/Forec/t25.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/25 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t25 19 | 20 | data segment 21 | mem db 4 dup(?) 22 | data ends 23 | 24 | code segment 25 | assume cs:code, ds:data 26 | start: 27 | mov ax, data 28 | mov ds, ax 29 | mov es, ax 30 | mov ax, 2A49h ;; (AX) = 2A49H 31 | mov si, 01h 32 | mov bl, al ;; 处理 ax 最后 4 位 33 | and bl, 0fh 34 | cmp bl, 0ah 35 | jl number1 ;; 0 ~ 9 36 | add bl, 07h ;; A ~ F 37 | number1: 38 | add bl, 30h 39 | mov mem[0], bl 40 | mov cl, 04h 41 | deal: 42 | cmp si, 04h 43 | jz quit 44 | shr ax, cl 45 | mov bl, al 46 | and bl, 0fh 47 | cmp bl, 0ah 48 | jl number2 49 | add bl, 07h 50 | number2: 51 | add bl, 30h 52 | mov mem[si], bl 53 | inc si 54 | jmp deal 55 | quit: 56 | mov ah, 4ch 57 | int 21h 58 | code ends 59 | end start -------------------------------------------------------------------------------- /code/Forec/t26.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/25 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t26 19 | 20 | data segment 21 | grade dw 0110h, 1000h, 100dh, 0001h, 0110h, 1001h, 0110h, 1002h, 002dh, 0010h, 0100h, 0200h, 0300h, 0400h, 0500h, 0600h, 0700h, 0800h, 0101h, 0202h, 0203h, 0104h, 0305h, 0506h, 0607h, 0207h, 080ah, 070dh, 0fffh, 0ffeh 22 | temp dw 30 dup(?) 23 | rank db 30 dup(1) 24 | outputinfo1 db 'Student $' 25 | outputinfo2 db ' score : $' 26 | outputinfo3 db ' rank: $' 27 | nextline db 0dh, 0ah, '$' 28 | data ends 29 | 30 | code segment 31 | assume cs:code, ds:data 32 | start: 33 | mov ax, data 34 | mov ds, ax 35 | mov es, ax 36 | 37 | mov si, offset grade 38 | mov di, offset temp 39 | mov cx, 1eh 40 | rep movsw ;; copy to temp 41 | 42 | mov si, 00h 43 | compare: 44 | cmp si, 3ch 45 | jz outputpart 46 | mov di, 00h 47 | mov bl, 01h 48 | mov ax, temp[si] 49 | nextcmp: 50 | cmp di, 3ch 51 | jz setrank 52 | cmp ax, temp[di] 53 | jae pass 54 | inc bl 55 | pass: 56 | add di, 2h 57 | jmp nextcmp 58 | setrank: 59 | shr si, 1 60 | mov rank[si], bl 61 | shl si, 1 62 | add si, 2h 63 | jmp compare 64 | 65 | ;; output part 66 | 67 | outputpart: 68 | mov si, 00h 69 | mov di, 00h 70 | 71 | outputs: 72 | cmp si, 3ch ;; 1eh * 2 = 3ch 73 | jge quit 74 | mov cl, 0ah 75 | mov ax, di ;; 输出 'Student xx score: 76 | div cl 77 | add ax, 3030h ;; to ascii 78 | mov bx, ax 79 | mov dx, offset outputinfo1 80 | mov ah, 9h 81 | int 21h 82 | mov ah, 2h 83 | mov dl, bl 84 | int 21h ;; 十位 85 | mov dl, bh ;; 个位 86 | int 21h 87 | mov dx, offset outputinfo2 88 | mov ah, 9h 89 | int 21h 90 | 91 | mov ah, 02h 92 | mov cl, 04h 93 | mov bx, temp[si] 94 | mov ch, 00h 95 | printnumber: 96 | cmp ch, 04h 97 | jz printleft 98 | mov dl, bh 99 | and dl, 0f0h 100 | shr dl, cl 101 | cmp dl, 09h 102 | jle number 103 | add dl, 07h 104 | number: 105 | add dl, 30h 106 | int 21h 107 | shl bx, cl 108 | inc ch 109 | jmp printnumber 110 | printleft: 111 | mov dx, offset outputinfo3 112 | mov ah, 9h 113 | int 21h ;; 输出 ' rank : ' 114 | mov bl, 0ah 115 | mov ah, 00h 116 | mov al, rank[di] 117 | div bl 118 | mov bx, ax 119 | mov ah, 02h 120 | mov dl, bl 121 | add dl, 30h 122 | int 21h 123 | mov dl, bh 124 | add dl, 30h 125 | int 21h 126 | mov ah, 9h 127 | mov dx, offset nextline 128 | int 21h 129 | add si, 02h 130 | inc di 131 | jmp outputs 132 | quit: 133 | mov ah, 4ch 134 | int 21h 135 | code ends 136 | end start -------------------------------------------------------------------------------- /code/Forec/t27.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/25 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t27 19 | 20 | .model small 21 | .data 22 | array_a db 15 dup(?) 23 | array_b db 20 dup(?) 24 | array_c db 15 dup(?) 25 | .stack 100h 26 | .code 27 | start: 28 | mov ax, @data 29 | mov ds, ax 30 | mov es, ax 31 | 32 | mov si, 00h 33 | mov cx, 00h 34 | outside: 35 | cmp si, 0fh 36 | jz quit 37 | mov al, array_a[si] 38 | mov di, 00h 39 | inside: 40 | cmp di, 14h 41 | jz quitinside 42 | mov bl, array_b[di] 43 | cmp al, bl 44 | jnz pass 45 | push si 46 | mov si, cx 47 | mov array_c[si], bl 48 | inc cx 49 | pop si 50 | pass: 51 | inc di 52 | jmp inside 53 | quitinside: 54 | inc si 55 | jmp outside 56 | quit: 57 | mov ah, 4ch 58 | int 21h 59 | end start -------------------------------------------------------------------------------- /code/Forec/t28.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/25 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t28 19 | 20 | .model small 21 | .data 22 | an dw ? 23 | bn dw ? 24 | cn dw ? 25 | dn dw ? 26 | .code 27 | start: 28 | mov ax, @data 29 | mov ds, ax 30 | mov es, ax 31 | 32 | mov ax, an 33 | mov bx, bn 34 | mov cx, cn 35 | cmp ax, 00h 36 | jz zero 37 | cmp bx, 00h 38 | jz zero 39 | cmp cx, 00h 40 | jz zero 41 | mov dx, 00h 42 | add dx, ax 43 | add dx, bx 44 | add dx, cx 45 | mov dn, dx 46 | jmp quit 47 | zero: 48 | mov dn, 00h 49 | quit: 50 | mov ah, 4ch 51 | int 21h 52 | end start -------------------------------------------------------------------------------- /code/Forec/t29.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/25 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t29 19 | 20 | .model small 21 | .data 22 | array dw 0100h, 0100h, 0010h 23 | outputinfo db 'Output: $' 24 | .code 25 | start: 26 | mov ax, @data 27 | mov ds, ax 28 | mov es, ax 29 | 30 | mov dx, offset outputinfo 31 | mov ah, 09h 32 | int 21h 33 | 34 | mov ax, array[0] 35 | mov bx, array[2] 36 | mov cx, array[4] 37 | 38 | cmp ax, bx 39 | jz asb ;; ax == bx 40 | cmp bx, cx ;; ax != bx 41 | jz asb ;; bx == cx 42 | cmp ax, cx ;; ax != bx, bx != cx 43 | jz asc 44 | mov ah, 02h 45 | mov dl, 30h 46 | int 21h 47 | jmp quit 48 | asb: 49 | cmp ax, cx 50 | jnz show1 ;; ax == bx, ax != cx 51 | mov ah, 02h 52 | mov dl, 32h 53 | int 21h 54 | jmp quit 55 | asc: 56 | cmp bx, cx ;; ax == cx 57 | jnz show1 ;; bx != cx 58 | mov ah, 02h 59 | mov dl, 32h 60 | int 21h 61 | jmp quit 62 | show1: 63 | mov ah, 02h 64 | mov dl, 31h 65 | int 21h 66 | quit: 67 | mov ah, 4ch 68 | int 21h 69 | end start -------------------------------------------------------------------------------- /code/Forec/t3.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t3 19 | 20 | data segment 21 | partno dw ? 22 | pname db 16 dup(?) 23 | count dd ? 24 | plenth equ $-partno 25 | data ends 26 | 27 | code segment 28 | assume cs:code, ds:data 29 | start: 30 | mov ax, data 31 | mov ds, ax 32 | mov ax, plenth 33 | mov ah, 4ch 34 | int 21h 35 | code ends 36 | end start 37 | 38 | ;; ans is 16h, total bytes used by data segment -------------------------------------------------------------------------------- /code/Forec/t30.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/25 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t30 19 | 20 | .model small 21 | .data 22 | inputinfo db 'Input: $' 23 | errorinfo db 0dh, 0ah, 'You can input at most 65535 chars!', 0dh, 0ah, '$' 24 | nextline db 0dh, 0ah, '$' 25 | letterinfo db 'Letter: $' 26 | numberinfo db 'Number: $' 27 | otherinfo db 'Other: $' 28 | .stack 100h 29 | .code 30 | start: 31 | mov ax, @data 32 | mov ds, ax 33 | mov es, ax 34 | 35 | mov dx, offset inputinfo 36 | mov ah, 9h 37 | int 21h 38 | 39 | mov si, 00h ;; total 40 | mov ah, 01h 41 | mov bx, 00h ;; letter 42 | mov cx, 00h ;; number 43 | read: 44 | cmp si, 0ffffh 45 | jz warning 46 | int 21h 47 | cmp al, 0dh 48 | jz outputs 49 | inc si 50 | cmp al, 30h 51 | jl read ;; other 52 | cmp al, 39h 53 | jle isnumber ;; '0' <= '9' 54 | cmp al, 41h 55 | jl read ;; '9' < 'a' 56 | cmp al, 5ah 57 | jle isletter ;; 'a' <= 'z' 58 | cmp al, 61h 59 | jl read ;; 'z' < 'A' 60 | cmp al, 7ah 61 | jle isletter ;; 'A' <= 'Z' 62 | jmp read ;; other 63 | isletter: 64 | inc bx 65 | jmp read 66 | isnumber: 67 | inc cx 68 | jmp read 69 | 70 | warning: 71 | mov dx, offset errorinfo 72 | mov ah, 09h 73 | int 21h 74 | 75 | outputs: 76 | sub si, bx 77 | sub si, cx 78 | push si 79 | push cx 80 | push bx 81 | 82 | mov dx, offset letterinfo 83 | mov ah, 09h 84 | int 21h 85 | call outputnumber ;; letter: xxx 86 | call nl 87 | 88 | mov dx, offset numberinfo 89 | mov ah, 09h 90 | int 21h 91 | call outputnumber ;; number: xxx 92 | call nl 93 | 94 | mov dx, offset otherinfo 95 | mov ah, 09h 96 | int 21h 97 | call outputnumber ;; other: xxx 98 | call nl 99 | 100 | quit: 101 | mov ah, 4ch 102 | int 21h 103 | 104 | outputnumber proc near 105 | pop bp ;; bp <- ip 106 | pop ax 107 | push bp 108 | cmp ax, 0ah 109 | jl only1 110 | mov cl, 0ah 111 | div cl 112 | mov bl, ah ;; 余数 113 | mov dl, al ;; 商 114 | mov dh, 00h 115 | push bx 116 | push dx 117 | call outputnumber 118 | pop bx 119 | mov ah, 02h 120 | add bl, 30h 121 | mov dl, bl 122 | int 21h 123 | ret 124 | only1: 125 | mov dl, al 126 | add dl, 30h 127 | mov ah, 02h 128 | int 21h 129 | ret 130 | outputnumber endp 131 | 132 | nl proc near 133 | mov dx, offset nextline 134 | mov ah, 09h 135 | int 21h 136 | ret 137 | nl endp 138 | end start -------------------------------------------------------------------------------- /code/Forec/t31.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/25 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t31 19 | 20 | data segment 21 | A dw 2 22 | B dw 3 23 | data ends 24 | 25 | code segment 26 | assume cs:code, ds:data 27 | start: 28 | mov ax, data 29 | mov ds, ax 30 | mov ax, A 31 | mov bx, B 32 | test ax, 0001h 33 | jz a_even ;; A is even 34 | test bx, 0001h 35 | jz quit ;; A is odd and B is even 36 | inc ax 37 | inc bx 38 | mov A, ax 39 | mov B, bx 40 | jmp quit 41 | a_even: 42 | test bx, 0001h 43 | jz quit ;; A is even and B is even 44 | xchg ax, bx 45 | mov A, ax 46 | mov B, bx 47 | quit: 48 | mov ah, 4ch 49 | int 21h 50 | code ends 51 | end start -------------------------------------------------------------------------------- /code/Forec/t32.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/25 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t32 19 | 20 | data segment 21 | program dd 5 dup(?) 22 | inputinfo db 'Input: $' 23 | errorinfo db 0dh, 0ah,'Input can only between 1 and 5!', 0dh, 0ah, '$' 24 | outputinfo db 'Start executing program $' 25 | nextline db 0dh, 0ah, '$' 26 | data ends 27 | 28 | code segment 29 | assume cs:code, ds:data 30 | start: 31 | mov ax, data 32 | mov ds, ax 33 | 34 | read: 35 | mov ah, 09h 36 | mov dx, offset inputinfo 37 | int 21h 38 | mov ah, 01h 39 | int 21h 40 | cmp al, 30h ;; '0' 41 | jl warning 42 | cmp al, 39h ;; '9' 43 | jg warning 44 | jmp execute 45 | warning: 46 | mov ah, 9h 47 | mov dx, offset errorinfo 48 | int 21h 49 | jmp read 50 | execute: 51 | ;; execute 52 | mov bl, al 53 | mov bh, 00h 54 | sub bx, 30h 55 | ;; call dword ptr program[bx] 56 | 57 | mov ah, 09h 58 | mov dx, offset nextline 59 | int 21h 60 | mov dx, offset outputinfo 61 | int 21h 62 | mov ah, 02h 63 | mov dl, al 64 | int 21h 65 | mov ah, 09h 66 | mov dx, offset nextline 67 | int 21h 68 | 69 | mov ah, 4ch 70 | int 21h 71 | code ends 72 | end start -------------------------------------------------------------------------------- /code/Forec/t34.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/25 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t34 19 | data segment 20 | skip db 0dh, 0ah, '$' 21 | data ends 22 | code segment 23 | assume cs:code, ds:data 24 | start: 25 | mov ax, data 26 | mov ds, ax 27 | mov ax, 04h ;; set ax 28 | 29 | mov cx, ax 30 | mov ah, 09h 31 | mov dx, offset skip 32 | loopp: 33 | int 21h 34 | loop loopp 35 | 36 | mov ah, 4ch 37 | int 21h 38 | code ends 39 | end start -------------------------------------------------------------------------------- /code/Forec/t35.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/25 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t35 19 | data segment 20 | score dw 76, 69, 84, 90, 73, 88, 99, 63, 100, 80 21 | s6 dw 0h ;; 2 22 | s7 dw 0h ;; 2 23 | s8 dw 0h ;; 3 24 | s9 dw 0h ;; 2 25 | s10 dw 0h ;; 1 26 | data ends 27 | code segment 28 | assume cs:code, ds:data 29 | start: 30 | mov ax, data 31 | mov ds, ax 32 | 33 | mov cx, 0ah 34 | mov si, 00h 35 | loopp: 36 | mov ax, score[si] 37 | cmp ax, 60 38 | jl pass 39 | cmp ax, 70 40 | jl six_seven ;; 60 < x < 69 41 | cmp ax, 80 42 | jl seven_eight ;; 70 < x < 79 43 | cmp ax, 90 44 | jl eight_nine ;; 80 < x < 89 45 | cmp ax, 100 46 | jl nine_100 ;; 90 < x < 99 47 | jg pass ;; > 100 48 | mov bx, s10 ;; 100 49 | inc bx 50 | mov s10, bx 51 | jmp pass 52 | six_seven: 53 | mov bx, s6 54 | inc bx 55 | mov s6, bx 56 | jmp pass 57 | seven_eight: 58 | mov bx, s7 59 | inc bx 60 | mov s7, bx 61 | jmp pass 62 | eight_nine: 63 | mov bx, s8 64 | inc bx 65 | mov s8, bx 66 | jmp pass 67 | nine_100: 68 | mov bx, s9 69 | inc bx 70 | mov s9, bx 71 | pass: 72 | add si, 02h 73 | loop loopp 74 | 75 | mov ah, 4ch 76 | int 21h 77 | code ends 78 | end start -------------------------------------------------------------------------------- /code/Forec/t36.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/25 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t36 19 | data segment 20 | table db 0efffh dup(?) 21 | nn dw ? 22 | char db ? 23 | time dw ? 24 | stringinfo db 'Input string: $' 25 | inputinfo db 'Input char to search: $' 26 | warninginfo db 0dh, 0ah, 'You can input at most 61439 chars!', 0dh, 0ah, '$' 27 | skip db 0dh, 0ah, '$' 28 | outputinfo db ' appeared $' 29 | outputpart2 db ' times in string.', 0dh, 0ah, '$' 30 | data ends 31 | stack segment para stack 'stack' 32 | db 100h dup(?) 33 | stack ends 34 | code segment 35 | assume cs:code, ds:data 36 | start: 37 | mov ax, data 38 | mov ds, ax 39 | mov es, ax 40 | 41 | mov ah, 09h 42 | mov dx, offset stringinfo 43 | int 21h 44 | 45 | mov si, 00h 46 | mov ah, 01h 47 | read: 48 | cmp si, 0efffh 49 | jz warning 50 | int 21h 51 | cmp al, 0dh 52 | jz run 53 | mov table[si], al 54 | inc si 55 | jmp read 56 | 57 | warning: 58 | mov ah, 09h 59 | mov dx, offset warninginfo 60 | int 21h 61 | 62 | run: 63 | mov nn, si 64 | find: 65 | mov ah, 09h 66 | mov dx, offset inputinfo 67 | int 21h 68 | mov ah, 01h 69 | int 21h 70 | cmp al, 0dh 71 | jz quit ;; 回车退出 72 | mov char, al 73 | 74 | call search 75 | 76 | mov ah, 09h 77 | mov dx, offset skip 78 | int 21h 79 | 80 | mov ah, 02h ;; 显示字符 81 | mov dl, char 82 | int 21h 83 | 84 | mov ah, 09h 85 | mov dx, offset outputinfo ;; 显示 appear 86 | int 21h 87 | 88 | mov ax, time 89 | push ax 90 | 91 | call outputnumber ;; 显示次数 92 | 93 | mov ah, 09h 94 | mov dx, offset outputpart2 95 | int 21h 96 | jmp find 97 | 98 | quit: 99 | mov ah, 4ch 100 | int 21h 101 | 102 | search proc near 103 | push ax 104 | push bx 105 | push cx 106 | push si 107 | 108 | mov si, 00h 109 | mov bx, 00h 110 | mov cx, nn 111 | mov al, char 112 | loopp: 113 | cmp al, table[si] 114 | jnz pass 115 | inc bx 116 | pass: 117 | inc si 118 | loop loopp 119 | 120 | mov time, bx 121 | pop si 122 | pop cx 123 | pop bx 124 | pop ax 125 | ret 126 | search endp 127 | 128 | outputnumber proc near 129 | pop bp ;; bp <- ip 130 | pop ax 131 | push bp 132 | cmp ax, 0ah 133 | jl only1 134 | mov cl, 0ah 135 | div cl 136 | mov bl, ah ;; 余数 137 | mov dl, al ;; 商 138 | mov dh, 00h 139 | push bx 140 | push dx 141 | call outputnumber 142 | pop bx 143 | mov ah, 02h 144 | add bl, 30h 145 | mov dl, bl 146 | int 21h 147 | ret 148 | only1: 149 | mov dl, al 150 | add dl, 30h 151 | mov ah, 02h 152 | int 21h 153 | ret 154 | outputnumber endp 155 | 156 | code ends 157 | end start -------------------------------------------------------------------------------- /code/Forec/t37.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/26 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t37 19 | data segment 20 | inputnameinfo db 'INPUT NAME: $' 21 | inputtelinfo db 'INPUT A TELEPHONE NUMBER: $' 22 | errorinfo db 0dh, 0ah, 'Input can only between 0-9 or */#!$' 23 | warninginfo db 0dh, 0ah, 'Name cannot longer than 16 !', 0dh, 0ah, '$' 24 | outputinfo db 0dh, 0ah, 'NAME TEL', 0dh, 0ah, '$' 25 | inbuf db 32 dup(?) ;; 16 name + 8 tel + 8 space 26 | totallen dw ? 27 | data ends 28 | stack segment para stack 'stack' 29 | db 100h dup(?) 30 | stack ends 31 | code segment 32 | assume cs:code, ds:data 33 | start: 34 | mov ax, data 35 | mov ds, ax 36 | mov es, ax 37 | 38 | call telist 39 | 40 | quit_pro: 41 | mov ah, 4ch 42 | int 21h 43 | 44 | telist proc near 45 | mov ah, 09h 46 | mov dx, offset inputnameinfo 47 | int 21h 48 | call input_name 49 | mov ah, 09h 50 | mov dx, offset inputtelinfo 51 | int 21h 52 | call inphone 53 | call printline 54 | ret 55 | telist endp 56 | 57 | input_name proc near 58 | mov si, 00h 59 | mov ah, 01h 60 | readname: 61 | cmp si, 10h ;; 16 62 | jz warning_name 63 | int 21h 64 | cmp al, 0dh ;; 回车 65 | jz quit_name 66 | mov inbuf[si], al 67 | inc si 68 | jmp readname 69 | warning_name: 70 | mov ah, 09h 71 | mov dx, offset warninginfo 72 | int 21h 73 | quit_name: 74 | mov totallen, si 75 | ret 76 | input_name endp 77 | 78 | inphone proc near 79 | mov si, totallen 80 | mov cx, 13h ;; 19 (16 name + 3space) 81 | sub cx, si 82 | fillspace: 83 | mov inbuf[si], ' ' 84 | inc si 85 | loop fillspace 86 | 87 | mov cx, 08h 88 | mov ah, 01h 89 | read_phone: 90 | int 21h 91 | cmp al, 39h ;; '9' '#':23h, '*':2ah 92 | jg errorinput 93 | cmp al, 23h 94 | jz load ;; is '#' 95 | cmp al, 2ah 96 | jz load ;; is '*' 97 | cmp al, 30h 98 | jl errorinput 99 | load: 100 | mov inbuf[si], al 101 | inc si 102 | loop read_phone 103 | mov totallen, si 104 | ret 105 | errorinput: 106 | mov ah, 09h 107 | mov dx, offset errorinfo 108 | int 21h 109 | jmp quit_pro 110 | inphone endp 111 | 112 | printline proc near 113 | mov ah, 09h 114 | mov dx, offset outputinfo 115 | int 21h 116 | mov si, totallen 117 | mov inbuf[si], '$' 118 | mov ah, 09h 119 | mov dx, offset inbuf 120 | int 21h 121 | ret 122 | printline endp 123 | 124 | code ends 125 | end start -------------------------------------------------------------------------------- /code/Forec/t38.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/26 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t38 19 | data segment 20 | val1 dw 1234h 21 | bininfo db 'BIN: $' 22 | octinfo db 'OCT: $' 23 | skip db 0dh, 0ah, '$' 24 | data ends 25 | stack segment para stack 'stack' 26 | db 100h dup(?) 27 | stack ends 28 | code segment 29 | assume cs:code, ds:data 30 | start: 31 | mov ax, data 32 | mov ds, ax 33 | mov es, ax 34 | call bando 35 | 36 | quit_pro: 37 | mov ah, 4ch 38 | int 21h 39 | 40 | bando proc near 41 | push val1 42 | call pairs 43 | ret 44 | bando endp 45 | 46 | pairs proc near 47 | pop bx 48 | pop ax 49 | push bx 50 | call outbin 51 | call outoct 52 | ret 53 | pairs endp 54 | 55 | outbin proc near 56 | push ax 57 | push bx 58 | push cx 59 | push dx 60 | mov bx, ax 61 | mov ah, 09h 62 | mov dx, offset bininfo 63 | int 21h 64 | mov cx, 10h 65 | mov ah, 02h 66 | loopp1: 67 | mov dl, bh 68 | and dl, 10000000b 69 | push cx 70 | mov cl, 07h 71 | shr dl, cl 72 | pop cx 73 | add dl, 30h 74 | int 21h 75 | shl bx, 1 76 | loop loopp1 77 | mov ah, 02h 78 | mov dl, 'B' 79 | int 21h ;; 输出 B 80 | call nextline 81 | pop dx 82 | pop cx 83 | pop bx 84 | pop ax 85 | ret 86 | outbin endp 87 | 88 | outoct proc near 89 | push ax 90 | push bx 91 | push cx 92 | push dx 93 | mov bx, ax 94 | mov dx, offset octinfo 95 | mov ah, 09h 96 | int 21h 97 | mov ah, 02h 98 | mov dl, bh 99 | and dl, 10000000b 100 | mov cl, 07h 101 | shr dl, cl 102 | add dl, 30h 103 | int 21h ;; 输出第一位 104 | shl bx, 1 105 | mov cx, 05h 106 | loopp2: 107 | mov dl, bh 108 | and dl, 11100000b 109 | push cx 110 | mov cl, 05h 111 | shr dl, cl ;; 八进制右移5位 112 | mov cl, 03h 113 | shl bx, cl ;; 原数左移3位 114 | pop cx 115 | add dl, 30h 116 | int 21h 117 | loop loopp2 118 | mov ah, 02h 119 | mov dl, 'O' 120 | int 21h ;; 输出 O 121 | call nextline 122 | pop dx 123 | pop cx 124 | pop bx 125 | pop ax 126 | ret 127 | outoct endp 128 | 129 | nextline proc near 130 | push ax 131 | push dx 132 | mov ah, 09h 133 | mov dx, offset skip 134 | int 21h 135 | pop dx 136 | pop ax 137 | ret 138 | nextline endp 139 | 140 | code ends 141 | end start -------------------------------------------------------------------------------- /code/Forec/t4.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t4 19 | 20 | data segment 21 | buff db 1, 2, 3, '123' 22 | ebuff db 0 23 | l equ ebuff-buff 24 | data ends 25 | 26 | code segment 27 | assume cs:code, ds:data 28 | start: 29 | mov ax, data 30 | mov ds, ax 31 | mov ax, l 32 | mov ah, 4ch 33 | int 21h 34 | code ends 35 | end start 36 | 37 | ;; ans is 0006h -------------------------------------------------------------------------------- /code/Forec/t40.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/11/2 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t40 19 | 20 | data segment 21 | X dw 0505h 22 | Y dw 0a0ah 23 | SUM dw ? 24 | data ends 25 | 26 | code segment 27 | assume cs:code, ds:data 28 | start: 29 | mov ax, data 30 | mov ds, ax 31 | finsum macro x, y 32 | push ax 33 | push bx 34 | mov ax, x 35 | mov bx, y 36 | if ax gt bx 37 | shl bx, 1 38 | else 39 | shl ax, 1 40 | endif 41 | add ax, bx 42 | mov sum, ax 43 | pop bx 44 | pop ax 45 | endm 46 | 47 | finsum X, Y 48 | 49 | mov ah, 4ch 50 | int 21h 51 | code ends 52 | end start -------------------------------------------------------------------------------- /code/Forec/t41.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/11/23 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t41 19 | 20 | data segment 21 | h dw ? 22 | key dw ? 23 | k dw ? 24 | i dw ? 25 | s dw ? 26 | datas db 100 dup(?) 27 | data ends 28 | 29 | code segment 30 | assume cs:code, ds:data 31 | start: 32 | mov ax, ds 33 | mov ds, ax 34 | mov es, ax 35 | 36 | ;; (1) 37 | mov cl, 8 38 | mov ax, key 39 | and ax, 0ff00h 40 | shr ax, cl 41 | mov h, ax 42 | 43 | ;; (2) 44 | mov ax, k 45 | add ax, '1' 46 | sub ax, 0abcdh 47 | mov bx, 38h ;; 56 48 | mov dx, 0h 49 | idiv bx 50 | mov k, ax 51 | 52 | ;; (3) 53 | mov cx, 64h 54 | mov si, 0h ;; i 55 | mov bx, 0h ;; s 56 | mov dh, 2h 57 | loop1: 58 | mov al, datas[si] 59 | imul dh 60 | add bx, ax 61 | inc si 62 | loop loop1 63 | mov s, bx 64 | mov i, 100 65 | 66 | ;; (4) 67 | mov bx, 0h ;; s 68 | mov cx, 64h ;; i 69 | mov dh, 2h 70 | loop2: 71 | mov al, cl 72 | mul dh 73 | add bx, ax 74 | loop loop2 75 | mov s, bx 76 | mov i, 0 77 | 78 | quit: 79 | mov ah, 4ch 80 | int 21h 81 | code ends 82 | end start -------------------------------------------------------------------------------- /code/Forec/t42.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/11/23 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t42 19 | 20 | data segment 21 | a dw ? 22 | b dw ? 23 | c dw ? 24 | data ends 25 | 26 | code segment 27 | assume cs:code, ds:data 28 | start: 29 | mov ax, data 30 | mov ds, ax 31 | mov es, ax 32 | 33 | cmp a, 1h 34 | jl yes ;; a < 1 35 | mov ax, b ;; a >= 1 36 | mov bx, 4h 37 | cwd 38 | idiv bx 39 | cmp ah, 0ah ;; b/4 > 10 ? 40 | jle no ;; b/4 < = 10 && a >= 1 41 | mov bx, 8h 42 | mov dx, 0h 43 | mov ax, c 44 | idiv bx 45 | cmp dx, 5 46 | jz yes ;; b/4 > 10 && c % 8 == 5 47 | jmp no ;; b/4 > 10 && c % 8 != 5 48 | 49 | yes: 50 | mov bx, b ;; b 51 | mov ax, 20 ;; a 52 | add ax, bx 53 | inc bx 54 | mov a, ax 55 | mov b, bx 56 | mov cl, 2h 57 | mov ax, c ;; c 58 | shl ax, cl 59 | mov c, ax 60 | jmp quit 61 | no: 62 | mov ax, 21 ;; a 63 | mov cx, c ;; c 64 | inc cx 65 | sub ax, cx 66 | mov c, cx 67 | mov a, ax 68 | mov bx, b 69 | dec bx 70 | mov b, bx 71 | 72 | quit: 73 | mov ah, 4ch 74 | int 21h 75 | code ends 76 | end start -------------------------------------------------------------------------------- /code/Forec/t43.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/11/23 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t43 19 | 20 | .model small 21 | .data 22 | a dw ? 23 | b dw ? 24 | c dw ? 25 | 26 | .stack 100h 27 | 28 | .code 29 | start: 30 | mov ax, @data 31 | mov ds, ax 32 | mov es, ax 33 | 34 | push a 35 | push b 36 | push c 37 | call calc 38 | 39 | mov ah, 4ch 40 | int 21h 41 | 42 | calc proc near 43 | push bp 44 | mov bp, sp 45 | push ax 46 | push bx 47 | push cx 48 | push dx 49 | mov cx, [bp+4] ;; c 50 | mov bx, [bp+6] ;; b 51 | mov ax, [bp+8] ;; a 52 | mov dx, ax 53 | add dx, bx ;; a + b 54 | cmp dx, cx 55 | jle fail ;; a + b <= c 56 | mov dx, ax 57 | add dx, cx 58 | cmp dx, bx 59 | jle fail ;; a + c <= b 60 | mov dx, bx 61 | add dx, cx 62 | cmp dx, ax 63 | jle fail ;; b + c <= a 64 | mov ax, 0h 65 | sub ax, 1h ;; 0 - 1, cf = 1 66 | jmp quitproc 67 | fail: 68 | sub ax, 0h ;; set cf = 0 69 | quitproc: 70 | pop dx 71 | pop cx 72 | pop bx 73 | pop ax 74 | pop bp 75 | ret 6;; ret 6, 3 parameters, but the order is not normal in debug 76 | calc endp 77 | end start -------------------------------------------------------------------------------- /code/Forec/t44.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/11/23 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t44 19 | 20 | .model small 21 | .data 22 | BUFFER dw 09h, 08h, 07h, 00h, 06h, 04h, 04h, 04h, 03h, 03h 23 | dw 02h, 09h, 08h, 07h, 06h, 05h, 04h, 03h, 02h, 01h 24 | BUFMAX equ 20 25 | TEMP1 dw 0 ;; end address of array 26 | TEMP2 dw 0 ;; first address of array 27 | .stack 100h 28 | .code 29 | start: 30 | mov ax, @data 31 | mov ds, ax 32 | mov es, ax 33 | 34 | mov ax, offset BUFFER 35 | mov bx, BUFMAX 36 | push ax 37 | push bx 38 | call far ptr sort 39 | 40 | mov ah, 4ch 41 | int 21h 42 | 43 | sort proc far 44 | ;; 2 parameters, the first is the address of data to be 45 | ;; sort, the second is the number of words in the array 46 | push bp 47 | mov bp, sp 48 | push si 49 | push dx 50 | push cx 51 | push bx 52 | push ax 53 | 54 | mov ax, [bp+6] ;; length 55 | mov bl, 2h 56 | mul bl 57 | mov cx, [bp+8] ;; address of the first element of array 58 | add ax, cx ;; word is 2 bytes, now ax is the end of array 59 | mov TEMP1, ax 60 | 61 | mov TEMP2, cx 62 | mov si, TEMP2 ;; i 63 | 64 | loop1: 65 | cmp si, TEMP1 66 | jge quitLoop1 67 | mov bx, TEMP2 ;; j 68 | mov dx, TEMP1 69 | sub dx, si ;; arr.length - 1 - i 70 | add dx, offset BUFFER 71 | 72 | loop2: 73 | cmp bx, dx 74 | jge quitLoop2 75 | mov ax, [bx] 76 | mov cx, [bx+2] 77 | cmp ax, cx 78 | jle continueLoop2 79 | mov [bx], cx 80 | mov [bx+2], ax 81 | continueLoop2: 82 | add bx, 2h 83 | jmp loop2 84 | quitLoop2: 85 | 86 | add si, 2h 87 | jmp loop1 88 | 89 | ;; bubble sort 90 | ;; for i = 0; i < arr.length - 1; i++ 91 | ;; for j = 0; j < arr.length - 1 - i; j++ 92 | ;; if arr[j] > arr[j+1] 93 | ;; swap arr, j, j+1 94 | quitLoop1: 95 | pop ax 96 | pop bx 97 | pop cx 98 | pop dx 99 | pop si 100 | pop bp 101 | ret 4 ;; 2 parameters 102 | sort endp 103 | end start -------------------------------------------------------------------------------- /code/Forec/t45.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/11/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t45 19 | 20 | code segment 21 | assume cs:code 22 | start: 23 | mov cx, 0aaaah ;; 10101010 10101010 -> 11001100 11001100 24 | 25 | mov ax, cx 26 | mov bx, cx 27 | mov cx, 8h 28 | 29 | loop1: 30 | shr ah, 01h 31 | jc hzero 32 | or bx, 0001h 33 | jmp checkL 34 | hzero: 35 | and bx, 0fffeh 36 | 37 | checkL: 38 | shl bx, 01h 39 | shr al, 01h 40 | jc lzero 41 | or bx, 01h 42 | jmp continueLoop 43 | lzero: 44 | and bx, 0fffeh 45 | continueLoop: 46 | cmp cx, 01h 47 | jz quit 48 | shl bx, 01h 49 | loop loop1 50 | quit: 51 | mov cx, bx 52 | 53 | mov ah, 4ch 54 | int 21h 55 | code ends 56 | end start -------------------------------------------------------------------------------- /code/Forec/t46.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/11/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t46 19 | 20 | data segment 21 | datas dw ? 22 | data ends 23 | 24 | code segment 25 | assume cs:code, ds:data 26 | start: 27 | mov ax, data 28 | mov ds, ax 29 | mov ax, 1000h 30 | mov es, ax 31 | mov dx, 0h ;; sum 32 | mov bp, 0h 33 | mov cx, 1024 34 | loop1: 35 | mov ax, es:[bp] 36 | add dx, ax 37 | add bp, 2h 38 | loop loop1 39 | mov datas, dx 40 | 41 | mov ah, 4ch 42 | int 21h 43 | code ends 44 | end start 45 | -------------------------------------------------------------------------------- /code/Forec/t47.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/11/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t47 19 | 20 | .model small 21 | .data 22 | product dw 45 dup (?) 23 | 24 | .code 25 | start: 26 | mov ax, @data 27 | mov ds, ax 28 | 29 | ;; for i = 1; i <= 9; i++ 30 | ;; for j = 1; j <= i; j++ 31 | ;; product[index] <- i * j 32 | 33 | mov si, offset product ;; index 34 | mov ax, 01h ;; i 35 | 36 | loop1: 37 | cmp al, 0ah 38 | jz quit 39 | mov bl, 01h ;; j 40 | loop2: 41 | cmp bl, al 42 | jg quitLoop2 43 | mov cx, ax 44 | mul bl 45 | mov [si], ax 46 | mov ax, cx 47 | inc bl 48 | add si, 02h 49 | jmp loop2 50 | quitLoop2: 51 | inc al 52 | jmp loop1 53 | quit: 54 | mov ah, 4ch 55 | int 21h 56 | end start -------------------------------------------------------------------------------- /code/Forec/t5.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t5 19 | 20 | .model small 21 | .data 22 | lname db 30 dup(?) 23 | address db 30 dup(?) 24 | city db 15 dup(?) 25 | code_list db 1, 7, 8, 3, 2 26 | code_length equ $ - code_list ;; (3) 27 | .stack 100h 28 | .code 29 | start: 30 | mov ax, @data 31 | mov ds, ax 32 | mov ax, offset lname ;; (1) 33 | mov si, word ptr code_list ;; (2) 34 | mov bx, code_length 35 | mov ah, 4ch 36 | int 21h 37 | end start -------------------------------------------------------------------------------- /code/Forec/t50.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/11/25 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t50 19 | 20 | .model small 21 | .data 22 | string db " hello world 1234 $" 23 | slength equ $-string 24 | 25 | .code 26 | start: 27 | mov ax, @data 28 | mov ds, ax 29 | mov si, offset string 30 | mov bx, offset string 31 | mov cx, slength 32 | loop1: 33 | mov al, [si] 34 | cmp al, 20h 35 | jnz cmpNum 36 | jmp pass 37 | cmpNum: 38 | cmp al, 30h 39 | jl next 40 | cmp al, 39h 41 | jg next 42 | jmp pass 43 | next: 44 | mov [bx], al 45 | inc bx 46 | pass: 47 | inc si 48 | loop loop1 49 | mov al, 24h 50 | mov [bx], al 51 | 52 | mov dx, offset string 53 | mov ah, 09h 54 | int 21h 55 | 56 | mov ah, 4ch 57 | int 21h 58 | end start -------------------------------------------------------------------------------- /code/Forec/t6.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t6 19 | 20 | data_seg segment 21 | five db 5 22 | data_list dw -1, 0, 2, 5, 4, 5 dup(?) 23 | max dw ? 24 | min dw ? 25 | data_seg ends 26 | 27 | code segment 28 | assume cs:code, ds:data_seg 29 | start: 30 | mov ax, data_seg 31 | mov ds, ax 32 | mov cx, 5h 33 | mov si, 0h 34 | mov ax, data_list[si] 35 | mov bx, data_list[si] 36 | let0: 37 | dec cx 38 | cmp cx, 0h 39 | jz quit 40 | add si, 2h 41 | cmp ax, data_list[si] 42 | jle let1 43 | mov ax, data_list[si] 44 | let1: 45 | cmp bx, data_list[si] 46 | jge quit 47 | mov bx, data_list[si] 48 | jmp let0 49 | quit: 50 | mov max, ax 51 | mov min, bx 52 | mov ah, 4ch 53 | int 21h 54 | code ends 55 | end start -------------------------------------------------------------------------------- /code/Forec/t7.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t7 19 | 20 | data segment at 0e000h 21 | array_b label byte ;; 定义字节类型 22 | array_w dw 50 dup(?) ;; 100字节数组,字类型 23 | data ends 24 | 25 | stack segment para stack 'stack' 26 | dw 100h dup (?) 27 | top label word 28 | stack ends 29 | 30 | code segment 31 | assume cs:code, ds:data, ss:stack 32 | org 1000h ;; 从 1000h 开始主程序 33 | start: 34 | mov ax, stack 35 | mov ss, ax ;; 为堆栈寄存器赋值 36 | mov sp, offset top ;; 为 sp 赋值 37 | mov ax, data 38 | mov ds, ax 39 | ;; your code here 40 | mov ah, 4ch 41 | int 21h 42 | code ends 43 | end start 44 | -------------------------------------------------------------------------------- /code/Forec/t75.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/11/2 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t75 19 | 20 | .model small 21 | .data 22 | buff dw 200 dup (?) 23 | n1 dw 0 24 | n2 dw 0 25 | n3 dw 0 26 | .code 27 | start: 28 | mov ax, @data 29 | mov ds, ax 30 | mov si, 00h 31 | mov bx, 00h 32 | mov cx, 00h 33 | mov dx, 00h 34 | compare: 35 | cmp si, 200 36 | jz output 37 | mov ax, buff[si] 38 | cmp ax, 0 39 | jl negative 40 | jg positive 41 | inc bx ;; zero 42 | jmp pass 43 | negative: 44 | inc cx ;; negative 45 | jmp pass 46 | positive: 47 | inc dx 48 | pass: 49 | inc si 50 | jmp compare 51 | 52 | output: 53 | mov n1, dx ;; positive 54 | mov n2, bx ;; zero 55 | mov n3, cx ;; negative 56 | 57 | mov ah, 4ch 58 | int 21h 59 | end start -------------------------------------------------------------------------------- /code/Forec/t8.asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t8 19 | 20 | d_seg segment 21 | augend dd 99251 22 | sum dd ? 23 | d_seg ends 24 | 25 | e_seg segment 26 | augadd dd -15962 27 | e_seg ends 28 | 29 | code segment 30 | assume cs:code, ds:d_seg, es:e_seg 31 | start: 32 | mov ax, d_seg 33 | mov ds, ax 34 | mov ax, e_seg 35 | mov es, ax 36 | mov ax, word ptr augend 37 | mov bx, word ptr augadd 38 | add ax, bx 39 | mov dx, word ptr augend[2] 40 | mov bx, word ptr augadd[2] 41 | adc dx, bx 42 | mov word ptr sum, ax 43 | mov word ptr sum[2], dx 44 | mov ah, 4ch 45 | int 21h 46 | code ends 47 | end start 48 | 49 | ;; ans is 83289, store in cs:0004-0008, 59 45 01 00 50 | -------------------------------------------------------------------------------- /code/Forec/t9(法1).asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/10/24 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t9 19 | 20 | .model small 21 | .data 22 | inputinfo db 100 dup(?) 23 | helpinfo db 'Input: $' 24 | outputinfo db 'Output: $' 25 | warninfo db 0dh, 0ah, 'Warning: You have input 100 letters, up to size!', 0dh, 0ah, '$' 26 | 27 | .code 28 | start: 29 | mov ax, @data 30 | mov ds, ax 31 | 32 | mov dx, offset helpinfo 33 | mov ah, 9h 34 | int 21h 35 | 36 | mov si, 0h 37 | mov ah, 1h 38 | let0: 39 | int 21h 40 | mov inputinfo[si], al 41 | inc si 42 | cmp al, 0dh 43 | jz let1 44 | cmp si, 100 45 | jl let0 46 | mov dx, offset warninfo 47 | mov ah, 9h 48 | int 21h 49 | let1: 50 | mov bx, 0h 51 | mov dx, offset outputinfo 52 | mov ah, 9h 53 | int 21h 54 | let2: 55 | and inputinfo[bx], 0dfh 56 | mov dl, inputinfo[bx] 57 | mov ah, 2h 58 | int 21h 59 | inc bx 60 | dec si 61 | jnz let2 62 | mov ah, 4ch 63 | int 21h 64 | end start -------------------------------------------------------------------------------- /code/Forec/t9(法2).asm: -------------------------------------------------------------------------------- 1 | ;; last edit date: 2016/11/1 2 | ;; author: Forec 3 | ;; LICENSE 4 | ;; Copyright (c) 2015-2017, Forec 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this code for any 7 | ;; purpose with or without fee is hereby granted, provided that the above 8 | ;; copyright notice and this permission notice appear in all copies. 9 | 10 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | 18 | title forec_t9 19 | 20 | data segment 21 | ; add your data here! 22 | pkey db 0ah, 0dh, "press any key...$" 23 | mess1 db 0ah, 0dh, 'input:$' 24 | mess2 db 0ah, 0dh, 'output:$' 25 | buff db 10, 0, 10 dup(0) 26 | ends 27 | 28 | stack segment 29 | dw 128 dup(0) 30 | ends 31 | 32 | code segment 33 | assume cs:code, ds:data 34 | start: 35 | ; set segment registers: 36 | mov ax, data 37 | mov ds, ax 38 | mov es, ax 39 | 40 | prog1: 41 | mov dx, offset mess1 42 | mov ah, 9 43 | int 21h 44 | mov dx, offset buff 45 | mov ah, 10 46 | int 21h 47 | mov cl, buff+1 48 | mov bx, 2 49 | mov dx, offset mess2 50 | mov ah, 9 51 | int 21h 52 | let1: 53 | and buff[bx], 0dfh 54 | mov dl, buff[bx] 55 | mov ah, 2 56 | int 21h 57 | inc bx 58 | dec cl 59 | jnz let1 60 | 61 | lea dx, pkey 62 | mov ah, 9 63 | int 21h 64 | 65 | ; wait for any key.... 66 | mov ah, 1 67 | int 21h 68 | 69 | mov ax, 4c00h ; 70 | int 21h 71 | ends 72 | 73 | end start ; 74 | -------------------------------------------------------------------------------- /code/YeWenting/T11.asm: -------------------------------------------------------------------------------- 1 | ;; Created by Ywt. 2 | ;; Date: 11/03/2016 3 | 4 | TITLE T11_YWT 5 | 6 | DATA SEGMENT 7 | ENDS 8 | 9 | CODE SEGMENT 10 | ASSUME CS:CODE, DS:DATA, SS:STACK 11 | 12 | START: ;; SET INITIAL VALUE 13 | MOV AX, 0ABCDH 14 | MOV BL, 0FH 15 | MOV CL, 04H 16 | MOV DL, 0F0H 17 | 18 | ;; TRANSFER 19 | AND BL, AH 20 | AND DL, AL 21 | SHR DL, CL 22 | AND AH, 0F0H 23 | SHR AH, CL 24 | XCHG DL, CL 25 | MOV DL, 0FH 26 | AND DL, AL 27 | MOV AL, AH 28 | 29 | ;; FINISH 30 | MOV AH, 4C0H 31 | MOV AL, AL 32 | INT 21H 33 | 34 | ENDS 35 | END START 36 | 37 | -------------------------------------------------------------------------------- /code/YeWenting/T13.asm: -------------------------------------------------------------------------------- 1 | ;; Created by Ywt. 2 | ;; Date: 11/03/2016 3 | 4 | TITLE T13_YWT 5 | 6 | DATA SEGMENT 7 | ENDS 8 | 9 | CODE SEGMENT 10 | ASSUME CS:CODE, DS:DATA, SS:STACK 11 | 12 | START: MOV AX, DATA 13 | MOV DS, AX 14 | 15 | ;; READ N TO CX 16 | MOV AH, 01H 17 | INT 21H 18 | SUB AL, 30H 19 | XOR CX, CX 20 | MOV CL, AL 21 | MOV AH, 02H 22 | MOV DL, 07H 23 | 24 | ;; RING 25 | RING: INT 21H 26 | LOOP RING 27 | 28 | ;; FINISH 29 | MOV AH, 4CH 30 | INT 21H 31 | 32 | ENDS 33 | END START 34 | 35 | -------------------------------------------------------------------------------- /code/YeWenting/T15.asm: -------------------------------------------------------------------------------- 1 | ;; Created by Ywt. 2 | ;; Date: 11/03/2016 3 | 4 | TITLE T15_YWT 5 | 6 | DATA SEGMENT 7 | ;; The mininum is 2, while there is a smaller odd num. 1 8 | DW 4, 1, 2, 97 DUP (4) 9 | ENDS 10 | 11 | CODE SEGMENT 12 | ASSUME CS:CODE, DS:DATA, SS:STACK 13 | 14 | START: MOV AX, DATA 15 | MOV DS, AX 16 | MOV CX, 100 17 | MOV DI, 0 18 | MOV AX, 07FFFH 19 | 20 | FIND: TEST [DI], 1 21 | JNZ NEXT 22 | CMP AX, [DI] 23 | JLE NEXT 24 | MOV AX, [DI] 25 | NEXT: ADD DI, 2 26 | LOOP FIND 27 | 28 | ;; FINISH 29 | MOV AH, 4CH 30 | INT 21H 31 | 32 | ENDS 33 | END START -------------------------------------------------------------------------------- /code/YeWenting/T17.asm: -------------------------------------------------------------------------------- 1 | ;; Created by Ywt. 2 | ;; Date: 11/21/2016 3 | ;; 4 | ;; USE BX TO STORE THE NUMBER 5 | ;; USE TEST TO GET BIT 6 | 7 | TITLE T17_YWT 8 | 9 | CODE SEGMENT 10 | ASSUME CS:CODE 11 | 12 | START: ;; GET INPUT 13 | XOR BX, BX 14 | MOV CX, 4 15 | 16 | READ: SHL BX, 4 17 | MOV AH, 1 18 | INT 21H 19 | SUB AL, 30H 20 | CMP AL, 9 21 | JBE ASSIGN ;; 0~9 22 | SUB AL, 7 ;; A~F 23 | ASSIGN: ADD BL, AL 24 | LOOP READ 25 | 26 | MOV AH, 2 ;; PRINT \n 27 | MOV DL, 0AH 28 | INT 21H 29 | MOV DL, 0DH ;; PRINT \r 30 | INT 21H 31 | 32 | ;; PRINT PART 33 | ;; CX->OUTER LOOP 34 | ;; SI->INNER LOOP 35 | ;; DI->NUMBER EXTRACTER 36 | MOV CX, 4 37 | OUTER: MOV DI, 8000H 38 | MOV SI, 4 39 | TRANS: TEST BX, DI 40 | MOV DL, 31H 41 | JNZ PRINT 42 | MOV DL, 30H 43 | PRINT: MOV AH, 2 44 | INT 21H 45 | SHR DI, 1 46 | DEC SI 47 | JNZ TRANS 48 | SHL BX, 4 49 | LOOP OUTER 50 | 51 | ;; FINISH 52 | MOV AH, 4CH 53 | INT 21H 54 | 55 | ENDS 56 | END START -------------------------------------------------------------------------------- /code/YeWenting/T19.asm: -------------------------------------------------------------------------------- 1 | ;; Created by Ywt. 2 | ;; Date: 11/21/2016 3 | ;; 4 | ;; LOOP: READ CHAR 5 | ;; JUDGE IF IT'S A NUMBER 6 | ;; BX-> NUM OF NON-NUMBER 7 | 8 | TITLE T19_YWT 9 | 10 | DATA SEGMENT 11 | ARRAY DB 10 DUP(?) 12 | ENDS 13 | 14 | CODE SEGMENT 15 | ASSUME CS:CODE DS:DATA 16 | 17 | START: XOR CX, CX 18 | MOV AX, DATA 19 | MOV DS, AX 20 | 21 | READ: MOV AH, 1 22 | INT 21H 23 | CMP AL, 24H 24 | JE RDEND 25 | CMP AL, 30H 26 | JB READ 27 | CMP AL, 39H 28 | JA READ 29 | INC CX 30 | JMP READ 31 | 32 | ;; STORE CX IN BASE 10 (BX->LEN AX->NUM CX->10) 33 | RDEND: XOR BX, BX 34 | MOV AX, CX 35 | MOV CL, 10 36 | TRANS: DIV CL 37 | ADD AH, '0' 38 | MOV ARRAY[BX], AH 39 | CBW 40 | INC BX 41 | CMP AX, 0 42 | JNZ TRANS 43 | 44 | ;; PRINT 'ENTER' 45 | MOV AH, 2 46 | MOV DL, 0AH 47 | INT 21H 48 | MOV DL, 0DH 49 | INT 21H 50 | 51 | ;; PRINT THE NUMBER 52 | PRINT: DEC BX 53 | MOV DL, ARRAY[BX] 54 | INT 21H 55 | JNZ PRINT 56 | 57 | EXIT: MOV AH, 4CH 58 | INT 21H 59 | ENDS 60 | END START -------------------------------------------------------------------------------- /code/YeWenting/T21.asm: -------------------------------------------------------------------------------- 1 | ;; Created by Ywt. 2 | ;; Date: 11/22/2016 3 | 4 | TITLE T21_YWT 5 | 6 | DATA SEGMENT 7 | STRING DB 99 DUP ('A'), '1' 8 | ENDS 9 | 10 | CODE SEGMENT 11 | ASSUME CS:CODE, DS:DATA 12 | 13 | START: MOV AX, DATA 14 | MOV DS, AX 15 | XOR CL, CL 16 | XOR BX, BX 17 | 18 | LOOP1: CMP STRING[BX], 30H 19 | JB NON 20 | CMP STRING[BX], 39H 21 | JA NON 22 | OR CL, 10H 23 | JMP END 24 | NON: INC BX 25 | CMP BX, 100 26 | JZ END 27 | JMP LOOP1 28 | 29 | ;; FINISH 30 | END: MOV AH, 4CH 31 | INT 21H 32 | 33 | ENDS 34 | END START -------------------------------------------------------------------------------- /code/YeWenting/T23.asm: -------------------------------------------------------------------------------- 1 | ;; Created by Ywt. 2 | ;; Date: 11/22/2016 3 | 4 | TITLE T23_YWT 5 | 6 | DATA SEGMENT 7 | M DW 1, -1, 2, 3, 6 DUP (0), ?, ? 8 | N EQU 10 9 | ENDS 10 | 11 | CODE SEGMENT 12 | ASSUME CS:CODE, DS:DATA 13 | 14 | START: MOV AX, DATA 15 | MOV DS, AX 16 | 17 | ;; BX->INDEX CX->MAX_ABS 18 | ;; DI->MAX_INDEX 19 | ;; DX->MAX_NUM 20 | XOR BX, BX 21 | XOR CX, CX 22 | LOOP1: MOV AX, M[BX] 23 | TEST AX, 8000H 24 | JZ ABS 25 | XOR AX, 0FFFFH 26 | INC AX 27 | ABS: CMP AX, CX 28 | JNA NEXT 29 | MOV CX, AX 30 | MOV DI, BX 31 | MOV DX, M[BX] 32 | NEXT: ADD BX, 2 33 | CMP BX, 2*N 34 | JNZ LOOP1 35 | 36 | END: MOV M[2*N], DX 37 | MOV M[2*N+2], DI 38 | 39 | ;; FINISH 40 | MOV AH, 4CH 41 | INT 21H 42 | 43 | ENDS 44 | END START -------------------------------------------------------------------------------- /code/YeWenting/T25.asm: -------------------------------------------------------------------------------- 1 | ;; Created by Ywt. 2 | ;; Date: 12/3/2016 3 | 4 | TITLE T25_YWT 5 | 6 | DATA SEGMENT 7 | MEM DB 4 DUP('?') 8 | ENDS 9 | 10 | CODE SEGMENT 11 | ASSUME CS:CODE, DS:DATA 12 | 13 | START: 14 | MOV AX, DATA 15 | MOV DS, AX 16 | 17 | MOV AX, 2A49H 18 | MOV SI, 0 19 | MOV CL, 4 20 | 21 | LOOP1: MOV BX, 000FH 22 | AND BX, AX 23 | CMP BX, 0AH 24 | JB ASCII 25 | ADD BX, 'A' - 3AH 26 | ASCII: ADD BX, 30H 27 | SHR AX, CL 28 | MOV MEM[SI], BL 29 | INC SI 30 | CMP SI, 5 31 | JNE LOOP1 32 | 33 | ;; FINISH 34 | MOV AH, 4CH 35 | INT 21H 36 | 37 | 38 | ENDS 39 | END START 40 | 41 | -------------------------------------------------------------------------------- /code/YeWenting/T27.asm: -------------------------------------------------------------------------------- 1 | ;; Created by Ywt. 2 | ;; Date: 12/4/2016 3 | 4 | TITLE T27_YWT 5 | 6 | DATA SEGMENT 7 | A DW 1, 2, 3, 4, 8, 10 DUP(?) 8 | B DW 0, 1, 4, 5, 9, 15 DUP(?) 9 | C DW 15 DUP(?) 10 | ENDS 11 | 12 | CODE SEGMENT 13 | ASSUME CS:CODE, DS:DATA 14 | 15 | START: 16 | MOV AX, DATA 17 | MOV DS, AX 18 | 19 | ;; SI->A DI->B BX->C 20 | MOV BX, 0 21 | MOV SI, 0 22 | LOOP1: MOV AX, A[SI] 23 | MOV DI, -1 24 | LOOP2: INC DI 25 | CMP DI, 20 26 | JZ NO ;; NO FOUND 27 | CMP AX, B[DI] 28 | JNZ LOOP2 29 | JMP YES ;; FOUND 30 | YES: MOV C[BX], AX 31 | INC BX 32 | NO: INC SI 33 | CMP SI, 15 34 | JE DONE 35 | JMP LOOP1 36 | 37 | ;; FINISH 38 | DONE: MOV AH, 4CH 39 | INT 21H 40 | 41 | 42 | ENDS 43 | END START 44 | 45 | -------------------------------------------------------------------------------- /code/YeWenting/T29.asm: -------------------------------------------------------------------------------- 1 | ;; Created by Ywt. 2 | ;; Date: 12/4/2016 3 | 4 | TITLE T29_YWT 5 | 6 | DATA SEGMENT 7 | ARRAY DW 1, -1, -1 8 | ENDS 9 | 10 | CODE SEGMENT 11 | ASSUME CS:CODE, DS:DATA 12 | 13 | START: 14 | MOV AX, DATA 15 | MOV DS, AX 16 | 17 | ;; AX->ARRAY[0] BX->ARRAY[1] DL->ANS 18 | MOV AX, ARRAY[0] 19 | MOV BX, ARRAY[2] 20 | CMP AX, BX 21 | JZ S0E1 22 | JMP S0NE1 23 | S0E1: CMP BX, ARRAY[2 * 2] 24 | JE ANS2 25 | JMP ANS1 26 | S0NE1: CMP AX, ARRAY[2 * 2] 27 | JE ANS1 28 | CMP BX, ARRAY[2 * 2] 29 | JNE ANS0 30 | JMP ANS1 31 | 32 | ANS0: MOV DL, 30H 33 | JMP PRINT 34 | ANS1: MOV DL, 31H 35 | JMP PRINT 36 | ANS2: MOV DL, 32H 37 | JMP PRINT 38 | 39 | PRINT: MOV AH, 02H 40 | INT 21H 41 | ;; FINISH 42 | MOV AH, 4CH 43 | INT 21H 44 | 45 | 46 | ENDS 47 | END START 48 | 49 | -------------------------------------------------------------------------------- /code/YeWenting/T31.asm: -------------------------------------------------------------------------------- 1 | ;; Created by Ywt. 2 | ;; Date: /2016 3 | 4 | TITLE T_YWT 5 | 6 | DATA SEGMENT 7 | A DW 1 8 | B DW 1 9 | ENDS 10 | 11 | CODE SEGMENT 12 | ASSUME CS:CODE, DS:DATA 13 | 14 | START: 15 | MOV AX, DATA 16 | MOV DS, AX 17 | 18 | ;; AX->A BX->B 19 | MOV AX, A 20 | MOV BX, B 21 | TEST AX, 0001H 22 | JZ AE 23 | JMP AO 24 | AE: TEST BX, 0001H 25 | JZ DONE 26 | JMP AEBO 27 | AO: TEST BX, 0001H 28 | JZ DONE 29 | JMP AOBO 30 | 31 | AOBO: ADD AX, 1 32 | MOV A, AX 33 | ADD BX, 1 34 | MOV B, BX 35 | JMP DONE 36 | AEBO: XCHG AX, BX 37 | MOV A, AX 38 | MOV B, BX 39 | DONE: 40 | ;; FINISH 41 | MOV AH, 4CH 42 | INT 21H 43 | 44 | 45 | ENDS 46 | END START 47 | 48 | -------------------------------------------------------------------------------- /code/YeWenting/T4.asm: -------------------------------------------------------------------------------- 1 | TITLE T4_YWT 2 | 3 | DATA SEGMENT 4 | BUFF DB 1, 2, 3, '123' 5 | EBUFF DB 0 6 | L EQU EBUFF - BUFF 7 | ANS DW L 8 | ENDS 9 | -------------------------------------------------------------------------------- /code/YeWenting/T5.asm: -------------------------------------------------------------------------------- 1 | TITLE T5_YWT 2 | 3 | DATA SEGMENT 4 | LNAME DB 30 DUP(?) 5 | ADDRESS DB 30 DUP(?) 6 | CITY DB 15 DUP(?) 7 | CODE_LIST DB 1, 7, 8, 3, 2 8 | ;;(3) 9 | CODE_LENGTH EQU $ - CODE_LIST 10 | VERIFY DB CODE_LENGTH 11 | ENDS 12 | 13 | CODE SEGMENT 14 | ASSUME CS:CODE, DS:DATA 15 | 16 | START: MOV AX, DATA 17 | MOV DS, AX 18 | 19 | ;; (1) 20 | MOV AX, WORD PTR LNAME 21 | 22 | ;; (2) 23 | MOV SI, WORD PTR CODE_LIST 24 | 25 | ;; FINISH 26 | MOV AX, 4C00H 27 | INT 21H 28 | 29 | ENDS 30 | END START 31 | -------------------------------------------------------------------------------- /code/YeWenting/T9.asm: -------------------------------------------------------------------------------- 1 | ;; Created by Ywt. 2 | ;; Date: 11/13/2016 3 | 4 | TITLE T9_YWT 5 | 6 | DATA SEGMENT 7 | ENDS 8 | 9 | CODE SEGMENT 10 | ASSUME CS:CODE, DS:DATA, SS:STACK 11 | 12 | START: MOV AX, DATA 13 | MOV DS, AX 14 | 15 | MOV AH, 01 16 | INT 21H 17 | SUB AL, 32 18 | MOV DL, AL 19 | MOV AH, 02 20 | INT 21H 21 | 22 | ;; FINISH 23 | MOV AX, 4C00H 24 | INT 21H 25 | 26 | ENDS 27 | END START 28 | 29 | -------------------------------------------------------------------------------- /code/YeWenting/book4-16.asm: -------------------------------------------------------------------------------- 1 | ;; Created by Ywt. 2 | ;; Date: 11/03/2016 3 | 4 | TITLE 4.16_YWT 5 | 6 | DATA SEGMENT 7 | BUFF DW 50 DUP(-1) 8 | DW 50 DUP(0) 9 | DW 100 DUP(1) 10 | N1 DB ? 11 | N2 DB ? 12 | N3 DB 200 13 | ENDS 14 | 15 | CODE SEGMENT 16 | ASSUME CS:CODE, DS:DATA 17 | 18 | START: MOV AX, DATA 19 | MOV DS, AX 20 | 21 | ;; DH= NUM OF POSITIVE DL = NUM OF ZERO 22 | MOV CX, 200 23 | LEA SI, BUFF 24 | MOV DX, 0 25 | SUB SI, 2 26 | 27 | CHECK: ADD SI, 2 28 | CMP [SI],0 29 | JNZ NZ 30 | INC DL 31 | LOOP CHECK 32 | JMP ASSIGN 33 | NZ: JG NGE 34 | INC DH 35 | LOOP CHECK 36 | JMP ASSIGN 37 | NGE: LOOP CHECK 38 | 39 | ;; STORE DATA TO RAM 40 | ASSIGN: MOV N1, DH 41 | MOV N2, DL 42 | SUB N3, DH 43 | SUB N3, DL 44 | 45 | ;; FINISH 46 | MOV AX, 4C00H 47 | INT 21H 48 | 49 | ENDS 50 | END START -------------------------------------------------------------------------------- /code/YeWenting/book4-28.asm: -------------------------------------------------------------------------------- 1 | ;; Created by Ywt. 2 | ;; Date: 11/09/2016 3 | 4 | TITLE 4.28_YWT 5 | 6 | CALC MACRO X, Y, SUM 7 | ;; STORE THE REGISTERS 8 | PUSH AX 9 | PUSH DX 10 | XOR DX, DX 11 | 12 | ;; CALCULATE THE SUM 13 | ADD DX, X 14 | ADD DX, Y 15 | MOV AX, X 16 | CMP AX, Y 17 | JG XG 18 | ADD DX, X 19 | JMP A_SUM 20 | XG: ADD DX, Y 21 | 22 | A_SUM: MOV SUM, DX 23 | ;;RESTORE 24 | POP DX 25 | POP AX 26 | ENDM 27 | 28 | DATA SEGMENT 29 | NUM1 DW 3 30 | NUM2 DW 3 31 | ANS DW ? 32 | ENDS 33 | 34 | CODE SEGMENT 35 | ASSUME CS:CODE, DS:DATA, SS:STACK 36 | 37 | START: MOV AX, DATA 38 | MOV DS, AX 39 | 40 | CALC NUM1, NUM2, ANS 41 | 42 | ;; FINISH 43 | MOV AX, 4C00H 44 | INT 21H 45 | ENDS 46 | END START 47 | 48 | -------------------------------------------------------------------------------- /code/YeWenting/t1.asm: -------------------------------------------------------------------------------- 1 | title t1_ywt 2 | 3 | DATA SEGMENT 4 | ARRAY DW 23, 36, 2, 100, 32000, 54, 0; 5 | ZERO DW ? 6 | DATA ENDS 7 | 8 | CODE SEGMENT 9 | START: 10 | ;; set ZERO in the (1) way 11 | mov ax, DATA 12 | mov ds, ax 13 | lea bx, ARRAY 14 | mov WORD PTR [bx+2*7], 0 15 | 16 | ;; reset ZERO to 0ffffh 17 | mov [bx+2*7], 0ffffh; 18 | 19 | ;; set ZERO in the (2) way 20 | lea bx, ARRAY[2*6] 21 | mov WORD PTR [bx+2], 0 22 | 23 | ;; Back to DOS 24 | mov ax,4c00h 25 | int 21h 26 | 27 | CODE ENDS 28 | END START 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /code/YeWenting/t2.asm: -------------------------------------------------------------------------------- 1 | TITLE T2_YWT 2 | 3 | DATASG SEGMENT 4 | FLD1B DB 'personal computer' 5 | FLD2B DB 32 6 | FLD3B DB 20H 7 | FLD4B DB 01011001B 8 | FLD5B DB '32654' 9 | FLD6B DB 10 DUP(0) 10 | FLD7B DB 'PART1', 20, 'PART2', 50, 'PART3', 14 11 | 12 | FLD1W DW 0FFF0H 13 | FLD2W DW 01011001B 14 | FLD3W DW FLD7B 15 | FLD4W DW 5, 6, 7, 8, 9 16 | FLD5W DW 5 DUP(0) 17 | FLD6W DW FLD1W - FLD1B 18 | ENDS 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /code/YeWenting/t3.asm: -------------------------------------------------------------------------------- 1 | TITLE T3_YWT 2 | 3 | DATA SEGMENT 4 | PARTNO DW ? 5 | PNAME DB 16 DUP(?) 6 | COUNT DD ? 7 | PLENTH EQU $ - PARTNO 8 | ANSWER DW PLENTH 9 | ENDS 10 | -------------------------------------------------------------------------------- /code/dsryhh/11.asm: -------------------------------------------------------------------------------- 1 | .model small 2 | .data 3 | splited db 4 dup(?) 4 | .code 5 | start: 6 | mov ax, @data 7 | mov ds, ax 8 | 9 | call split 10 | 11 | mov al, splited 12 | mov bl, splited + 1 13 | mov cl, splited + 2 14 | mov dl, splited + 3 15 | 16 | mov ah,4ch 17 | int 21h 18 | 19 | split proc 20 | push dx 21 | push bx 22 | push cx 23 | 24 | mov bx, offset splited 25 | mov cx,4 26 | 27 | mov dx,ax 28 | and dx, 1111b 29 | mov [bx],dl 30 | 31 | ror ax,cl 32 | mov dx,ax 33 | and dx, 1111b 34 | mov [bx+1],dl 35 | 36 | ror ax,cl 37 | mov dx,ax 38 | and dx, 1111b 39 | mov [bx+2],dl 40 | 41 | ror ax,cl 42 | mov dx,ax 43 | and dx, 1111b 44 | mov [bx+3],dl 45 | 46 | pop cx 47 | pop bx 48 | pop dx 49 | ret 50 | split endp 51 | 52 | end start -------------------------------------------------------------------------------- /code/dsryhh/12.asm: -------------------------------------------------------------------------------- 1 | ;12、试编写一程序,要求比较两个字符串 STRING1 和 STRING2 所含字符是否完全相同,若相同则显示 MATCH,若不相同则显示 NO MATCH。 2 | .model small 3 | .data 4 | STRING1 db 'hello world!',0 5 | STRING2 db 'hello china!',0 6 | matchString db 'MATCH$' 7 | nomatchString db 'NO MATCH$' 8 | .code 9 | start: 10 | mov ax,@data 11 | mov ds,ax 12 | 13 | call compare 14 | 15 | mov ah,4ch 16 | int 21h 17 | 18 | compare proc 19 | push ax 20 | push bx 21 | push dx 22 | push si 23 | 24 | mov si,0 25 | 26 | comstart: 27 | mov bx,offset STRING1 28 | mov dl,[bx][si] 29 | mov bx,offset STRING2 30 | 31 | cmp dl, [bx][si] 32 | jne nomatch 33 | 34 | cmp dl, 0 35 | je match 36 | 37 | inc si 38 | jmp comstart 39 | 40 | nomatch: 41 | mov dx,offset nomatchString 42 | mov ah,09h 43 | int 21h 44 | jmp funcreturn 45 | 46 | match: 47 | mov dx,offset matchString 48 | mov ah,09h 49 | int 21h 50 | jmp funcreturn 51 | funcreturn: 52 | pop si 53 | pop dx 54 | pop bx 55 | pop ax 56 | 57 | ret 58 | compare endp 59 | 60 | end start -------------------------------------------------------------------------------- /code/dsryhh/15.asm: -------------------------------------------------------------------------------- 1 | ;15、试编写一个汇编语言程序,求出首地址为 DATA 的 100D 字数组中的最小偶数,并把它存放在 AX 中。 2 | .model small 3 | .data 4 | data dw 10,9,8,7,6,5,4,3,2,1,90 dup(60) 5 | .code 6 | start: 7 | mov ax,@data 8 | mov ds,ax 9 | 10 | call mineven 11 | 12 | mov ah,4ch 13 | int 21h 14 | 15 | mineven proc 16 | push bx 17 | push cx 18 | push dx 19 | push si 20 | 21 | 22 | mov bx,offset data 23 | mov si,0 24 | mov cx,100 25 | mov ax,[bx][si] 26 | 27 | checker: 28 | mov dx,[bx][si] 29 | test dx,1b 30 | jnz continue;check if even 31 | 32 | cmp ax,dx 33 | jle continue 34 | 35 | mov ax,dx 36 | 37 | continue: 38 | add si,2 39 | loop checker 40 | 41 | pop si 42 | pop dx 43 | pop cx 44 | pop bx 45 | 46 | ret 47 | mineven endp 48 | end start -------------------------------------------------------------------------------- /code/dsryhh/19.asm: -------------------------------------------------------------------------------- 1 | ;19、从键盘输入一系列以 $ 为结束符的字符串,然后对其中的非数字字符计数,并显示出计数结果。 2 | .model small 3 | .data 4 | strings db '1234fdsa56fdsafdsa7fdsa890$' 5 | .code 6 | start: 7 | mov ax,@data 8 | mov ds,ax 9 | 10 | call counter 11 | 12 | mov ah,4ch 13 | int 21h 14 | 15 | counter proc 16 | 17 | push ax 18 | push bx 19 | push dx 20 | push si 21 | 22 | mov bx,offset strings 23 | mov si,0 24 | 25 | mov ax,0 26 | 27 | startcount: 28 | mov dl,[bx][si] 29 | cmp dl, '0' 30 | jl nextloop 31 | cmp dl,'9' 32 | jg nextloop 33 | inc ax 34 | 35 | nextloop: 36 | cmp dl,'$' 37 | je display 38 | inc si 39 | jmp startcount 40 | 41 | display: 42 | mov dx,10 43 | div dl 44 | add al,'0' 45 | add ah,'0' 46 | push ax 47 | mov dl,al 48 | mov ah,02h 49 | int 21h 50 | pop ax 51 | mov dl,ah 52 | mov ah,02h 53 | int 21h 54 | 55 | pop si 56 | pop dx 57 | pop bx 58 | pop ax 59 | ret 60 | counter endp 61 | end start 62 | 63 | -------------------------------------------------------------------------------- /code/dsryhh/29.asm: -------------------------------------------------------------------------------- 1 | ;29、试编写一程序,要求比较数组 ARRAY中 的三个 16 位补码数,并根据比较结果在终端上显示如下信息: 2 | .model small 3 | .data 4 | array dw -2,2,-2 5 | .code 6 | start: 7 | mov ax, @data 8 | mov ds,ax 9 | 10 | call compAndDisp 11 | 12 | mov ah,4ch 13 | int 21h 14 | 15 | compAndDisp proc 16 | push ax 17 | push dx 18 | 19 | mov ax,0 20 | mov dx,array 21 | 22 | cmp dx,array + 2 23 | jne cmp2 24 | inc ax 25 | 26 | cmp2: 27 | cmp dx,array + 4 28 | jne cmp3 29 | inc ax 30 | 31 | cmp3: 32 | mov dx,array + 2 33 | cmp dx,array + 4 34 | jne cmpend 35 | inc ax 36 | 37 | cmpend: 38 | cmp ax,0 39 | je disp0 40 | cmp ax,1 41 | je disp1 42 | jmp disp2 43 | 44 | disp0: 45 | mov dx,'0' 46 | mov ah,02h 47 | int 21h 48 | jmp procend 49 | 50 | disp1: 51 | mov dx,'1' 52 | mov ah,02h 53 | int 21h 54 | jmp procend 55 | 56 | disp2: 57 | mov dx,'2' 58 | mov ah,02h 59 | int 21h 60 | jmp procend 61 | 62 | procend: 63 | pop dx 64 | pop ax 65 | ret 66 | compAndDisp endp 67 | end start -------------------------------------------------------------------------------- /code/dsryhh/44.asm: -------------------------------------------------------------------------------- 1 | ;假设有二十个无符号字存放在以 Buffer 为开始的缓冲区中,编写一个程序把它们从低到高排序。 2 | .model small 3 | .data 4 | buffer dw 1,2,10,3,4,5,6,7,20,8,9,11,12,13,14,15,16,17,18,19 5 | .code 6 | start: 7 | mov ax,@data 8 | mov ds,ax 9 | 10 | mov bx, offset buffer 11 | call sortbuffer 12 | 13 | mov ah,4ch 14 | int 21h 15 | 16 | sortbuffer proc 17 | push bx 18 | push dx 19 | push cx 20 | push si 21 | 22 | lea bx, buffer 23 | mov si,0 24 | mov cx,19 25 | 26 | outerloop: 27 | push cx 28 | push si 29 | innerloop: 30 | mov dx,[bx][si] 31 | cmp dx,[bx+si+2] 32 | ja exchange 33 | jmp noexchange 34 | exchange: 35 | xchg dx,[bx+si+2] 36 | mov [bx+si],dx 37 | noexchange: 38 | add si,2 39 | loop innerloop 40 | pop si 41 | pop cx 42 | add si,2 43 | loop outerloop 44 | 45 | pop si 46 | pop cx 47 | pop dx 48 | pop bx 49 | ret 50 | sortbuffer endp 51 | end start -------------------------------------------------------------------------------- /code/dsryhh/77.asm: -------------------------------------------------------------------------------- 1 | data segment 2 | STUNAME DB 20 DUP(10 DUP('$'));each name has 10 bytes 3 | CLASS DB 20 DUP('$');each class has 1 byte 4 | STUID DB 20 DUP(10 DUP('$'));each id has 10 bytes 5 | SCORE DB 20 DUP(0,0);each score has 2 bytes 6 | COUNT DB 0;count of the student list 7 | SCORESEGMENT DB 5 DUP(0);fail,60~70,70~80,80~90,90~100 8 | DISPLAYORDER DB 20 DUP(0) 9 | 10 | RecordHint DB '---Student info input---',0dh,0ah,'$' 11 | RecordFinishHint DB '---Student info input complete---',0dh,0ah,'$' 12 | InputNumHint DB 'Input the number of students',0dh,0ah,'$' 13 | InputNameHint DB 'Input the name of students',0dh,0ah,'$' 14 | InputClassHint DB 'Input the class of students',0dh,0ah,'$' 15 | InputIdHint DB 'Input the id of students',0dh,0ah,'$' 16 | InputScoreHint DB 'Input the score of students. Example: 70.0',0dh,0ah,'$' 17 | NewLine DB 0dh,0ah,'$' 18 | ScoreSegmentLevelHint DB '-E- -D- -C- -B- -A-',0dh,0ah,'$' 19 | 20 | AppName DB '-----Student Information Management System-----',0dh,0ah,'$' 21 | Help DB '-r Register new student',0dh,0ah, 22 | '-d Display students list (ordered by score)',0dh,0ah, 23 | '-a Average score',0dh,0ah, 24 | '-n The number of each segments',0dh,0ah, 25 | '-h Help',0dh,0ah, 26 | '-q Exit system',0dh,0ah,'$' 27 | 28 | ArgumentExceptionHint DB 'Illegal argument. Try again.',0dh,0ah,'$' 29 | 30 | data ends 31 | stack segment stack 32 | DW 100h dup(?) 33 | stack ends 34 | code segment 35 | assume cs:code,ds:data,ss:stack 36 | main proc 37 | start: 38 | ;----clear all register 39 | xor ax,ax 40 | xor bx,bx 41 | xor cx,cx 42 | xor dx,dx 43 | xor si,si 44 | xor di,di 45 | 46 | mov ax,data 47 | mov ds,ax;init ds 48 | 49 | call dispappname 50 | call disphelp 51 | 52 | commandReadIn: 53 | call disphyphen 54 | 55 | mov ah,01h 56 | int 21h;READ CHARACTER FROM STANDARD INPUT 57 | ;command store in AL now 58 | 59 | call dispnewline 60 | 61 | cmp al,'r';switch 62 | je recordCommand 63 | cmp al,'d' 64 | je displayCommand 65 | cmp al,'a' 66 | je averageCommand 67 | cmp al,'n' 68 | je numberCommand 69 | cmp al,'h' 70 | je helpCommand 71 | cmp al,'q' 72 | je exit 73 | call disphelp 74 | jmp commandReadIn;input illegal parameter 75 | 76 | recordCommand: 77 | call recordf 78 | jmp commandReadIn 79 | 80 | displayCommand: 81 | call dispinorder 82 | jmp commandReadIn 83 | 84 | averageCommand: 85 | call averagescore 86 | jmp commandReadIn 87 | 88 | numberCommand: 89 | call statisticsegment 90 | jmp commandReadIn 91 | 92 | helpCommand: 93 | call disphelp 94 | jmp commandReadIn 95 | 96 | exit: 97 | mov ah,4ch 98 | int 21h 99 | main endp 100 | 101 | recordf proc 102 | push dx 103 | push ax 104 | push bx 105 | push cx 106 | 107 | lea dx,RecordHint 108 | mov ah,09h 109 | int 21h;output hint 110 | 111 | recordfInputNumBegin: 112 | lea dx,InputNumHint 113 | mov ah,09h 114 | int 21h;output hint 115 | 116 | mov ah,01h 117 | int 21h;READ CHARACTER FROM STANDARD INPUT 118 | call dispnewline 119 | ;number store in AL now 120 | ;paramater vaildation 121 | cmp al,'0' 122 | jl recordfInputNumError 123 | cmp al,'9' 124 | jg recordfInputNumError 125 | jmp recordfInputNumRight 126 | recordfInputNumError: 127 | call dispwrongargumenthint 128 | jmp recordfInputNumBegin 129 | recordfInputNumRight: 130 | sub al,30h;convert ASCII code to number 131 | xor cx,cx;set cx to zero 132 | mov cl,al 133 | 134 | 135 | onestu: 136 | call readname 137 | call dispnewline 138 | 139 | call readclass 140 | call dispnewline 141 | 142 | call readstuid 143 | call dispnewline 144 | 145 | call readscore 146 | call dispnewline 147 | 148 | inc COUNT 149 | dec cx 150 | jne onestu 151 | 152 | lea dx,RecordFinishHint 153 | mov ah,09h 154 | int 21h;output hint 155 | 156 | pop cx 157 | pop bx 158 | pop ax 159 | pop dx 160 | ret 161 | recordf endp 162 | 163 | dispinorder proc 164 | push cx 165 | push dx 166 | push ax 167 | push dx 168 | push si 169 | xor cx,cx 170 | 171 | mov cx,0 172 | mov cl,COUNT 173 | call sortbyscore 174 | mov bx,offset DISPLAYORDER 175 | mov si,0 176 | dispinorderLoop: 177 | ;mov dl,cl 178 | ;dec dl;index begin from 0 179 | mov dx,0 180 | mov dl,[bx][si] 181 | call dispitem 182 | 183 | inc si 184 | loop dispinorderLoop 185 | 186 | pop si 187 | pop dx 188 | pop ax 189 | pop dx 190 | pop cx 191 | ret 192 | dispinorder endp 193 | 194 | readname proc 195 | ;input name begin 196 | push cx 197 | push dx 198 | push ax 199 | push si 200 | push bx 201 | lea dx,InputNameHint 202 | mov ah,09h 203 | int 21h;output hint 204 | 205 | mov dl,10 206 | mov al,COUNT 207 | mul dl;ax = count * 10. offset of name 208 | mov si,ax 209 | lea bx,STUNAME 210 | mov cx,0 211 | inputname: 212 | mov ah,01h 213 | int 21h;READ CHARACTER FROM STANDARD INPUT 214 | cmp al,0dh 215 | je inputnamefinish 216 | cmp cx,9d 217 | je inputnamefinish 218 | 219 | mov [bx][si],al 220 | 221 | inc si 222 | inc cx 223 | jmp inputname 224 | inputnamefinish: 225 | mov [bx][si],'$' 226 | pop bx 227 | pop si 228 | pop ax 229 | pop dx 230 | pop cx 231 | ret 232 | readname endp 233 | 234 | readclass proc 235 | ;input class begin 236 | push dx 237 | push ax 238 | push si 239 | push bx 240 | 241 | lea dx,InputClassHint 242 | mov ah,09h 243 | int 21h;output hint 244 | 245 | mov ax,0 246 | mov al,COUNT 247 | mov si,ax;COUNT in al 248 | lea bx,class 249 | 250 | mov ah,01h 251 | int 21h;READ CHARACTER FROM STANDARD INPUT 252 | 253 | sub al,30h;convert ASCII code to number 254 | mov [bx][si],al 255 | 256 | pop bx 257 | pop si 258 | pop ax 259 | pop dx 260 | ret 261 | readclass endp 262 | 263 | readstuid proc 264 | ;input stuid begin 265 | push ax 266 | push bx 267 | push cx 268 | push dx 269 | push si 270 | lea dx,InputIdHint 271 | mov ah,09h 272 | int 21h;output hint 273 | 274 | mov dl,10 275 | mov ax,0 276 | mov al,COUNT 277 | mul dl;ax = count * 10. offset of name 278 | mov si,ax 279 | lea bx,STUID 280 | mov cx,0 281 | inputid: 282 | mov ah,01h 283 | int 21h;READ CHARACTER FROM STANDARD INPUT 284 | cmp al,0dh 285 | je inputidfinish 286 | cmp cx,9d 287 | je inputidfinish 288 | 289 | ;sub al,30h 290 | mov [bx][si],al 291 | 292 | inc si 293 | inc cx 294 | jmp inputid 295 | inputidfinish: 296 | mov [bx][si],'$' 297 | pop si 298 | pop dx 299 | pop cx 300 | pop bx 301 | pop ax 302 | ret 303 | readstuid endp 304 | 305 | readscore proc 306 | ;input score begin 307 | push ax 308 | push bx 309 | push dx 310 | push si 311 | lea dx,InputScoreHint 312 | mov ah,09h 313 | int 21h;output hint 314 | 315 | push dx 316 | xor dx,dx 317 | mov dl,COUNT 318 | mov si,dx 319 | pop dx 320 | add si,si;si = count * 2 321 | lea bx,SCORE 322 | 323 | mov ah,01h 324 | int 21h;READ CHARACTER FROM STANDARD INPUT 325 | sub al,30h;convert ASCII code to number 326 | mov dl,10 327 | mul dl 328 | mov dx,ax;ten-digit in DX. 329 | 330 | mov ah,01h 331 | int 21h;READ CHARACTER FROM STANDARD INPUT 332 | sub al,30h;convert ASCII code to number 333 | add dl,al;score < 100, so dh = 00h 334 | 335 | mov [bx][si],dl;integer part 336 | 337 | mov ah,01h 338 | int 21h;READ CHARACTER FROM STANDARD INPUT 339 | cmp al,'.' 340 | jne inputscorefinish 341 | mov ah,01h 342 | int 21h;READ CHARACTER FROM STANDARD INPUT 343 | sub al,30h 344 | mov 1h[bx][si],al 345 | 346 | inputscorefinish: 347 | pop si 348 | pop dx 349 | pop bx 350 | pop ax 351 | ret 352 | readscore endp 353 | 354 | dispitem proc 355 | ;input: DL: index 356 | 357 | call dispitemname 358 | call dispitemclass 359 | call dispitemstuid 360 | call dispitemscore 361 | 362 | call dispnewline 363 | 364 | ret 365 | dispitem endp 366 | 367 | dispitemname proc 368 | ;display name 369 | ;input DX index 370 | push dx 371 | push bx 372 | push ax 373 | push si 374 | lea bx,ds:STUNAME 375 | mov al,10 376 | mul dl 377 | mov si,ax 378 | 379 | lea dx,ds:[bx][si] 380 | mov ah,09h 381 | int 21h;output name 382 | 383 | call dispwhitespace 384 | pop si 385 | pop ax 386 | pop bx 387 | pop dx 388 | ret 389 | dispitemname endp 390 | 391 | dispitemclass proc 392 | ;display class 393 | push dx 394 | push bx 395 | push si 396 | push ax 397 | lea bx,ds:CLASS 398 | mov si,dx 399 | mov dl,ds:[bx][si] 400 | add dl,30h;convert number to ASCII code 401 | mov ah,02h 402 | int 21h 403 | 404 | call dispwhitespace 405 | pop ax 406 | pop si 407 | pop bx 408 | pop dx 409 | ret 410 | dispitemclass endp 411 | 412 | dispitemstuid proc 413 | ;display stuid 414 | push dx 415 | push bx 416 | push ax 417 | push si 418 | lea bx,ds:STUID 419 | mov al,10 420 | mul dl 421 | mov si,dx 422 | 423 | lea dx,ds:[bx][si] 424 | mov ah,09h 425 | int 21h;output id 426 | 427 | call dispwhitespace 428 | pop si 429 | pop ax 430 | pop bx 431 | pop dx 432 | ret 433 | dispitemstuid endp 434 | 435 | dispitemscore proc 436 | ;display score 437 | ;input DX index 438 | push dx 439 | push bx 440 | push si 441 | push ax 442 | 443 | lea bx,ds:SCORE 444 | mov si,dx 445 | add si,si;SI = DL * 2 446 | 447 | mov ax,0 448 | mov al,ds:[bx][si] 449 | mov dl,10 450 | div dl;DL = AX / 10, AL = integer part of score 451 | 452 | push ax;02h system interrupt will use al as return value 453 | mov dl,al 454 | add dl,30h;convert number to ASCII code 455 | mov ah,02h 456 | int 21h 457 | pop ax 458 | 459 | push ax;02h system interrupt will use al as return value 460 | mov dl,ah 461 | add dl,30h;convert number to ASCII code 462 | mov ah,02h 463 | int 21h 464 | pop ax 465 | 466 | call dispdot 467 | 468 | push ax 469 | mov dl,ds:1h[bx][si] 470 | add dl,30h;convert number to ASCII code 471 | mov ah,02h 472 | int 21h 473 | pop ax 474 | 475 | call dispwhitespace 476 | 477 | pop ax 478 | pop si 479 | pop bx 480 | pop dx 481 | ret 482 | dispitemscore endp 483 | 484 | dispwhitespace proc 485 | push dx 486 | push ax 487 | mov dl,' ' 488 | mov ah,02h 489 | int 21h;display a withespace 490 | pop ax 491 | pop dx 492 | 493 | ret 494 | dispwhitespace endp 495 | 496 | dispnewline proc 497 | push ax 498 | push dx 499 | lea dx,NewLine 500 | mov ah,09h 501 | int 21h;output hint 502 | pop dx 503 | pop ax 504 | ret 505 | dispnewline endp 506 | 507 | dispwrongargumenthint proc 508 | push ax 509 | push dx 510 | lea dx,ArgumentExceptionHint 511 | mov ah,09h 512 | int 21h;output hint 513 | pop dx 514 | pop ax 515 | ret 516 | dispwrongargumenthint endp 517 | 518 | disphelp proc 519 | push ax 520 | push dx 521 | lea dx,Help 522 | mov ah,09h 523 | int 21h;output hint 524 | 525 | call dispnewline 526 | pop dx 527 | pop ax 528 | ret 529 | disphelp endp 530 | 531 | dispappname proc 532 | push ax 533 | push dx 534 | lea dx,AppName 535 | mov ah,09h 536 | int 21h;output hint 537 | pop dx 538 | pop ax 539 | ret 540 | dispappname endp 541 | 542 | dispsegmentlevelhint proc 543 | push ax 544 | push dx 545 | lea dx,ScoreSegmentLevelHint 546 | mov ah,09h 547 | int 21h;output hint 548 | pop dx 549 | pop ax 550 | ret 551 | dispsegmentlevelhint endp 552 | 553 | disphyphen proc 554 | push dx 555 | push ax 556 | mov dl,'-' 557 | mov ah,02h 558 | int 21h;display a withespace 559 | pop ax 560 | pop dx 561 | 562 | ret 563 | disphyphen endp 564 | 565 | dispdot proc 566 | push dx 567 | push ax 568 | mov dl,'.' 569 | mov ah,02h 570 | int 21h;display a dot 571 | pop ax 572 | pop dx 573 | 574 | ret 575 | dispdot endp 576 | 577 | disptabs proc 578 | push dx 579 | push ax 580 | mov dl,09h 581 | mov ah,02h 582 | int 21h;display a tab 583 | pop ax 584 | pop dx 585 | 586 | ret 587 | disptabs endp 588 | 589 | averagescore proc 590 | push cx 591 | push dx 592 | mov cx,0 593 | 594 | ;integer part 595 | mov si,0 596 | call scoresum;return value in AX 597 | mov dl,COUNT 598 | div dl;result store in AX 599 | push ax 600 | mov al,ah;Handle the remainder 601 | mov dx,10 602 | mul dl;remainder * 10 603 | mov dl,COUNT 604 | div dl;remainder * 10 / COUNT = decimal part 605 | mov dl,al;dl: decimal part 606 | pop ax 607 | mov dh,al;dh: integer part 608 | push dx 609 | 610 | ;decimal part 611 | mov si,1 612 | call scoresum 613 | mov dl,COUNT 614 | div dl;decimal part in AL 615 | 616 | pop dx 617 | 618 | add dl,al;result in dx 619 | call dispfloat 620 | call dispnewline 621 | 622 | pop cx 623 | pop dx 624 | ret 625 | averagescore endp 626 | 627 | scoresum proc 628 | ;PARAM SI: SI = 0, integer part; SI = 1, decimal part 629 | ;RETURN AX: sum 630 | push si 631 | push cx 632 | push dx 633 | mov cx,0 634 | mov cl,COUNT 635 | mov ax,0 636 | 637 | mov bx, offset SCORE 638 | 639 | scoresumloopallcount: 640 | mov dx,0 641 | mov dl,[bx][si] 642 | add ax,dx 643 | 644 | add si,2h 645 | loop scoresumloopallcount 646 | pop dx 647 | pop cx 648 | pop si 649 | ret 650 | scoresum endp 651 | 652 | dispfloat proc 653 | ;input param: dx float to be showed 654 | push dx 655 | mov dl,dh 656 | mov dh,0 657 | call dispbyte 658 | pop dx 659 | call dispdot 660 | 661 | add dl,30h 662 | call dispchar 663 | 664 | ret 665 | dispfloat endp 666 | 667 | dispbyte proc 668 | ;input param: dl 669 | push dx 670 | push ax 671 | mov dh,0 672 | mov ax,dx 673 | mov dx,100 674 | div dl 675 | mov dl,al 676 | add dl,30h 677 | call dispchar 678 | 679 | mov al,ah 680 | mov ah,0 681 | mov dx,10 682 | div dl 683 | mov dl,al 684 | add dl,30h 685 | call dispchar 686 | 687 | mov al,ah 688 | mov ah,0 689 | mov dx,1 690 | div dl 691 | mov dl,al 692 | add dl,30h 693 | call dispchar 694 | 695 | pop ax 696 | pop dx 697 | ret 698 | dispbyte endp 699 | 700 | dispchar proc 701 | ;input char(ASCII code) in dl 702 | push dx 703 | push ax 704 | mov ah,02h 705 | int 21h;display a withespace 706 | pop ax 707 | pop dx 708 | 709 | ret 710 | dispchar endp 711 | 712 | statisticsegment proc 713 | push bx 714 | push cx 715 | push si 716 | mov cx,0 717 | mov cl,COUNT 718 | 719 | cmp cl,0 720 | je statisticsegmentexit 721 | 722 | mov bx,offset SCORE 723 | mov si,0 724 | 725 | statisticsegmentloop: 726 | mov dx,0 727 | mov dl,[bx][si] 728 | call scoresegmentchecker 729 | 730 | add si,2 731 | loop statisticsegmentloop 732 | 733 | statisticsegmentexit: 734 | call dispscoresegment 735 | pop si 736 | pop cx 737 | pop bx 738 | ret 739 | statisticsegment endp 740 | 741 | scoresegmentchecker proc 742 | ;input param DL: integer part of score 743 | pushf 744 | cmp dl,90d 745 | jge scoresegmentchecker90 746 | cmp dl,80d 747 | jge scoresegmentchecker80 748 | cmp dl,70d 749 | jge scoresegmentchecker70 750 | cmp dl,60d 751 | jge scoresegmentchecker60 752 | jmp scoresegmentcheckerfailed 753 | 754 | scoresegmentchecker90: 755 | inc SCORESEGMENT + 4 756 | jmp scoresegmentcheckerexit 757 | scoresegmentchecker80: 758 | inc SCORESEGMENT + 3 759 | jmp scoresegmentcheckerexit 760 | scoresegmentchecker70: 761 | inc SCORESEGMENT + 2 762 | jmp scoresegmentcheckerexit 763 | scoresegmentchecker60: 764 | inc SCORESEGMENT + 1 765 | jmp scoresegmentcheckerexit 766 | scoresegmentcheckerfailed: 767 | inc SCORESEGMENT 768 | jmp scoresegmentcheckerexit 769 | scoresegmentcheckerexit: 770 | 771 | popf 772 | ret 773 | scoresegmentchecker endp 774 | 775 | dispscoresegment proc 776 | push cx 777 | push bx 778 | push si 779 | push dx 780 | mov bx,offset SCORESEGMENT 781 | mov si,0 782 | mov cx,5 783 | call dispsegmentlevelhint 784 | dispscoresegmentloop: 785 | mov dl,[bx][si] 786 | call dispbyte 787 | call dispwhitespace 788 | inc si 789 | loop dispscoresegmentloop 790 | call dispnewline 791 | pop dx 792 | pop si 793 | pop bx 794 | pop cx 795 | ret 796 | dispscoresegment endp 797 | 798 | sortbyscore proc 799 | push ax 800 | push cx 801 | push bx 802 | push si 803 | 804 | call initorder 805 | 806 | mov bx,offset DISPLAYORDER 807 | mov si,0 808 | mov cx,0 809 | mov cl,COUNT 810 | 811 | cmp cl,1 812 | je sortbyscoreexit;if COUNT == 1 then return 813 | 814 | dec cl;loop COUNT - 1 times 815 | sortbyscoreloopouter: 816 | push cx 817 | mov cx,0 818 | mov cl,COUNT 819 | dec cl;loop COUNT - 1 times 820 | mov si,0 821 | sortbyscoreloopinner: 822 | ;TODO 823 | mov dl,[bx][si];get current index 824 | call getscorewithindex 825 | mov ax,dx 826 | mov dl,1[bx][si];get next index 827 | call getscorewithindex 828 | cmp ax,dx 829 | jl sortbyscoreexchange 830 | jmp sortbyscorekeep 831 | sortbyscoreexchange: 832 | mov dl,[bx][si] 833 | xchg dl,1[bx][si] 834 | mov [bx][si],dl 835 | sortbyscorekeep: 836 | inc si 837 | loop sortbyscoreloopinner 838 | pop cx 839 | loop sortbyscoreloopouter 840 | 841 | sortbyscoreexit: 842 | pop si 843 | pop bx 844 | pop cx 845 | pop ax 846 | ret 847 | sortbyscore endp 848 | 849 | getscorewithindex proc 850 | ;input DL: index of item 851 | ;return DX: score of item 852 | push bx 853 | push si 854 | mov bx,offset SCORE 855 | mov dh,0 856 | add dx,dx 857 | mov si,dx;SI = 2 * DL 858 | mov dx,[bx][si];Byte order 859 | xchg dl,dh 860 | pop si 861 | pop bx 862 | ret 863 | getscorewithindex endp 864 | 865 | initorder proc 866 | push cx 867 | push bx 868 | push si 869 | ;init order 870 | mov cx,0 871 | mov cl,COUNT 872 | 873 | mov bx,offset DISPLAYORDER 874 | mov si,0 875 | 876 | sortbyscoreloop: 877 | mov [bx][si],cl 878 | dec BYTE PTR [bx][si] 879 | inc si 880 | loop sortbyscoreloop 881 | pop si 882 | pop bx 883 | pop cx 884 | ret 885 | initorder endp 886 | 887 | code ends 888 | end start -------------------------------------------------------------------------------- /code/dsryhh/9.asm: -------------------------------------------------------------------------------- 1 | .model small 2 | .code 3 | start: 4 | mov ah,01h 5 | int 21h 6 | add al, 'A' - 'a' 7 | mov dl,al 8 | mov ah,02h 9 | int 21h 10 | jmp start 11 | end start -------------------------------------------------------------------------------- /code/non1996/1-(1).asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | ARRAY DW 23, 36, 2, 100, 32000, 54, 0 3 | ZERO DW 100 4 | DATA ENDS 5 | 6 | CODE SEGMENT 7 | ASSUME CS:CODE, DS:DATA 8 | START: 9 | MOV AX, DATA 10 | MOV DS, AX 11 | 12 | LEA BX, ARRAY 13 | MOV AX, 0 14 | MOV [BX+14], AX 15 | MOV AX, 4C00H 16 | INT 21H 17 | 18 | CODE ENDS 19 | END START 20 | -------------------------------------------------------------------------------- /code/non1996/1-(2).asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | ARRAY DW 23, 36, 2, 100, 32000, 54, 0 3 | ZERO DW 100 4 | DATA ENDS 5 | 6 | CODE SEGMENT 7 | ASSUME CS:CODE, DS:DATA 8 | START: 9 | MOV AX, DATA 10 | MOV DS, AX 11 | 12 | LEA BX, ARRAY + 12 13 | MOV AX, 0 14 | MOV [BX+2], AX 15 | MOV AX, 4C00H 16 | INT 21H 17 | 18 | CODE ENDS 19 | END START -------------------------------------------------------------------------------- /code/non1996/10.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/10.asm -------------------------------------------------------------------------------- /code/non1996/11.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | NUM DW 5698H 3 | DATA ENDS 4 | 5 | CODE SEGMENT 6 | ASSUME CS:CODE, DS:DATA 7 | START: 8 | MOV AX, DATA 9 | MOV DS, AX 10 | 11 | MOV AX, NUM 12 | 13 | MOV BL, AL 14 | AND BL, 0F0H 15 | MOV CL, 4 16 | SHR BL, CL 17 | 18 | MOV DL, AH 19 | AND DL, 0F0H 20 | MOV CL, 4 21 | SHR DL, CL 22 | 23 | MOV CL, AH 24 | AND CL, 0FH 25 | 26 | AND AL, 0FH 27 | 28 | MOV AH, 4CH 29 | INT 21H 30 | CODE ENDS 31 | END START -------------------------------------------------------------------------------- /code/non1996/12.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/12.asm -------------------------------------------------------------------------------- /code/non1996/13.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/13.asm -------------------------------------------------------------------------------- /code/non1996/14.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/14.asm -------------------------------------------------------------------------------- /code/non1996/15.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/15.asm -------------------------------------------------------------------------------- /code/non1996/16.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/16.asm -------------------------------------------------------------------------------- /code/non1996/17.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/17.asm -------------------------------------------------------------------------------- /code/non1996/18.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/18.asm -------------------------------------------------------------------------------- /code/non1996/19.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/19.asm -------------------------------------------------------------------------------- /code/non1996/2.asm: -------------------------------------------------------------------------------- 1 | DATASG SEGMENT 2 | FLD1B DB 'personal computer' 3 | FLD2B DB 32 4 | FLD3B DB 20H 5 | FLD4B DB 01011001B 6 | FLD5B DB 32654 7 | FLD6B DB 10 DUP(0) 8 | FLD7B DB 'PART1', 20 9 | DB 'PART2', 50 10 | DB 'PART3', 14 11 | FLD1W DW 0FFF0H 12 | FLD2W DW 01011001B 13 | FLD3W DW FLD7B 14 | FLD4W DW 5, 6, 7, 8, 9 15 | FLD5W DW 5 DUP(0) 16 | FLD6W DW FLD1W-FLD1B 17 | DARASG ENDS 18 | 19 | -------------------------------------------------------------------------------- /code/non1996/20.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/20.asm -------------------------------------------------------------------------------- /code/non1996/21.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/21.asm -------------------------------------------------------------------------------- /code/non1996/22.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/22.asm -------------------------------------------------------------------------------- /code/non1996/23.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | ; N EQU 100 3 | M DW 50 DUP(0), 50 DUP(1) 4 | MAX DW 0 5 | OFF DW 0 6 | DATA ENDS 7 | 8 | 9 | CODE SEGMENT 10 | ASSUME CS:CODE, DS:DATA 11 | START: 12 | MOV AX, DATA 13 | MOV DS, AX 14 | 15 | MOV SI, OFFSET M 16 | MOV DI, OFFSET MAX 17 | MOV AX, 0 18 | MOV BX, 0 19 | FIND_MAX: 20 | CMP [SI], AX 21 | JBE NOTLARGER 22 | MOV AX, [SI] 23 | MOV BX, SI 24 | NOTLARGER: 25 | ADD SI, 2 26 | 27 | CMP SI, DI 28 | JNZ FIND_MAX 29 | 30 | MOV MAX, AX 31 | MOV OFF, BX 32 | 33 | MOV AH, 4CH 34 | INT 21H 35 | CODE ENDS 36 | END START -------------------------------------------------------------------------------- /code/non1996/24.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/24.asm -------------------------------------------------------------------------------- /code/non1996/25.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/25.asm -------------------------------------------------------------------------------- /code/non1996/26.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/26.asm -------------------------------------------------------------------------------- /code/non1996/27.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | LENA EQU 15 3 | LENB EQU 20 4 | A DW LENA DUP(0) 5 | B DW LENB DUP(0) 6 | C DW LENB DUP(0) 7 | DATA ENDS 8 | 9 | STACK SEGMENT STACK 10 | DW 100H DUP(0) 11 | STACK ENDS 12 | 13 | CODE SEGMENT 14 | ASSUME CS:CODE, DS:DATA, SS:STACK 15 | START: 16 | MOV AX, DATA 17 | MOV DS, AX 18 | MOV AX, STACK 19 | MOV SS, AX 20 | 21 | MOV CX, LENA 22 | MOV SI, OFFSET A 23 | MOV DI, OFFSET B 24 | MOV BX, OFFSET C 25 | LOOP_1: 26 | PUSH CX 27 | 28 | MOV AX, [SI] 29 | MOV CX, LENB 30 | MOV DI, OFFSET B 31 | LOOP_2: 32 | CMP AX, [DI] 33 | JZ EQUAL 34 | ADD DI, 2 35 | LOOP LOOP_2 36 | JMP CONTINUE 37 | EQUAL: 38 | MOV [BX], AX 39 | ADD BX, 2 40 | CONTINUE: 41 | POP CX 42 | ADD SI, 2 43 | LOOP LOOP_1 44 | 45 | 46 | MOV AX, 4CH 47 | INT 21H 48 | CODE ENDS 49 | END START -------------------------------------------------------------------------------- /code/non1996/28.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | A DW 1 3 | B DW 0 4 | C DW 3 5 | D DW 0 6 | DATA ENDS 7 | 8 | CODE SEGMENT 9 | ASSUME CS:CODE, DS:DATA 10 | START: 11 | MOV AX, DATA 12 | MOV DS, AX 13 | 14 | CMP A, 0 15 | JZ CLEAR 16 | CMP B, 0 17 | JZ CLEAR 18 | CMP C, 0 19 | JZ CLEAR 20 | 21 | MOV AX, A 22 | ADD AX, B 23 | ADD AX, C 24 | MOV D, AX 25 | JMP FINISH 26 | 27 | CLEAR: 28 | MOV A, 0 29 | MOV B, 0 30 | MOV C, 0 31 | 32 | FINISH: 33 | MOV AH, 4CH 34 | INT 21H 35 | CODE ENDS 36 | END START -------------------------------------------------------------------------------- /code/non1996/29.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | ARRAY DW 1, 2, 1 3 | DATA ENDS 4 | 5 | CODE SEGMENT 6 | ASSUME CS:CODE, DS:DATA 7 | START: 8 | MOV AX, DATA 9 | MOV DS, AX 10 | 11 | MOV BX, 0 12 | MOV DX, 0 13 | MOV AX, ARRAY[BX] 14 | 15 | FIRST: 16 | CMP AX, ARRAY[BX + 2] 17 | JNZ SECOND 18 | INC DL 19 | 20 | SECOND: 21 | CMP AX, ARRAY[BX + 4] 22 | JNZ THIRD 23 | INC DL 24 | CMP DL, 2 25 | JZ COUT 26 | 27 | THIRD: 28 | MOV AX, ARRAY[BX + 2] 29 | CMP AX, ARRAY[BX + 4] 30 | JNZ COUT 31 | INC DL 32 | 33 | COUT: 34 | MOV AH, 02H 35 | ADD DL, '0' 36 | INT 21H 37 | 38 | 39 | MOV AH, 04CH 40 | INT 21H 41 | CODE ENDS 42 | END START -------------------------------------------------------------------------------- /code/non1996/3.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/3.asm -------------------------------------------------------------------------------- /code/non1996/30.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/30.asm -------------------------------------------------------------------------------- /code/non1996/31.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/31.asm -------------------------------------------------------------------------------- /code/non1996/34.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | NUM DW 10 3 | DATA ENDS 4 | 5 | CODE SEGMENT 6 | ASSUME CS:CODE, DS:DATA 7 | START: 8 | MOV AX, DATA 9 | MOV DS, AX 10 | 11 | MOV AX, NUM 12 | CALL SKIPLINES 13 | 14 | MOV AH, 4CH 15 | INT 21H 16 | 17 | SKIPLINES PROC 18 | PUSH AX 19 | PUSH CX 20 | PUSH DX 21 | MOV CX, AX 22 | 23 | MOV AH, 02H 24 | 25 | OUT: 26 | MOV DL, '-' 27 | INT 21H 28 | MOV DL, 0DH 29 | INT 21H 30 | MOV DL, 0AH 31 | INT 21H 32 | LOOP OUT 33 | 34 | 35 | 36 | POP DX 37 | POP CX 38 | POP AX 39 | RET 40 | SKIPLINES ENDP 41 | 42 | CODE ENDS 43 | END START -------------------------------------------------------------------------------- /code/non1996/35.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | SCORES DW 76, 69, 84, 90, 73, 88, 99, 63, 100, 80 3 | S6 DW 0 4 | S7 DW 0 5 | S8 DW 0 6 | S9 DW 0 7 | S10 DW 0 8 | DATA ENDS 9 | 10 | CODE SEGMENT 11 | ASSUME CS:CODE, DS:DATA 12 | START: 13 | MOV AX, DATA 14 | MOV DS, AX 15 | 16 | MOV SI, OFFSET SCORES 17 | MOV CX, 10 18 | COUNT: 19 | CMP [SI], 70 20 | JB SIX 21 | CMP [SI], 80 22 | JB SEVEN 23 | CMP [SI], 90 24 | JB EIGHT 25 | CMP [SI], 100 26 | JB NINE 27 | JMP TEN 28 | SIX: 29 | INC S6 30 | JMP NEXT 31 | SEVEN: 32 | INC S7 33 | JMP NEXT 34 | EIGHT: 35 | INC S8 36 | JMP NEXT 37 | NINE: 38 | INC S9 39 | JMP NEXT 40 | TEN: 41 | INC S10 42 | NEXT: 43 | ADD SI, 2 44 | LOOP COUNT 45 | 46 | FINISH: 47 | MOV AH, 4CH 48 | INT 21H 49 | CODE ENDS 50 | END START -------------------------------------------------------------------------------- /code/non1996/36.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/36.asm -------------------------------------------------------------------------------- /code/non1996/4.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/4.asm -------------------------------------------------------------------------------- /code/non1996/40.asm: -------------------------------------------------------------------------------- 1 | FINSUM MACRO PARA1, PARA2, SUM 2 | PUSH AX 3 | PUSH BX 4 | 5 | LOCAL LARGE 6 | LOCAL FINAL 7 | 8 | MOV AX, PARA1 9 | MOV BX, PARA2 10 | CMP AX, BX 11 | JG LARGE 12 | SHL BX, 1 13 | JMP FINAL 14 | LARGE: 15 | SHL AX, 1 16 | FINAL: 17 | ADD AX, BX 18 | MOV SUM, AX 19 | POP BX 20 | POP AX 21 | 22 | ENDM 23 | 24 | DATA SEGMENT 25 | X DW 5 26 | Y DW 10 27 | SUM DW 0 28 | DATA ENDS 29 | 30 | STACK SEGMENT STACK 31 | DW 10H DIP(0) 32 | STACK ENDS 33 | 34 | CODE SEGMENT 35 | ASSUME CS:CODE, DS:DATA 36 | START: 37 | MOV AX, DATA 38 | MOV DS, AX 39 | 40 | FINSUM X, Y, SUM 41 | 42 | MOV AH, 4CH 43 | INT 21H 44 | 45 | CODE ENDS 46 | END START -------------------------------------------------------------------------------- /code/non1996/5.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | LNAME DB 30 DUP(0) 3 | ADDRESS DB 30 DUP(0) 4 | CITY DB 15 DUP(0) 5 | CODE_LIST DB 1, 7, 8, 3, 2 6 | CODE_LENGTH DW $ - CODE_LIST;(3) 7 | DATA ENDS 8 | 9 | CODE SEGMENT 10 | ASSUME CS:CODE DS:DATA 11 | START: 12 | MOV AX, DATA 13 | MOV DS, AX 14 | 15 | ;LEA AX, LNAME 16 | MOV AX, DATA 17 | MOV DS, AX 18 | 19 | MOV AX, OFFSET LNAME ;(1) 20 | MOV SI, WORD PTR CODE_LIST ;(2) 21 | MOV BX, CODE_LENGTH 22 | 23 | MOV AH, 04CH 24 | INT 21H 25 | CODE ENDS 26 | END START -------------------------------------------------------------------------------- /code/non1996/6.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | DATA_LEN DB 5 3 | DATA_LIST DW -1, 0, 2, 5, 4, 0, 0, 0, 0, 0 4 | MAX DW 0 5 | MIN DW 00FFH 6 | 7 | DATA ENDS 8 | 9 | CODE SEGMENT 10 | ASSUME CS:CODE DS:DATA 11 | START: 12 | MOV AX, DATA 13 | MOV DS, AX 14 | 15 | 16 | MOV CL, DATA_LEN 17 | MOV BX, 0 18 | CMPLOOP: 19 | MOV AX, DATA_LIST + [BX] 20 | ADD BX, 2 21 | 22 | CMP AX, MAX 23 | JLE NOT_LARGER 24 | MOV MAX, AX 25 | NOT_LARGER: 26 | CMP AX, MIN 27 | JGE NOT_LESS 28 | MOV MIN, AX 29 | NOT_LESS: 30 | LOOP CMPLOOP 31 | 32 | MOV AX, MAX 33 | MOV AX, MIN 34 | CODE ENDS 35 | END START -------------------------------------------------------------------------------- /code/non1996/7.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | ORG 0E000H ;(1) 3 | 4 | ARRAY_BYTE LABEL BYTE 5 | ARRAY_WORD LABEL WORD 6 | ARRAY DB 100 DUP(0) ;(2) 7 | DATA ENDS 8 | 9 | STACK SEGMENT STACK 10 | ALIGN 16 11 | DW 100H DUP(0) 12 | STACK ENDS 13 | 14 | CODE SEGMENT 15 | ASSUME CS:CODE DS:DATA 16 | ORG 1000H 17 | START: 18 | MOV AX, DATA 19 | MOV DS, AX 20 | MOV AX, STACK 21 | MOV SS, AX 22 | 23 | MOV AX, 4CH 24 | INT 21H 25 | CODE ENDS 26 | END START -------------------------------------------------------------------------------- /code/non1996/8.asm: -------------------------------------------------------------------------------- 1 | C_SEG SEGMENT 2 | AUGEND DD 99251 3 | SUM DD ? 4 | C_SEG ENDS 5 | 6 | E_SEG SEGMENT 7 | ADDEND DD -15962 8 | E_SEG ENDS 9 | 10 | CODE SEGMENT 11 | ASSUME CS:CODE, DS:C_SEG, ES:E_SEG 12 | START: 13 | MOV AX, C_SEG 14 | MOV DS, AX 15 | MOV AX, E_SEG 16 | MOV ES, AX ;init segment register 17 | 18 | MOV AX, WORD PTR AUGEND 19 | MOV BX, WORD PTR ES:ADDEND 20 | ADD AX, BX 21 | MOV SUM, AX ;add low word of these num 22 | 23 | MOV AX, WORD PTR AUGEND + 2 24 | MOV BX, WORD PTR ES:ADDEND + 2 25 | ADC AX, BX 26 | MOV SUM + 2, AX ;add height word of these num 27 | 28 | MOV AL, 4CH 29 | INT 21H 30 | CODE ENDS 31 | END START 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /code/non1996/9.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Forec/assembly-exercise/1c4a44c60c0e93a1350ed4f887aeaf1414702a51/code/non1996/9.asm -------------------------------------------------------------------------------- /code/occupying/t1.asm: -------------------------------------------------------------------------------- 1 | .data 2 | ARRAY dw 23,36,2,100,32000,54,0 3 | ZERO dw ? 4 | .code 5 | start: 6 | mov ax,@data 7 | mov ds,ax 8 | mov bx,offset ARRAY 9 | mov [bx+14],0 10 | mov bx,offset ARRAY[12] 11 | mov [bx+2],0 12 | end start 13 | -------------------------------------------------------------------------------- /code/seagullbird/4_16.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | BUFF DW 0, 1, -1, 197 DUP (0) 3 | N1 DB ? 4 | N2 DB ? 5 | N3 DB ? 6 | DATA ENDS 7 | 8 | CODE SEGMENT 9 | ASSUME DS:DATA, CS:CODE 10 | START: 11 | MOV AX, DATA 12 | MOV DS, AX 13 | 14 | MOV BX, -2 15 | MOV AX, 0 16 | MOV DL, 0 17 | 18 | FOR: 19 | ADD BX, 2 20 | CMP BX, 402 21 | JZ FINAL 22 | MOV SI, [BX] 23 | CMP SI, WORD PTR 0 24 | JZ ADD_N2 25 | SHL SI, 1 26 | JC ADD_N3 27 | JNC ADD_N1 28 | 29 | ADD_N3: 30 | ADD DL, 1 31 | JMP FOR 32 | ADD_N2: 33 | ADD AH, 1 34 | JMP FOR 35 | ADD_N1: 36 | ADD AL, 1 37 | JMP FOR 38 | 39 | 40 | FINAL: 41 | MOV AL, N1 ;>0 1 42 | MOV AH, N2 ;=0 198 C6H 43 | MOV DL, N3 ;<0 1 44 | 45 | MOV AH, 4CH 46 | INT 21H 47 | CODE ENDS 48 | END START 49 | -------------------------------------------------------------------------------- /code/seagullbird/t10.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | BUFF DB 3 DUP (?), '$' 3 | DATA ENDS 4 | 5 | CODE SEGMENT 6 | ASSUME CS:CODE, DS:DATA 7 | START: 8 | MOV AX, DATA 9 | MOV DS, AX 10 | MOV AH, 08H 11 | INT 21H ; 读入一个字符(无回显) 12 | 13 | MOV BUFF[1], AL 14 | SUB AL, 1 15 | MOV BYTE PTR BUFF, AL 16 | ADD AL, 2 17 | MOV BUFF[2], AL 18 | 19 | XOR DX, DX 20 | MOV AH, 9 21 | INT 21H 22 | 23 | MOV AH, 4CH 24 | INT 21H 25 | CODE ENDS 26 | END START -------------------------------------------------------------------------------- /code/seagullbird/t11.asm: -------------------------------------------------------------------------------- 1 | TITLE seagullbird_t11 2 | 3 | .MODEL SMALL 4 | .DATA 5 | NUMBER DW 1234H 6 | .CODE 7 | MAIN PROC FAR 8 | ASSUME CS:_TEXT, DS:_DATA 9 | PUSH DS 10 | XOR AX, AX 11 | PUSH AX 12 | MOV AX, @DATA 13 | MOV DS, AX 14 | 15 | MOV AX, NUMBER 16 | MOV CL, 4 17 | MOV BX, AX 18 | AND AX, 0FH 19 | ROR BX, CL 20 | MOV SI, BX 21 | AND BX, 0FH 22 | ROR SI, CL 23 | MOV DX, SI 24 | AND SI, 0FH 25 | ROR DX, CL 26 | AND DX, 0FH 27 | MOV CX, SI 28 | RET 29 | MAIN ENDP 30 | END MAIN -------------------------------------------------------------------------------- /code/seagullbird/t13.asm: -------------------------------------------------------------------------------- 1 | TITLE seagullbird_t13 2 | .MODEL SMALL 3 | .DATA 4 | MESSAGE DB 'PLEASE INPUT A NUMBER TO RING: $' 5 | .CODE 6 | MAIN PROC FAR 7 | ASSUME CS:_TEXT, DS:_DATA 8 | PUSH DS 9 | XOR AX, AX 10 | PUSH AX 11 | MOV AX, @DATA 12 | MOV DS, AX 13 | PRINT: 14 | MOV AH, 09 15 | LEA DX, MESSAGE 16 | INT 21H 17 | 18 | MOV AH, 01H 19 | INT 21H 20 | CMP AL, 30H 21 | JL PRINT 22 | CMP AL, 39H 23 | JG PRINT 24 | 25 | SUB AL, 30H 26 | MOV CL, AL 27 | MOV DL, 07H 28 | MOV AH, 02H 29 | LP: 30 | INT 21H 31 | LOOP LP 32 | 33 | RET 34 | MAIN ENDP 35 | END MAIN -------------------------------------------------------------------------------- /code/seagullbird/t15.asm: -------------------------------------------------------------------------------- 1 | TITLE seagullbird_t15 2 | .MODEL SMALL 3 | .DATA 4 | ARRAY DW 8, 6, 4, 2, -2 5 | .CODE 6 | MAIN PROC FAR 7 | ASSUME CS:_TEXT, DS:_DATA 8 | PUSH DS 9 | XOR AX, AX 10 | PUSH AX 11 | MOV AX, @DATA 12 | MOV DS, AX 13 | 14 | MOV CL, 5 15 | LEA BX, ARRAY 16 | MOV AX, [BX] 17 | LP: 18 | CMP CL, 0 19 | JZ QUIT 20 | DEC CL 21 | MOV DX, [BX] 22 | MOV SI, DX 23 | RCR DX, 1 24 | JNC JUDGE ; EVEN 25 | ADD BX, 2 26 | JMP LP 27 | 28 | JUDGE: 29 | CMP SI, AX 30 | JL NEW_MIN 31 | ADD BX, 2 32 | JMP LP 33 | 34 | NEW_MIN: 35 | MOV AX, SI 36 | ADD BX, 2 37 | JMP LP 38 | 39 | QUIT: 40 | RET 41 | MAIN ENDP 42 | END MAIN -------------------------------------------------------------------------------- /code/seagullbird/t17.asm: -------------------------------------------------------------------------------- 1 | TITLE seagullbird_t17 2 | .MODEL SMALL 3 | .DATA 4 | BUFF DB 4 DUP (0) 5 | .CODE 6 | MAIN PROC FAR 7 | ASSUME CS:_TEXT, DS:_DATA 8 | PUSH DS 9 | XOR AX, AX 10 | PUSH AX 11 | MOV AX, @DATA 12 | MOV DS, AX 13 | 14 | MOV SI, 0 15 | MOV AH, 01H 16 | 17 | INPUT: 18 | CMP SI, 4 19 | JGE OUTPUT 20 | INT 21H 21 | CMP AL, 30H ; <0 22 | JL FINAL 23 | CMP AL, 66H ; >f 24 | JG FINAL 25 | CMP AL, 39H ; <=9 26 | JLE NUMBER 27 | CMP AL, 41H ; 9 40 | JG PLUS 41 | 42 | NEXT: 43 | INC BX 44 | JMP FOR 45 | 46 | PLUS: 47 | INC CL 48 | JMP NEXT 49 | 50 | OUTPUT: 51 | MOV AH, 02H 52 | MOV DL, 0DH 53 | INT 21H 54 | MOV DL, 0AH 55 | INT 21H 56 | 57 | XOR AX, AX 58 | MOV AL, CL ; SAVE RESULT TO AX 59 | MOV CL, 10 60 | DIV CL 61 | MOV CH, AH ; REMAINDER 62 | MOV CL, AL ; QUOTIENT 63 | 64 | CMP CL, 0 ; QUOTIENT IS 0 65 | JZ REMAINDER 66 | MOV DL, 30H 67 | ADD DL, CL 68 | MOV AH, 02H 69 | INT 21H 70 | 71 | REMAINDER: 72 | MOV DL, 30H 73 | ADD DL, CH 74 | MOV AH, 02H 75 | INT 21H 76 | 77 | 78 | MOV DL, 0DH 79 | INT 21H 80 | MOV DL, 0AH 81 | INT 21H 82 | JMP INPUT 83 | 84 | WRONG: 85 | MOV AH, 09H 86 | LEA DX, WRONG_MSG 87 | INT 21H 88 | JMP INPUT 89 | 90 | FINAL: 91 | RET 92 | MAIN ENDP 93 | END MAIN -------------------------------------------------------------------------------- /code/seagullbird/t21.asm: -------------------------------------------------------------------------------- 1 | TITLE seagullbird_t21 2 | .MODEL SMALL 3 | .DATA 4 | STRING DB 100 DUP (?) 5 | .CODE 6 | MAIN PROC FAR 7 | ASSUME CS:_TEXT, DS:_DATA 8 | PUSH DS 9 | XOR AX, AX 10 | PUSH AX 11 | MOV AX, @DATA 12 | MOV DS, AX 13 | 14 | XOR CL, CL 15 | XOR BX, BX 16 | FOR: 17 | CMP BX, 99 18 | JG FINAL 19 | CMP BYTE PTR [BX], 30H 20 | JL PASS 21 | CMP BYTE PTR [BX], 39H 22 | JG PASS 23 | OR CL, 00010000B ; SET 5TH TO 1 24 | JMP FINAL 25 | PASS: 26 | INC BX 27 | JMP FOR 28 | 29 | FINAL: 30 | RET 31 | MAIN ENDP 32 | END MAIN -------------------------------------------------------------------------------- /code/seagullbird/t23.asm: -------------------------------------------------------------------------------- 1 | TITLE seagullbird_t23 2 | .MODEL SMALL 3 | .DATA 4 | M DW 10 DUP (0), 1, -2, 3, -4, 5, -6, 7, -8, 9, -10 5 | N EQU $ - M 6 | .CODE 7 | MAIN PROC FAR 8 | ASSUME CS:_TEXT, DS:_DATA 9 | PUSH DS 10 | XOR AX, AX 11 | PUSH AX 12 | MOV AX, @DATA 13 | MOV DS, AX 14 | 15 | XOR BX, BX 16 | XOR AX, AX ; MAX NUMBER 17 | 18 | FOR: 19 | CMP BX, N 20 | JGE SAVE 21 | MOV CX, [BX] 22 | CMP CX, 0 23 | JGE POSITIVE 24 | NEG CX 25 | POSITIVE: 26 | CMP CX, AX 27 | JLE NEXT 28 | MOV AX, CX 29 | NEXT: 30 | ADD BX, 2 31 | JMP FOR 32 | 33 | SAVE: 34 | ADD BX, N 35 | MOV [BX], AX 36 | MOV [BX+2], BX 37 | 38 | RET 39 | MAIN ENDP 40 | END MAIN -------------------------------------------------------------------------------- /code/seagullbird/t25.asm: -------------------------------------------------------------------------------- 1 | TITLE seagullbird_t25 2 | .MODEL SMALL 3 | .DATA 4 | MEM DB 4 DUP (?), 0DH, '$' 5 | OUTPUT_INFO DB 'THE NUMBER IN AX IS 2A49H, AND THE OUTPUT IS: $' 6 | .CODE 7 | MAIN PROC FAR 8 | ASSUME CS:_TEXT, DS:_DATA 9 | PUSH DS 10 | XOR AX, AX 11 | PUSH AX 12 | MOV AX, @DATA 13 | MOV DS, AX 14 | 15 | MOV AX, 2A49H 16 | LEA BX, MEM 17 | MOV CL, 4 18 | MOV SI, 4 19 | 20 | FOR: 21 | CMP SI, 0 22 | JZ OUTPUT 23 | MOV DX, AX 24 | AND DX, 000FH 25 | CMP DX, 9 26 | JG LETTER 27 | ADD DX, 30H 28 | JMP NEXT 29 | NEXT: 30 | MOV [BX], DX 31 | INC BX 32 | DEC SI 33 | ROR AX, CL 34 | JMP FOR 35 | 36 | LETTER: 37 | ADD DX, 37H 38 | JMP NEXT 39 | 40 | OUTPUT: 41 | MOV AH, 9 42 | LEA DX, OUTPUT_INFO 43 | INT 21H 44 | LEA DX, MEM 45 | INT 21H 46 | 47 | RET 48 | MAIN ENDP 49 | END MAIN -------------------------------------------------------------------------------- /code/seagullbird/t27.asm: -------------------------------------------------------------------------------- 1 | TITLE seagullbird_t27 2 | .MODEL SMALL 3 | .DATA 4 | A DB 15 DUP (1) 5 | B DB 20 DUP (1) 6 | C DB 15 DUP (0) 7 | .CODE 8 | MAIN PROC FAR 9 | ASSUME CS:_TEXT, DS:_DATA 10 | PUSH DS 11 | XOR AX, AX 12 | PUSH AX 13 | MOV AX, @DATA 14 | MOV DS, AX 15 | 16 | LEA BX, A 17 | LEA BP, C 18 | 19 | FOR_1: 20 | CMP BX, LENGTH A 21 | JGE FINAL 22 | LEA SI, B 23 | MOV AX, [BX] 24 | FOR_2: 25 | CMP SI, LENGTH B 26 | JGE END_FOR_2 27 | CMP AX, DS:[SI] 28 | JZ CONTINUE 29 | INC SI 30 | JMP FOR_2 31 | 32 | CONTINUE: 33 | MOV DS:[BP], AX 34 | INC BP 35 | JMP END_FOR_2 36 | 37 | END_FOR_2: 38 | INC BX 39 | JMP FOR_1 40 | 41 | FINAL: 42 | RET 43 | MAIN ENDP 44 | END MAIN -------------------------------------------------------------------------------- /code/seagullbird/t29.asm: -------------------------------------------------------------------------------- 1 | TITLE seagullbird_t29 2 | .MODEL SMALL 3 | .DATA 4 | ARRAY DW 1, 1, 1 5 | .CODE 6 | MAIN PROC FAR 7 | ASSUME CS:_TEXT, DS:_DATA 8 | PUSH DS 9 | XOR AX, AX 10 | PUSH AX 11 | MOV AX, @DATA 12 | MOV DS, AX 13 | 14 | MOV BX, 0 15 | MOV DX, 0 16 | MOV AX, ARRAY[BX] 17 | 18 | FIRST: 19 | CMP AX, ARRAY[BX + 2] 20 | JNZ SECOND 21 | INC DL 22 | 23 | SECOND: 24 | CMP AX, ARRAY[BX + 4] 25 | JNZ THIRD 26 | INC DL 27 | CMP DL, 2 28 | JZ COUT 29 | 30 | THIRD: 31 | MOV AX, ARRAY[BX + 2] 32 | CMP AX, ARRAY[BX + 4] 33 | JNZ COUT 34 | INC DL 35 | 36 | COUT: 37 | MOV AH, 02H 38 | ADD DL, '0' 39 | INT 21H 40 | 41 | 42 | RET 43 | MAIN ENDP 44 | END MAIN -------------------------------------------------------------------------------- /code/seagullbird/t31.asm: -------------------------------------------------------------------------------- 1 | TITLE seagullbird_t31 2 | .MODEL SMALL 3 | .DATA 4 | A DB 3 5 | B DB 3 6 | .CODE 7 | MAIN PROC FAR 8 | ASSUME CS:_TEXT, DS:_DATA 9 | PUSH DS 10 | XOR AX, AX 11 | PUSH AX 12 | MOV AX, @DATA 13 | MOV DS, AX 14 | 15 | MOV AL, 01H 16 | MOV AH, AL 17 | LEA BX, A 18 | AND AL, [BX] ; AL 存 A 的最低位 19 | AND AH, [BX+1] ; AH 存 B 的最低位 20 | 21 | ADD AL, AH 22 | 23 | CMP AL, 2 24 | JZ TWO_ODDS 25 | CMP AL, 1 26 | JZ ONE_ODD_ONE_EVEN 27 | CMP AL, 0 28 | JZ TWO_EVENS 29 | 30 | ONE_ODD_ONE_EVEN: 31 | CMP AH, 0 ; 如果 B 为偶数,则 A 一定为奇数,不作改变 32 | JZ FINAL 33 | MOV AL, [BX] 34 | MOV AH, [BX+1] 35 | MOV [BX+1], AL 36 | MOV [BX], AH 37 | JMP FINAL 38 | 39 | TWO_ODDS: 40 | MOV AL, [BX] 41 | INC AL 42 | MOV [BX], AL 43 | MOV AL, [BX+1] 44 | INC AL 45 | MOV [BX+1], AL 46 | JMP FINAL 47 | 48 | TWO_EVENS: 49 | JMP FINAL 50 | 51 | FINAL: 52 | RET 53 | MAIN ENDP 54 | END MAIN -------------------------------------------------------------------------------- /code/seagullbird/t6.asm: -------------------------------------------------------------------------------- 1 | DATA_SEG SEGMENT 2 | FIVE DB 5D 3 | DATA_LIST DW -1, 0, 2, 5, 4, 5 DUP (?) 4 | MAX DW ? 5 | MIN DW ? 6 | DATA_SEG ENDS 7 | CODE SEGMENT 8 | MAIN PROC FAR 9 | ASSUME CS:CODE, DS:DATA_SEG 10 | MOV AX, DATA_SEG 11 | MOV DS, AX 12 | MOV DX, DATA_LIST[0] 13 | MOV MAX, DX 14 | MOV MIN, DX 15 | MOV SI, 8 16 | LP: MOV DX, DATA_LIST[SI] 17 | CMP MAX, DX 18 | JL CHANGE_MAX 19 | JMP JUDGE_MIN 20 | JUDGE_MIN: MOV DX, DATA_LIST[SI] 21 | CMP MIN, DX 22 | JG CHANGE_MIN 23 | JMP NEXT 24 | CHANGE_MAX: MOV DX, DATA_LIST[SI] 25 | MOV MAX, DX 26 | JMP NEXT 27 | CHANGE_MIN: MOV DX, DATA_LIST[SI] 28 | MOV MIN, DX 29 | JMP NEXT 30 | NEXT: SUB SI, 2 31 | CMP SI, 0 32 | JGE LP 33 | MOV BX, MAX 34 | MOV DX, MIN 35 | MOV AX, 4C00H 36 | INT 21H 37 | MAIN ENDP 38 | CODE ENDS 39 | END MAIN -------------------------------------------------------------------------------- /code/seagullbird/t7.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT AT 0E000H ; 数据段的位置从 0E000H 开始 2 | ARRAY_B LABEL BYTE ; 不同类型同一起始地址 3 | ARRAY_W DW 50 DUP (?) 4 | DATA ENDS 5 | 6 | STACK SEGMENT PARA STACK 'STACK' 7 | TOP LABEL BYTE 8 | BASE DB 100 DUP (?) 9 | STACK ENDS 10 | 11 | CODE SEGMENT 12 | ASSUME CS:CODE, DS:DATA, SS:STACK ; 段指定 13 | ORG 1000H ; 指定主程序从 1000H 开始 14 | START: 15 | MOV AX, DATA 16 | MOV DS, AX 17 | ; your code here 18 | MOV AX, 4C00H 19 | INT 21H 20 | 21 | CODE ENDS 22 | END START 23 | -------------------------------------------------------------------------------- /code/seagullbird/t8.asm: -------------------------------------------------------------------------------- 1 | D_SEG SEGMENT 2 | AUGEND DD 99251 3 | SUM DD ? 4 | D_SEG ENDS 5 | 6 | E_SEG SEGMENT 7 | ADDEND DD -15962 8 | E_SEG ENDS 9 | 10 | CODE SEGMENT 11 | ASSUME CS:CODE, DS:D_SEG, ES:E_SEG 12 | START: 13 | MOV AX, D_SEG 14 | MOV DS, AX 15 | MOV AX, E_SEG 16 | MOV ES, AX 17 | MOV AX, WORD PTR AUGEND 18 | MOV DX, WORD PTR ADDEND 19 | ADD AX, DX 20 | MOV BX, WORD PTR AUGEND[2] 21 | MOV DX, WORD PTR ADDEND[2] 22 | ADC BX, DX 23 | MOV WORD PTR SUM, AX 24 | MOV WORD PTR SUM[2], BX 25 | 26 | MOV AX, 4C00H 27 | INT 21H 28 | CODE ENDS 29 | END START 30 | 31 | ; SUM IN DS:0004, 59 45 01 00 -------------------------------------------------------------------------------- /code/seagullbird/t9.asm: -------------------------------------------------------------------------------- 1 | DATA SEGMENT 2 | BUFF DB 80, ?, 80 DUP (?) 3 | DATA ENDS 4 | 5 | CODE SEGMENT 6 | ASSUME CS:CODE, DS:DATA 7 | START: 8 | MOV AX, DATA 9 | MOV DS, AX 10 | 11 | LEA DX, BUFF 12 | MOV BX, DX ; 将输入字符的起始地址转存到 BX 13 | MOV AH, 10 14 | INT 21H ; 从键盘读入一个字节字符串(没有加容错,必须是小写字母),DS:DX=存放输入字符的起始地址 15 | 16 | MOV BX, 2 17 | FOR: 18 | MOV AL, [BX] ; 取一个字节字符 19 | CMP AL, 13 ; 判断是否是回车符 20 | JZ FINAL 21 | SUB AL, 32 22 | MOV [BX], AL 23 | ADD BX, 1 24 | ADD DX, 1 25 | JMP FOR 26 | 27 | 28 | FINAL: 29 | MOV BX, WORD PTR BUFF[1] 30 | MOV BH, 0 31 | ADD BX, 2 32 | MOV BUFF[BX], 36 ; 在末尾放入'$' 33 | MOV DX, 2 34 | MOV AH, 9 35 | INT 21H 36 | 37 | MOV AH, 4CH 38 | INT 21H 39 | CODE ENDS 40 | END START --------------------------------------------------------------------------------