专栏

曾梦想仗剑走天涯,看一看世界的繁华......

16位有符号整型数据的输出~~~~

;-----------------------------------------------------------------------------
;            __write_int_
;        ==========================
;
;Proc For write a int decimal to screen, int data in BX
;-----------------------------------------------------------------------------
__write_int_   proc    near
       push    cx
       push    ax
;process if negtive
       mov     ax, bx
       not    ax
       test    ah, 10000000B
       jne     not_negative_w            ;not negative
       mov     dl, '-'
       mov     ah, 02h
       int     21h
       neg     bx
not_negative_w:
       mov    cx, 10000d            ;divide by 10000
       mov    ax, bx                ;data in bx, mov to ax
       call    __dec_div_
       mov    cx, 1000d
       mov    ax, bx
       call    __dec_div_
       mov    cx, 100d
       mov    ax, bx
       call    __dec_div_
       mov    cx, 10d
       mov    ax, bx
       call    __dec_div_
       mov    cx, 1d
       mov    ax, bx
       call    __dec_div_
;linefeed and carriage after out put a data
       mov    ah, 2h
       mov    dl, 0ah                ;linefeed
       int    21h
       mov    dl, 0dh                ;carriage return after read
       int    21h
;
       pop    ax
       pop    cx
       ret                    ;return form _write_int_
;-----------------------------------------------------------------------------
;            __dec_div_
;        ==========================
;
;Subroutine to divide number in BX by number in CX
;print quotient on screen, (numberator in DX+AX, denom in CX)
;-----------------------------------------------------------------------------
__dec_div_     proc    near
;
       mov    ax, bx                          ;number low half
       mov    dx, 0                           ;zero out high half
       div    cx                              ;divide by CX
       mov    bx, dx                          ;remainder into BX
       mov    dl, al                ;quotient into DL
;print the contents of DL on screen
       add    dl, 30h                         ;convert to ASCII
       mov    ah, 2h
       int    21h
       ret
__dec_div_     endp                            ;end of proc __dec_div_
;-----------------------------------------------------------------------------
__write_int_   endp                            ;end of proc __write_int_
;
;-----------------------------------------------------------------------------
;
codesg    ends                    ;end of code segment
;*****************************************************************************
      end    begin                ;end assembly
;
阅读更多
文章标签: div subroutine assembly
上一篇汇编实现16位有符号数的输入~~~~~~
下一篇Simple C-Minus Compiler 简介
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭