integer数转ascii串子程序。
调用前将数字放在ax中,存放转换后字符串的地址放bx,然后将bx,ax先后压入堆栈。过程如下:
itoaproc proc near
push bp
mov bp,sp
push ax
push bx
push cx
push dx
push di
pushf
mov ax,[bp+6]
mov di,[bp+4]
ifSpecial:
cmp ax,8000h
jne EndIfSpecial
mov BYTE PTR [di],'-'
mov BYTE PTR [di+1],'3'
mov BYTE PTR [di+2],'2'
mov BYTE PTR [di+3],'7'
mov BYTE PTR [di+4],'6'
mov BYTE PTR [di+5],'8'
jmp ExitIToA
EndIfSpecial:
mov dx, ax
mov al,' '
mov cx,5 ; first five
cld ; bytes of
rep stosb ; destination field
mov ax, dx ; copy source number
mov cl,' ' ; default sign (blank for +)
IfNeg: cmp ax,0 ; check sign of number
jge EndIfNeg ; skip if not negative
mov cl,'-' ; sign for negative number
neg ax ; number in AX now >= 0
EndIfNeg:
mov bx,10 ; divisor
WhileMore: mov dx,0 ; extend number to doubleword
div bx ; divide by 10
add dl,30h ; convert remainder to character
mov [di],dl ; put character in string
dec di ; move forward to next position
cmp ax,0 ; check quotient
jnz WhileMore ; continue if quotient not zero
mov [di],cl ; insert blank or "-" for sign
ExitIToA: popf ; restore flags and registers
pop di
pop dx
pop cx
pop bx
pop ax
pop bp
ret 3 ;exit, discarding parameters
itoaproc ENDP