下面程序段的功能是把DA1数据区的数转换为对应的ASCII码。试完善成本程序。
DA1 DB 00H,01H,02H,03H,04H,05H,06H,07H,08H,09H
ASCI DB 10DUP(?)
CUNT=ASCI-DAI
LEA SI,DAI
LEA DI,ASCI
————————————
LOOP:MOV AL,[SI]
——————————————
MOV [DI],AL
INC DI
LOOP LOOP1
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