ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2021-12-12 16:04:54  阅读:147  来源: 互联网

标签:8086 code 中断 mov int si 寄存器 ax data


实验任务1

任务点1

验证add对ZF和CF的影响

可以看到add对ZF和CF都造成了影响

验证inc对ZF和CF的影响

 inc只对ZF造成影响

任务点2

源代码:

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

问题1

不能够将上述代码替换,如果某个字的相加产生了进位,那么计算结果将产生错误。 

 

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

 

 ①汇编指令代码line11-18,实现每次从键盘读取一个字符,并比较是否等于“#”,若是执行跳转到标记next处。   ② 汇编指令代码line20-22,实现的功能是输出换行符,换行符的十六进制ASCII码值就是0AH。   ③ 汇编指令代码line24-30,实现的功能是将数据段中长度为si的字符串输出。

实验任务3

源代码

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

stack segment
        db 16 dup(0)
stack ends

code segment
start:
        mov ax, data
        mov ds, ax

        mov cx, 5
        mov si, offset x
s:      mov ax, ds:[si]
        call printNumber
        call printSpace
        inc si
        inc si
        loop s

        mov ah, 4ch
        int 21h

printNumber:
        mov bx, 0AH     ;除数
        mov dx, 0       ;高位置为0,记录余数
        mov di, 0
        push cx
 s1:    div bx
        push dx         ;余数入栈
        inc di
        mov dx, 0
        cmp ax, 0       ;被除数为0时结束
        je next
        jmp s1
next:   mov ah, 2
        mov cx, di
s2:     pop dx
        or dl, 30H      ;数字转字符
        int 21h
        loop s2

        pop cx
        ret

printSpace:
        mov dl, ' '
        mov ah, 2
        int 21h
        ret
code ends
end start

 

实验任务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 strupr;
    mov ax, 4c00h
    int 21h

strupr:
    mov al, [si]
    cmp al, 97
    jb s
    cmp al, 122
    ja s
    and al, 0dfh
    mov [si], al
  s:inc si
    loop strupr
    ret
code ends
end start

在debug中调试截图:

 

 

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

中断也是异常的一种,中断有硬中断(由硬件产生的中断)和软中断(软件产生的中断)之分。ARM有七种不同的中断源,在中断向量表中对应的地址范围是0X00 ~ 0X1C。

int是软中断指令,CPU执行int n指令,相当于引发一个n号中断的中断过程,执行过程如下: 1)取得中断类型码 (2)标志寄存器的值入栈(3)设置标志寄存器TF和IF值为0 (4)CS入栈(5)IP入栈(6)从[中断类型码 * 4]和[中断类型码 * 4 + 2]两个字单元获取中断处理程序的入口地址IP和CS.

标签:8086,code,中断,mov,int,si,寄存器,ax,data
来源: https://www.cnblogs.com/zhujianyu0127/p/15670986.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有