其他分享
首页 > 其他分享> > 实验4 8086标志寄存器及中断

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

作者:互联网

 1 assume cs:code, ds:data
 2 
 3 data segment
 4    x dw 1020h, 2240h, 9522h, 5060h, 3359h, 6652h, 2530h, 7031h
 5    y dw 3210h, 5510h, 6066h, 5121h, 8801h, 6210h, 7119h, 3912h
 6 data ends
 7 code segment 
 8 start:
 9     mov ax, data
10     mov ds, ax
11     mov si, offset x
12     mov di, offset y
13     call add128
14 
15     mov ah, 4ch
16     int 21h
17 
18 add128:
19     push ax
20     push cx
21     push si
22     push di
23 
24     sub ax, ax
25 
26     mov cx, 8
27 s:  mov ax, [si]
28     adc ax, [di]
29     mov [si], ax
30 
31     inc si
32     inc si
33     inc di
34     inc di
35     loop s
36 
37     pop di
38     pop si
39     pop cx
40     pop ax
41     ret
42 code ends
43 end start

 

不能替换,因为add命令可能会改变标志位CF

 

 

 

 

 

 

 1 assume cs:code, ds:data
 2 data segment
 3         str db 80 dup(?)
 4 data ends
 5 
 6 code segment
 7 start:  
 8         mov ax, data
 9         mov ds, ax
10         mov si, 0
11 s1:        
12         mov ah, 1
13         int 21h
14         mov [si], al
15         cmp al, '#'
16         je next
17         inc si
18         jmp s1
19 next:
20         mov ah, 2
21         mov dl, 0ah
22         int 21h
23         
24         mov cx, si
25         mov si, 0
26 s2:     mov ah, 2
27         mov dl, [si]
28         int 21h
29         inc si
30         loop s2
31 
32         mov ah, 4ch
33         int 21h
34 code ends
35 end start

 

 

 

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

  从输入里读入一串字符,直到#时候停止。

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

  输出换行符。

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

  打印刚刚输入的字符。

 

 1 assume cs:code,ds:data
 2 
 3 data segment
 4     x dw 91, 792, 8536, 65521, 2021
 5     len equ $ - x
 6 data ends
 7 
 8 code segment
 9 start:
10     mov ax, data
11     mov ds, ax
12     mov si, offset x
13 
14     mov cx, len/2
15 s:  mov ax, [si]
16     call printNumber
17     call printSpace
18     inc si
19     inc si
20     loop s
21     mov ax, 4c00h
22     int 21h
23 
24 printNumber:
25     push cx
26     mov cx, 0
27 
28  s1:mov dx, 0
29     mov bx, 10
30     div bx
31     push dx
32     inc cx
33     cmp ax, 0
34     jne s1
35 
36     mov ah, 2
37  s2:pop dx
38     add dx, 48
39     int 21h
40     loop s2
41 
42     pop cx
43     ret
44 
45 printSpace:
46     mov ah, 2
47     mov dl, 20h
48     int 21h
49     ret
50 code ends
51 end start

 

 

 

 1 assume cs:code,ds:data
 2 data segment
 3     str db "assembly language, it's not difficult but tedious"
 4     len equ $ - str
 5 data ends
 6 
 7 stack segment
 8     db 8 dup(?)
 9 stack ends
10 
11 code segment
12 start:
13     mov ax, data
14     mov ds, ax
15     mov si, 0
16     mov cx, len
17     call strupr
18     call printStr
19 
20     mov ax, 4c00h
21     int 21h
22 
23 strupr:
24     push cx
25     push si
26     s:
27         mov al, ds:[si]
28         cmp al, 97
29         jl c
30         cmp al, 122
31         jg c
32         and al, 0dfh
33         mov ds:[si], al
34     c:
35         inc si
36         loop s
37 
38     pop si
39     pop cx
40     ret
41 
42 
43 printStr:
44     push cx
45     push si
46     s2:
47         mov ah, 2
48         mov dl, ds:[si]
49         int 21h
50         inc si
51     loop s2
52 
53     pop si
54     pop cx
55     ret
56 
57 code ends
58 end start

 

 

 

 1 assume cs:code, ds:data
 2 
 3 data segment
 4     str1 db "yes", '$'
 5     str2 db "no", '$'
 6 data ends
 7 
 8 code segment
 9 start:
10     mov ax, data
11     mov ds, ax
12 
13     mov ah, 1
14     int 21h
15 
16     mov ah, 2
17     mov bh, 0
18     mov dh, 24
19     mov dl, 70
20     int 10h
21 
22     cmp al, '7'
23     je s1
24     mov ah, 9
25     mov dx, offset str2
26     int 21h
27 
28     jmp over
29 
30 s1: mov ah, 9
31     mov dx, offset str1
32     int 21h
33 over:  
34     mov ah, 4ch
35     int 21h
36 code ends
37 end start

 

 

 【功能】判断输入的字符是不是7,如果结果为是,打印yes,否则就输出no。

 

 1 assume cs:code
 2 
 3 code segment
 4 start:
 5     int 42
 6 
 7     mov ah, 4ch
 8     int 21h
 9 code ends
10 end start

 

 1 assume cs:code
 2 code segment
 3 start:
 4 ; 42 interrupt routine install code
 5 mov ax, cs
 6 mov ds, ax
 7 mov si, offset int42 ; set ds:si
 8 mov ax, 0
 9 mov es, ax
10 mov di, 200h ; set es:di
11 mov cx, offset int42_end - offset int42
12 cld
13 rep movsb
14 ; set IVT(Interrupt Vector Table)
15 mov ax, 0
16 mov es, ax
17 mov word ptr es:[42*4], 200h
18 mov word ptr es:[42*4+2], 0
19 mov ah, 4ch
20 int 21h
21 int42:
22 jmp short int42_start
23 str db "welcome to 2049!"
24 len equ $ - str
25 ; display string "welcome to 2049!"
26 int42_start:
27 mov ax, cs
28 mov ds, ax
29 mov si, 202h
30 mov ax, 0b800h
31 mov es, ax
32 mov di, 24*160 + 32*2
33 mov cx, len
34 s: mov al, [si]
35 mov es:[di], al
36 mov byte ptr es:[di+1], 2
37 inc si
38 add di, 2
39 loop s
40 iret
41 int42_end:
42 nop
43 code ends
44 end start

 

 

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