Assembly 在x86程序集中将整数转换为ASCII码时出现问题
我正在尝试使用下面的代码将Assembly 在x86程序集中将整数转换为ASCII码时出现问题,assembly,x86,16-bit,Assembly,X86,16 Bit,我正在尝试使用下面的代码将ax中的整数转换为ASCII码。但运行它会输出515,而不是我预期的513。错误在哪里 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
ax
中的整数转换为ASCII码。但运行它会输出515,而不是我预期的513。错误在哪里
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
stk段
dw 32 dup(0)
stk结束
dts段
posnumdb6dup(0);0您的divide循环看起来不错
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ( void )
{
unsigned int ax;
unsigned int dx;
ax=513;
while(ax)
{
dx=ax%10;
ax=ax/10;
printf("%c",dx+0x30);
}
printf("\n");
}
#包括
#包括
#包括
内部主(空)
{
无符号整数ax;
无符号整数dx;
ax=513;
while(ax)
{
dx=ax%10;
ax=ax/10;
printf(“%c”,dx+0x30);
}
printf(“\n”);
}
我从上面的循环中得到了315
我怀疑当你试着在你的5上翻转绳子时,你是在踩你的3。试试713这样的数字,看看结果是否是717。523如果你得到525,等等。我猜1234得到4334。SI
没有初始化。它应该指向为逆序数字分配的缓冲区。Er,抱歉。我不知道这是一个古老的答案