实验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

回答问题

  不能替换 add指令会影响进位寄存器的值 进而影响adc加法的正确

在debug中调试,观察数据段中做128位加之前和加之后,数据段的值的变化。给出调试观察截 图。

 

 

任务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,实现的功能是?

  比较键盘输入的字符与#的ASCII码值 相等则跳转到next 不相等则继续输入

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

  屏幕输出0a

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

  输入的字符串再输出到屏幕上

任务3

task3.asm源码

 

assume cs:code,ds:data

data segment
    x dw 91, 792, 8536, 65521, 2021
    len equ $ - x
data ends
    
stack segment 
    db 64 dup(0)
stack ends

code segment
start:
    mov ax,data
    mov ds,ax
    mov ax,stack
    mov ss,ax
    mov sp,40h

    mov cx,len/2
    mov bx,0

s1:
    mov ax,ds:[bx]
    push bx
    push cx
    call printNumber
    call printSpace
    pop cx
    pop bx
    inc bx
    inc bx
    loop s1

    mov ah,4ch
    int 21h

printNumber:

    mov cx,0
    mov bx,10

s2:
    mov dx,0
    div bx
    push dx
    inc cx
    cmp ax,0
    jne s2

s3:
    mov ah,2
    pop dx
    or dl,30h
    int 21h
    loop s3
    ret

printSpace:
    mov ah,2
    mov dl,20h
    int 21h
    ret

code ends
end start

 

 任务4

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 cx,len
    mov bx,0
    mov ax,0
strupr:
    cmp byte ptr ds:[bx],61h
    jb s1
    cmp byte ptr ds:[bx],7ah
    ja s1
    mov al,ds:[bx]
    and al,11011111B
    mov ds:[bx],al
s1:
    inc bx
    loop strupr

    mov ah,4ch
    int 21h
code ends
end start

 

 任务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 ; 设置光标位置在第24行
mov dl, 70 ; 设置光标位置在第70列
int 10h ; 设置光标位置
cmp al, '7'
je s1
mov ah, 9
mov dx, offset str2
int 21h ; 显示标号str2处的字符串
jmp over
s1: mov ah, 9
mov dx, offset str1
int 21h ; 显示标号str2处的字符串
over:
mov ah, 4ch
int 21h
code ends
end start

 

 该程序功能是如果输入字符为7则在第24行70列位置显示yes 如果输入不为7则显示no

任务6

task6.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
assume cs:code
code segment
start:
int 42 ; 调用自己实现的42号软中断
mov ah, 4ch
int 21h
code ends
end start

 

posted @ 2021-12-16 15:10  08091  阅读(9)  评论(3编辑  收藏  举报