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

我的博客

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

[2010-07-07 17:40] 推荐博文 【原创】十进制转换成十六进制和二进制

图片载入中
;------------------------------------------------------------------------------
assume        cs:code
data        segment
tab        dd 1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000
buf        dw 4 dup (0)
tmp        dw 8 dup (0)
error        db 'Invialid number!','$'
error1        db 'stirngs too big!','$'
hexmsg        db 'Hexcode:','$'
binmsg        db 'Bincode:','$'
cr        db 0dh,0ah,'$'
data        ends
code        segment
err:        mov dx,offset error
        mov ah,9
        int 21h
        jmp over
err1:        mov dx,offset error1
        mov ah,9
        int 21h
        jmp over
;-----------------------------
;mulit-summ
;-----------------------------
cf:        
        mov cl,byte ptr es:[bx]
        mov ch,0
        cmp si,0
        je ok1
        mov ax,word ptr [si]
        mul cx
        mov [di],ax
        mov [di+2],dx
        mov ax,word ptr [si+2]
        mul cx
        add word ptr [di+2],ax
        mov ax,[di]
        mov dx,[di+2]
        adc [di+6],ax
        adc [di+8],dx
        ret
ok1:        jmp ok
;-----------------------------
;from hex to bin
;-----------------------------
h2b:        push ax
        push dx
        push cx
        mov cx,16
        sub dx,dx
s3:        rol ax,1
        push ax
        adc dl,0
        or dl,30h
        mov ah,2
        int 21h
        pop ax
        sub dl,dl
        loop s3
        pop cx
        pop dx
        pop ax
        ret
;
start:        
;-----------------------------
;main program
;-----------------------------
        mov ax,data
        mov ds,ax
        mov cx,es:80h
        and cx,0fh
        cmp cx,10
        jg err1
        mov si,82h
s:        
        mov al,es:[si]
        cmp al,0dh
        jz do1
        cmp al,30h
        jb err
        cmp al,39h
        ja err
        and ax,0fh
        mov es:[si],al
        inc si
        loop s
do1:
        mov bx,es:[80h]
        and bx,0fh
        mov si,es:[80h]
        and si,0fh
        sub si,1
        mov cl,2
        shl si,cl
        sub si,4
        mov bx,82h
        mov di,offset tmp
        mov ax,0
        mov dx,0        
s1:
        call cf
        inc bx
        sub si,4
        jmp s1
ok:        add [di+6],cx
;-----------------------------
        mov bl,es:[80h]
        cmp bl,0
        jz over
        jmp hex
;-----------------------------
;disp hex
;-----------------------------
hex:        lea dx,hexmsg
        mov ah,9
        int 21h

        mov cx,8
        mov bx,0
        mov dx,[di+8]
s2:        push cx
        mov cl,4
        cmp bx,4
        je s21
        rol dx,cl
        push dx
        and dl,0fh
        cmp dl,9
        ja s211
        add dl,30h
        jmp ok3
s211:        add dl,37h
ok3:        mov ah,2
        int 21h
        inc bx
        pop dx
        pop cx
        loop s2
s21:        mov ax,[di+6]
s212:
        push cx
        mov cl,4
        rol ax,cl
        push ax
        and al,0fh
        cmp al,9
        ja s213
        add al,30h
        mov dl,al
        jmp ok4
s213:        add al,37h
        mov dl,al
ok4:        mov ah,2
        int 21h
        pop ax
        pop cx
        loop s212
;-----------------------------
;disp bin
;-----------------------------
        mov dx,offset cr
        mov ah,9
        int 21h

        mov dx,offset binmsg
        mov ah,9
        int 21h

        mov ax,[di+6]
        mov dx,[di+8]
        xchg ax,dx
        call h2b
        xchg dx,ax
        call h2b
;-----------------------------        
over:
;-----------------------------
        mov ah,4ch
        int 21h
code        ends
        end        start
;-----------------------------------------------------------------------------
评论次数(15)  |  浏览次数(38913)  |  类型(程序与练习) |  收藏此文  | 

[  thedaydreamwang   发表于  2010-07-08 04:57  ]

第一次这么靠前!!先赞一个!!

[  游客   发表于  2010-07-25 20:40  ]

我靠 汇编我看没什么 好玩的

[  jjch224   发表于  2010-07-26 00:20  ]

虽然有些东西还看不懂,不过,相信学完课本里面的东西,就可以了解了,致敬!!!

[  游客   发表于  2010-08-08 09:14  ]

Very good!
Thank you!

[  three-stone   发表于  2010-10-21 16:02  ]

现在还看不懂。

[  xiaoluo   发表于  2010-11-21 22:16  ]

呵呵,还看不懂的呢,哎,希望学完这本书后可以看懂

[  游客   发表于  2010-12-29 17:12  ]

有没有十六位的二进制转十进制的代码啊?

[  游客   发表于  2011-04-17 16:45  ]

写的太好了,一运行就能通过,对于初学者是莫大的鼓励啊。

[  游客   发表于  2011-12-09 11:26  ]

mov cx,es:80h 
es:80h什么东西哪里冒出来

[  游客   发表于  2012-04-04 15:02  ]

<><><>石头

[  biaggi   发表于  2014-11-06 08:11  ]

看不明白,在下還須學習

[  lshhjx   发表于  2015-12-08 13:40  ]

注释在程序中很重要,楼主不知道吗?

[  somniumchase   发表于  2021-01-01 11:44  ]

我一运行就说没有数字

 
 请输入验证码  (提示:点击验证码输入框,以获取验证码