实验四

1. 实验任务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

 

回答问题

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

 

不能替换,因为add 影响进位标志而inc 不影响进位标志。

 

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

 

 

 

2. 实验任务2

 

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

 

 

 

回答问题

运行程序,从键盘上输入一串字符,以#结束(比如,输入George Orwell, 1984#),观察结果。结合运行结果,理解代码并回答问题:

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

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

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

 

1.line11-line18的作用是判断输入字符是否等于#,若等于,则跳转到next,若不相等,则一直循环s1,将输入存储到数据段ds中。

2.line20-22的作用是输出换行字符

3.line24-30的作用是打印输入的字符。

 

 

 

3. 实验任务3

 

assume cs:code, ds:data, ss:stack

data segment

    x dw 91, 792, 8536, 65521, 2021

    len equ $ - x

data ends

 

stack segment

    db 16 dup(?)

stack ends

 

code segment

start:

    mov ax, data

    mov ds, ax

    mov ax, stack

    mov ss, ax

    mov sp, 16

    mov si, offset x

    mov cx, len/2

    mov bx,10

    call print

 

    mov ah,4ch

    int 21h

 

print:

    mov ax, [si]

 s1:mov dx,0

    div bx

    push dx;存余数dx

    cmp ax,0ah;判断商大于等于10

    jnb s1

 

printNumber:

;打印数字

    push ax

 s2:pop dx

    or dx,30h

    mov ah,2

    int 21h

    cmp sp,0eh

    jne s2

 

printSpace:

;打印空格

    mov dl, ' '

    int 21h

 

    inc si

    inc si

    loop print

    ret

 

code ends

end start

 

 

 

4. 实验任务4

 

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

    call strup

 

    mov ah,4ch

    int 21h

 

strup:

    mov al,[si]

    cmp al,61h

    jb s

    cmp al,7ah

    ja s

    sub al,20h

    mov [si],al

 s: inc si

    loop strup

    ret

 

code ends

end start

 

在debug中调试截图( call strupr 调用之前,数据段的值,以及,调用之后,数据段的值)

 

 

5. 实验任务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’,如果是打印yes,如果不是则打印no。

 

6. 实验任务6

中断是指CPU因为收到了某个突发信息不再接着向下顺序执行指令,而是转去处理这个特殊信息,执行相应的中断程序。

软中断类似于call和ret的执行,实现机制:

1、根据中断信息获取中断类型码

2、标志寄存器入栈,令TF=0、IF=0

3、CS、IP依次入栈

4、根据中断类型码(N)在中断向量表中找到相应中断处理程序的入口地址

(CS=4N+2,IP=4N)

5、执行中断处理程序

6、返回继续顺序执行

posted @ 2021-12-17 09:21  Fanerr  阅读(37)  评论(0编辑  收藏  举报