汇编语言王爽 实验10

时间:2023-01-01 00:44:03
  1 assume cs:code
2 data segment
3 db 10 dup(0)
4 data ends
5
6 code segment
7 start:
8 mov ax,12666
9 mov bx,data
10 mov ds,bx
11 mov si,0
12 call dtoc
13
14 mov dh,8
15 mov dl,3
16 mov cl,2
17 call show_str
18
19 mov ax,4c00h
20 int 21h
21
22 dtoc:
23 push ax
24 push cx
25 push bx
26 push dx
27 push si
28 push di
29
30
31 mov bx,10
32 mov di,0
33
34 s0:
35 mov dx,0
36 div bx
37 add dx,30h
38
39 push dx ;用栈存储倒序的余数
40 inc di
41
42 mov cx,ax
43
44 jcxz ok0
45
46 jmp short s0
47 ok0:
48
49
50 mov cx,di
51 s1:
52 pop ax ;正序显示
53 mov [si],al
54 inc si
55
56 loop s1
57
58 pop di
59 pop si
60 pop dx
61 pop bx
62 pop cx
63 pop ax
64 ret
65
66
67 show_str:
68 push ax ;子程序用到的寄存器入栈
69 push bx
70 push cx
71 push di
72 push si
73
74
75 mov ax,0b800h
76 mov es,ax
77
78 mov al,160
79 dec dh
80 mul dh
81 mov bx,ax ;计算行偏移
82
83 dec dl
84 mov al,dl
85 mov ah,0
86 add bx,ax;计算列偏移
87
88 mov di,0
89 mov al,cl
90 s:
91 mov ch,0
92 mov cl,ds:[si]
93
94 jcxz ok
95
96 mov ch,al
97
98 mov es:[bx+di],cx
99 add di,2
100 inc si
101 loop s
102 ok:
103 pop si
104 pop di
105 pop cx
106 pop bx
107 pop ax
108 ret
109
110 code ends
111 end start