/*EAX中放数字,buffer address in esi...*/
/* convert a usigned number to a string ......*/
mov ebx,10 ; number base
Next:
xor edx,edx
div ebx
add dl,30h
mov byte ptr [esi],dl
inc esi
cmp eax,0
jnz Next
mov [edi],0 ;end a string with NULL
...
...
;DO other works.
<2>关于字符串转成数字有好多函数可用呀..它们转化时都是以遇到第一个
非数字为转换结束条件的....
EG:
"1323A34" 转成数字结果为...1323.
函数有(C库):atoi(),atol(),atof() and so forth.....
int atoi( const char *string );
char *_itoa( int value, char *string, int radix );
#include <stdlib.h>
#include <stdio.h>
int main()
{
char* szStr = "123456";
int iNumber = 7890;
char szBuffer[20];
printf("Convert string %s to a number %d.\n",szStr,
atoi(szStr));
printf("Convert number %d to a string %s.\n",iNumber,
_itoa(iNumber,szBuffer,10));
printf("the result is %s\n",szBuffer);
唉.....老兄偶也是自己在学习......由于MASM32中不包括C库中的头文件.....即没有相应的*.INC文件....也没有想应的库,那就只能自己从STDLIB.H中手工整理出函数的原形了.........至于库从VC中找到libc.lib or MSVCRT.LIB 包含进去了.....
如下..
printf proto foramt:dword, vararg
atoi proto string:dword
itoa proto value:dword, string:dword, radix:dword
唉....偶还是写了一个程序............希望对你有用.....................................
/*-------------------------------------------------------------------*/
.386
.model flat, c
option casemap:none
includelib MSVCRT.LIB
.data
szFormatA db 'Convert string %s to number %d',0dh,0ah,0
szFormatB db 'Convert number %d to string %s',0dh,0ah,0
szStr db '12345',0
szBuffer db 20 dup(?)
iResult dd 0
iNumber dd 6789
.code
printf proto foramt:dword, :vararg
atoi proto string:dword
_itoa proto value:dword, string:dword, radix:dword
exit proto statu:dword
/*--------------------------------------------------------------------*/
ml /c /coff test.asm <cr>
link /subsystem:console /libpath:E:\SoftDevTools\VC++\VC98\Lib test.obj <cr>
test <cr>
Convert string 12345 to number 12345
Convert number 6789 to string 6789