汇编网首页登录博客注册
masmaster的学习博客
博客首页博客互动【做检测题】论坛求助

我的博客

个人首页 |  我的文章 |  我的相册 |  我的好友 |  最新访客 |  文章收藏 |  论坛提问 |  友情链接 |  给我留言  
图片载入中
文章收藏

[2010-07-25 09:38] 练习:32位十六进制数转换成十进制数程序

终于把这个问题搞定啦!当程序按照自己的意愿运行和输出的时候, 才发现, 其实很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
;-----------------------------------------------------
评论次数(0)  |  浏览次数(384)  |  类型(程序与练习) |  收藏此文  | 
 
 请输入验证码  (提示:点击验证码输入框,以获取验证码