hi, i need an Ascii->Float and a Flot->Ascii routines, better if in TASM sintax. Could anyone help ? THX
Posted on 2001-06-07 01:59:00 by angelo
Use sscanf to convert from ascii to float, and sprintf to convert from float to ascii. Sorry I have no asm example. In C you would do :

  char buffer[16];
  float f = 0.123456;

  // convert f1 to an ascii string, the result is in buffer
  sprintf(buffer, "%f", f1);

  // convert buffer to a float, the result is in f1
  sscanf(buffer, "%f", &f1);
Here is the asm code produced by the VisualC++ compiler (some lines were modified)

TITLE	test.c

.model FLAT


buffer    BYTE    16 DUP (0)
; you must know how to convert a float to a double !
f	  DD	03dfcd680r	; 0.123456
float_fmt BYTE  "%f", 0


PUBLIC	_main
EXTRN	_sprintf:NEAR
EXTRN	_sscanf:NEAR
EXTRN	__fltused:NEAR



; Line 7
	push	ebp
	mov	ebp, esp
; Line 9
	fld	DWORD PTR f
	sub	esp, 8
	fstp	QWORD PTR 
	push	OFFSET float_fmt
	push	OFFSET buffer
	call	_sprintf
	add	esp, 16					
; Line 12
	push	OFFSET f
	push	OFFSET float_fmt
	push	OFFSET buffer
	call	_sscanf
	add	esp, 12					
; Line 13
	pop	ebp
	ret	0
main	ENDP
Correction : you have to link with the libc library. Good luck! This message was edited by karim, on 6/7/2001 8:06:16 AM
Posted on 2001-06-07 07:48:00 by karim
karim, many tanx, this is wonderful ! I was trying to use some very long asm floating routines with many variables. Big mess. With your indication should be all very easy !
Posted on 2001-06-08 01:58:00 by angelo