编程语言
首页 > 编程语言> > 汇编语言第四次实验

汇编语言第四次实验

作者:互联网

1. 实验任务1

 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位置0。从而丢失了低位加法的进位,导致计算结果错误。因此不能替换。

 

2. 实验任务2

 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

 

3. 实验任务3

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

 

4. 实验任务4

 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 code segment
 8 start:
 9     mov ax,data
10     mov ds,ax
11     mov si,offset str
12     mov cx,len
13     call strupr
14     
15     mov ah,4ch
16     int 21h
17 
18 strupr:mov al,[si]
19     cmp al,97
20     jb next
21     cmp al,122
22     ja next
23     and al,0dfh
24     mov [si],al
25 next:inc si
26     loop strupr
27     ret
28 code ends
29 end start

 call strupr调用前后分别查看数据段的值,发现strupr函数确实将小写字母转换成了大写。

 

5. 实验任务5

 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。

 

6. 实验任务6

 

CPU可以在执行完当前执行的指令后,检测到从CPU外部发送过来的或内部产生的中断信息,包括int指令信息。通过将中断处理程序安装到内存空间并设置中断向量表,可以使将来通过int指令跳转到中断处理程序执行。

标签:code,汇编语言,mov,int,si,实验,ax,data,第四次
来源: https://www.cnblogs.com/t1lam1lsu/p/15656123.html