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

实验任务一

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

不能。用add指令对si,di操作可能会影响CF位,进而引起进位,导致原本计算中的adc计算错误。

在debug中调试,数据段中做128位加之前

 

 

 做128位加之后

 

 

 

 

实验任务二

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。
② 汇编指令代码line20-22,实现的功能是?

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

打印字符串

 

 

实验三

task3.asm源码

assume cs:code, ds:data
data segment
	x dw 91, 792, 8536, 65521, 2021
	len equ $ - x
data ends

code segment
start:  
	mov ax, data
	mov ds, ax
	mov si, offset x
	mov cx, 5
	
s:	mov ax, [si]
	push cx
	call printNumber
	call printSpace
	add si, 2
	pop cx
	loop s
	
	mov ah, 4ch
	int 21h
	
printNumber:   
	mov dx, 0
	mov cx, 0
s1:	mov bx, 10
	div bx
	push dx
	mov dx, 0
	inc cx
	add ax, 0
	jnz s1
	
s2:	pop dx
	mov ah, 2
	add dl, '0'
	int 21h
	loop s2
	ret
	
printSpace:
	mov ah, 2
	mov dl, ' '
	int 21h
	ret

code ends
end start

  运行结果:

 

 

 

 

实验任务四

task4.asm源码

assume cs:code, ds:data
data segment
	str db "assembly language, it's not difficult but tedious"
	len equ $ - str
data ends

code segment
start:  
	mov ax, data
	mov ds, ax
	mov si, offset str
	mov cx, len
	
s:	call strupr
	
	mov ah, 4ch
	int 21h
	
strupr:   
s1:	mov al, [si]
	cmp al, 'a'
	jb s2
	cmp al, 'z'
	ja s2
	sub byte ptr [si], 32
s2: inc si
	loop s1

code end
end start

  调试结果:

 

 

 

实验任务五

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,则显示str1中的内容,否则显示str2中的内容。

 

 

 

实验任务六

当一个系统运行错误时会产生中断,软中断由程序执行。发生中断后,会查询软中断的向量表,获得对应的中断代码段地址和偏移量,执行对应位置的代码。

 

posted @ 2021-12-13 18:33  ZCLee  阅读(28)  评论(1编辑  收藏  举报