终于把这个问题搞定啦!当程序按照自己的意愿运行和输出的时候, 才发现, 其实很easy!
;----------------------------------------------------
1 title htod.asm
2 ;from hex-digit to dec-digit translate and print decimal digit
3 assume cs:code
4 data segment
5 tmp db 10 dup (0)
6 crlf db 0dh,0ah,'$'
7 data ends
8 code segment
9 start:
10 mov ax,data ;DateSegment addr
11 mov ds,ax
12 mov si,0 ;Assign store tmp-data addr
13 ;
14 mov dx,01h ;Dividend:High 16bit hex
15 mov ax,0ffffh ;Dividend:Low 16bit hex
16 cmp dx,0
17 jz _a ;if dx=0 then print ax
18 xchg ax,dx
19 call shex ;Display DX and AX hex digit
20 xchg ax,dx
21 call shex
22 jmp _p
23 _a:
24 call shex
25 _p:
26 push ax
27 push dx
28 mov dx,offset crlf ;print newline
29 mov ah,9
30 int 21h
31 pop dx
32 pop ax
33 mov bx,10 ;Divisor
34 ;begin hex to dec translate
35 main:
36 cmp ax,10 ;if ax<10,then jmp label disp
37 jb disp ;print decimal digit
38 call divdw ;call sub-proc
39 inc si
40 jmp main
41 ;begin print decimal digit on screen.
42 disp:
43 add al,30h
44 mov [si],al
45 L:
46 mov ah,2 ;call dos func,print decimal digit
47 mov dl,[si]
48 int 21h
49 dec si
50 cmp si,0
51 jnl L
52 ;Return Dos
53 mov ah,4ch
54 int 21h
55 ;
56 ;display 16bit Register Hex-digit
57 shex proc uses ax cx dx
58 mov cx,4
59 sh: push cx
60 mov cl,4
61 rol ax,cl
62 push ax
63 sub ah,ah
64 and al,0fh
65 cmp al,0ah
66 jge s1
67 add al,30h
68 jmp ok
69 s1: add al,37h
70 ok: mov ah,2
71 mov dl,al
72 int 21h
73 pop ax
74 pop cx
75 loop sh
76 ret
77 shex endp
78 ;
79 ;Function: from hex to dec conv
80 ;DX=High 16bit hex
81 ;AX=Low 16bit hex
82 ;Bx=divisor
83 ;Result:
84 ;Put Rem into DS:SI
85 divdw proc uses bx cx
86 push ax
87 mov ax,dx
88 xor dx,dx
89 div bx
90 mov cx,ax
91 pop ax
92 div bx
93 add dl,30h
94 mov [si],dl
95 mov dx,cx
96 ret
97 divdw endp
98 ;
99 code ends
100 end start
;-----------------------------------------------------
- [somniumchase] 我一运行就说没有数字 01/01 11:44
- [游客] 为什么啊 08/07 15:36
- [游客] 如果想快一些 就改下面这里 dx值改成1H delay: push ax 04/19 02:53
- [lshhjx] 注释在程序中很重要,楼主不知道吗? 12/08 13:40
- [biaggi] 看不明白,在下還須學習 11/06 08:11
- [游客] 我运行的时候直接显示Unkown filename跳出了- -请问怎么改 06/16 21:44
- [游客] 勿庸置疑,注释是好习惯。与人方便自己方便。 04/12 10:33
- [游客] 老实说,看着真心累呀! 04/07 18:37
- [游客] 很无语,初学者就多看书,不要动不动要别人注释,基础打好了,再自己注释,这样比别人帮你注释好得多 12/17 19:43
- [dgkepu] 初学者:不懂,希望有多点注释带着学习学习! 12/07 20:52
- [游客] windows 7是一个64Bit操作系统,它不兼容DOS,无法识别16Bit系统。重装系统wind 02/28 21:05
- [游客] windows 7是一个64Bit操作系统,它不兼容DOS,无法识别16Bit系统。重装系统wind 02/28 21:05
- [466987333] 你好,高手,我想请教一个问题。 我用的是win7操作系统,32位的,里面没有找masm目录,是不是 12/12 17:30
- [lanfioncc] 那个太高级了。。。我还有点看不懂。。不过谢谢!!! 11/27 11:23
- [yc2010] 实验16中的 table: dw sub1,sub2,sub3,sub4 可不可以改成呢? 09/11 09:08
- [yc2010] mov bl,ah mov bh,0 add bx,bx ----------->这里为 09/07 21:03
- [yc2010] 为什么要add bx,bx呢? 09/07 20:55
- [yc2010] 那是不是像table[bx],ds[bx]....等(内存单元)都是表示一个字节呢? 09/06 21:10
- [masmaster] 杨季文的《80X86汇编语言程序设计教程》 09/01 12:52
- [游客] to masmaster shl左移4位,那al传进来的4,5,6位背景色不就没了. 为什 09/01 11:00