问题x86汇编转换成整数ASCII code [英] Problem converting integer to ASCII code in x86 assembly
本文介绍了问题x86汇编转换成整数ASCII code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用下面的code为整数转换成斧
来ASCII codeS。但运行它输出515,而不是513如我所料。哪里的错误?
STK段
DW 32 DUP(0)
STK结束
DTS段
posnum分贝6 DUP(0); 0℃; X&下; 65536;
DTS结束
CDS段
假设CS:CDS,DS:DTS,SS:STK
主要PROC远 MOV AX,赛格DTS
MOV DS,AX
MOV ES,AX
异斧,斧 MOV AX,513 MOV DI,抵消posnum 呼叫ConvertPositive MOV啊,09H
MOV DX,偏移posnum
INT 21H
main_finish:
MOV啊,08H
INT 21H
MOV AX,4c00h
INT 21H
主要ENDP
CDS完特效片段
假设CS:特效
ConvertPositive PROC远
XOR DX,DX
XOR CX,CX
MOV BL,10
MOV BH,0
divloop:
MOV DX,0
DIV BX
添加DL,30H
MOV字节PTR [SI],DL
INC CL
INC SI
CMP斧,0
JNE divloop
enddiv:
十二月SI
复制:
STD
LODSB
CLD
STOSB
循环副本
MOV字节PTR [二],$
RET
ConvertPositive ENDP
特效结束
主要结束
解决方案
SI
未初始化。它应指向分配相反的顺序数字的缓冲区。
I am trying to use the code below to convert an integer in ax
to ASCII codes. But running it outputs 515, rather than 513 as I expected. Where is the error?
stk segment
dw 32 dup(0)
stk ends
dts Segment
posnum db 6 dup(0) ;0<x<65536;
dts ends
cds Segment
Assume cs:cds , ds:dts,ss:stk
Main Proc Far
mov ax,seg dts
mov ds,ax
mov es,ax
xor ax,ax
mov ax,513
mov di,offset posnum
Call ConvertPositive
mov ah,09h
mov dx ,offset posnum
int 21h
main_finish:
mov ah,08h
int 21h
mov ax,4c00h
int 21h
Main endp
cds Ends
procs segment
assume cs:procs
ConvertPositive proc far
xor dx,dx
xor cx,cx
mov bl,10
mov bh,0
divloop:
mov dx,0
div bx
add dl,30h
mov byte ptr [si],dl
inc cl
inc si
cmp ax,0
jne divloop
enddiv:
dec si
copy:
std
LODSB
cld
STOSB
loop copy
mov byte ptr [di],'$'
ret
ConvertPositive endp
procs ends
end Main
解决方案
SI
is not initialized. It should point to a buffer allocated for the reverse order digits.
这篇关于问题x86汇编转换成整数ASCII code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文