Calling a C function from assembly code using as88 Assembler

I am working on a floating point calculator for 16-bit processors, in particular 8086/8088. I use as88 Tracker , which does not implement floating points, not allowing me to use sscanf with "% f".

I was thinking about doing this in C code and calling this function from Assembly code, but I could not learn how to do this.

This is my code:

 #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 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 user-entered line number into the float.

Can anyone help me with this?

Thank!

+3
2

C, , . , - , C- obj, , asm , sys. , , , sscanf(), , C, ; ; ; ; . .

.. - , - asm-. "3.14159", , ? , , imo.

0

-, , C . , 8088 x86 ABI, , 20 (), C- :

    push    RETVAL    ;last parameter first (address of float to return)
    push    STRFLOAT  ;first parameter last (format string)
    call    sscanf    ;error code is in ax
    add     sp,4      ;returned float is at RETVAL
    ;do something...

.sect .data
    STRFLOAT: .asciz  "%f"

.sect .bss
    RETVAL:   .space 4

sscanf _sscanf sscanf_.

0

All Articles