实验4 8086标志寄存器及中断

实验任务1

task1.asm源码

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

line31~line34的4条inc指令,能否替换成如下代码?你的结论的依据/理由是什么?

add si, 2
add di, 2

答:我认为不能替换,inc命令不改变标志位CF,而add命令改变标志位CF。

加之前:

加之后:

 

 

 

实验任务2

task2.asm源码:

assume cs:code, ds:data
data segment
str 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

运行测试截图:

 

① 汇编指令代码line11-18,实现的功能是?

 答:从键盘上读入一串字符,当遇到‘#’时停止读入,并且跳转到next程序段。

(mov ah, 1 int 21h  1号功能为:从键盘上输入一个字符,将其对应字符的ASCII码送入AL中,并在屏幕上显示该字符。cmp al, '#'  je next功能为:如果al中的数据为‘#’,那么就要跳转到next代码段

 

② 汇编指令代码line20-22,实现的功能是?

答:输出换行符。(mov ah, 2 mov dl, 0ah 这里ah为2,2号功能为字符输出,这里的意思是将dl中的数据在屏幕上输出,oah ASCLL码对应的符号为换行符

 

 ③ 汇编指令代码line24-30,实现的功能是?

答:将刚刚输入的字符串输出在屏幕上。

实验任务3

task3.asm源码

 

assume cs:code, ds:data
data segment
   x dw 91
   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 si, 0
mov bl, 10
mov cx, len

s: 
   mov dl, [si]
   call printNumber
   call PrintSpace
   inc si
loop s

mov ah, 4ch
int 21h

printNumber:
   s2:
      mov al, dl  ;al存商
      div bl
      push ax
      cmp al, 0
      je s3
      mov dl, al
      loop s2
   s3:
      pop dx
      xchg dh, dl
      or dl,30H  ;输出十位dl
      mov ah,2
      int 21h
      loop s3
   ret

PrintSpace:
   mov ah, 2
   mov dl, ' '
   int 21h
   ret

code ends
end start

运行测试截图

 

 

实验任务4

task4.asm源码

 

在debug中调试截图( call strupr 调用之前,数据段的值,以及,调用之后,数据段的值) add si, 2 add di, 2 1 2 5.

 

实验任务5

task5.asm源码

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,以及输入其他字符,运行结果截图)

 

 

程序的功能是:键盘输入7时,显示“yes”,输入其他字符时,显示“no”。

 

实验任务6

通过此项实现任务,你对中断、软中断实现机制的理解 自己选一个未被使用的中断码,实现一个中断例程,并调用测试。

源码

task6_1.asm源码:


assume cs:code code segment start: ; 42 interrupt routine install code mov ax, cs mov ds, ax mov si, offset int42 ; set ds:si mov ax, 0 mov es, ax mov di, 200h ; set es:di mov cx, offset int42_end - offset int42 cld rep movsb ; set IVT(Interrupt Vector Table) mov ax, 0 mov es, ax mov word ptr es:[42*4], 200h mov word ptr es:[42*4+2], 0 mov ah, 4ch int 21h int42: jmp short int42_start str db "welcome to 2049!" len equ $ - str ; display string "welcome to 2049!" int42_start: mov ax, cs mov ds, ax mov si, 202h mov ax, 0b800h mov es, ax mov di, 24*160 + 32*2 mov cx, len s: mov al, [si] mov es:[di], al mov byte ptr es:[di+1], 2 inc si add di, 2 loop s iret int42_end: nop code ends end start

task6_2.asm源码:


assume cs:code code segment start: int 42 mov ah, 4ch int 21h code ends end start

 

运行测试截图

 

posted @ 2021-12-17 00:36  南斋  阅读(37)  评论(0编辑  收藏  举报