I'm working on a Floating Point calculator for 16bits processors, specifically 8086/8088. I'm using as88 Tracker which doesn't implement floating points, not allowing me to use sscanf with "%f".
I thought about doing that in C code and calling this function from my Assembly code but couldn't find out how to do it.
This is my code so far:
#include "../syscalnr.h"
.sect .text
_code_:
push bp
mov bp, sp
push SEGOP-PRIOP ! Pushes PRIOP String Size into the stack
push PRIOP
push STDOUT
push _WRITE ! System Call to print string on the display
sys
add sp, 8
mov di, rasc ! Prepares DI to receive char
push _GETCHAR
1: sys
cmpb al, '\n' ! Compares with EOL and keeps storing the string chars
je 2f
stosb ! Stores char into variable rasc
jmp 1b
2: xorb al, al ! Clears registers
add sp, 2
.sect .data
_data_:
PRIOP: .asciz "Insert first operand:\n "
SEGOP: .ascii "Insert second operand: "
FORMAT: .asciz "%u"
F_CHAR: .asciz "%c"
F_STR: .asciz "%s\n"
.sect .bss
_bss_:
rasc: .space 10
I want to be able to write a C function as:
float* getVal(char* ch) {
float fVal;
sscanf(ch, "%f", &fVal);
if(fVal == 0) return 0;
return fVal;
}
And call it from my Assembly code to translate the string number input by the user into a float.
Can anyone help me with that?
Thanks!
strtod, which is part of the standard library. - Chris Lutz