汇编实现16位有符号数的输入~~~~~~

来源:互联网 发布:昆山ug编程培训学费 编辑:程序博客网 时间:2024/06/04 17:59
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;NOTE: This ASM file is generated by:
;                  Simple C minus Compiler     v1.0
;      CopyRight (C) 2002-2008 Lonelyforest. All rights reseved.
;
; Because its not perfect, so this file maybe have bug! use it carefully!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;
;-----------------------------------------------------------------------------
;            __read_int_
;        ==========================
;
;Proc For Read a int decimal, result in BX
;-----------------------------------------------------------------------------
__read_int_    proc    near
       local   minus:byte, count:byte
;minus is falg to input number
;initial
       push    ax
       push    cx
       push    dx
       mov    minus, '+'            ;flag, +
       mov     bx, 0
       mov    count, 5d            ;number of digits
;
_new_char_:
       mov    ah, 1                ;input from keyboard
       int    21h                  ;call DOS
;
       cmp    al, '+'
       je    _new_char_            ;maybe have bug!
       cmp    al, '-'
       jne    _continue_read_
       mov    minus, '-'
       jmp    _new_char_
;
_continue_read_:
       sub    al, 30h                ;ASCII to Binary
       jl    _exit_read_            ;jump exit if < 0
       cmp    al, 9d                ;is it > 9d ?
       jg    _exit_read_            ;yes
       cbw                          ;byte in al to word in ax
;digit now in (ax)
       xchg    ax,bx                ;trade digit & number
       mov    cx, 10d
       mul    cx
       xchg    ax,bx                ;trade number & digit
;Add digit in AX to number in BX
       add    bx, ax                ;add digit to number
       dec    count
       jnz    _new_char_            ;get next digit if < 5
_exit_read_:                        ;should process minus!!!
       cmp     minus, '-'
       jne     not_negative_r
       neg     bx                              ;negetive
not_negative_r:
       mov    ah, 2h
       mov    dl, 0ah                ;linefeed
       int    21h
       mov    dl, 0dh                ;carriage return after read
       int    21h
;
       pop    dx                     ;recover registers
       pop    cx
       pop    ax
;result number in bx
       ret
__read_int_    endp                ;end of proc __read_int_
;