实验4 8086标志寄存器及中断
实验任务1
源代码
assume cs:code, ds:data data segment x dw 1020h, 2240h, 9522h, 5060h, 3359h, 6652h, 2530h, 7031h y dw 3210h, 5510h, 6066h, 5121h, 8801h, 6210h, 7119h, 3912h data ends code segment start: mov ax, data mov ds, ax mov si, offset x mov di, offset y call add128 mov ah, 4ch int 21h add128: push ax push cx push si push di sub ax, ax mov cx, 8 s: mov ax, [si] adc ax, [di] mov [si], ax inc si inc si inc di inc di loop s pop di pop si pop cx pop ax ret code ends end start
不能替换,因为add会改变CF的值,使进位出错。
运行结果


实验任务2
源代码
assume cs:code, ds:data data segment db 80 dup(?) data ends code segment start: mov ax, data mov ds, ax mov si, 0 s1: mov ah, 1 int 21h mov [si], al cmp al, '#' je next inc si jmp s1 next: mov ah, 2 mov dl, 0ah int 21h mov cx, si mov si, 0 s2: mov ah, 2 mov dl, [si] int 21h inc si loop s2 mov ah, 4ch int 21h code ends end start
运行结果
相关知识
|
01 |
键盘输入并回显 |
AL=输入字符 |
|
02 |
显示输出 |
DL=输出字符 |
(1)输入字符到al,存入[si],和#比较,相等进入next,不相等继续循环。
(2)输出换行符。
(3)输出字符si次,由于最后一次si没有增加,最后的#不输出。
实验任务3
源代码
assume ds:data, cs:code, ss:stack data segment x dw 91, 792, 8536, 65535, 2021, 0 len equ $ - x data ends stack segment db 16 dup(0) stack ends code segment start: mov ax, data mov ds, ax mov ax, stack mov ss, ax mov sp, 16 mov di, offset x mov cx, len/2 ; len/2处理数量 foreach: mov ax, word ptr ds:[di] push cx call printNumber pop cx mov ah, 2 mov dl, 20h int 21h add di, 2 loop foreach mov ah, 4ch int 21h ;ax:输入数字 printNumber: mov bx, 0 num: mov dx, 0 mov bp, 10 div bp;dxax/bp得ax商 dx余数 push dx;余数 即末位 inc bx;存储数字位数 cmp ax, 0 je next jmp num next: mov cx, bx;数字位数 print: pop dx add dl, 30h;转成为字符 mov ah, 2 int 21h loop print ret code ends end start
运行结果
实验任务4
源代码
data segment str1 db "assembly language, it's not difficult but tedious" len equ $ - str1 data ends stack segment db 16 dup(0) stack ends code segment assume cs:code,ds:data,ss:stack start: mov ax,data mov ds,ax mov si,offset str1 mov cx,len call strupr mov ah,4ch int 21h strupr: s: mov al,ds:[si] cmp al,'a' jb next cmp al,'z' ja next and al,0dfh;1101 1111 mov ds:[si],al next: inc si loop s ret code ends end start
运行结果

实验任务5
源代码
assume cs:code, ds:data data segment str1 db "yes", '$' str2 db "no", '$' data ends code segment start: mov ax, data mov ds, ax mov ah, 1 int 21h mov ah, 2 mov bh, 0 mov dh, 24 mov dl, 70 int 10h cmp al, '7' je s1 mov ah, 9 mov dx, offset str2 int 21h jmp over s1: mov ah, 9 mov dx, offset str1 int 21h over: mov ah, 4ch int 21h code ends end start
运行结果
输入7
输入8
程序的功能:在指定位置,输入7显示yes,输入7以外的显示no,实现了类似密码的功能。
实验任务6
运行结果
原理
文件1:先安装需要调用的中断处理程序,然后设置中断向量表。
文件2:执行int指令,产生中断信息,cpu收到后引发中断过程,然后转而执行中断处理程序。
浙公网安备 33010602011771号