Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Interfacig asm with c++

_Silencer_Silencer Member Posts: 1
[b][red]This message was edited by _Silencer at 2002-10-27 23:49:40[/red][/b][hr]

As a newcomer to assembler language, Im currently learning to call asm subroutines through c++ and calling C++ functions from an asm routine.

Basically, I dont know how can I provide a C++ function a double floating point number as a parameter: heres my code:

extern "C" double bisection(double (* f) (double), double a, double b);

double f1(double x) {
return (x - 3) * (x + 4);

int main(void) {

double x1;

x1 = bisection(&f1, 1.0, 4.0);
cout << "(x-3)(x+4)=0, x=" << x1 << endl;

return 0 ;

I define f as a pointer to the f1 function and double X as a parameter.

From the subroutine point of view, Im trying to make the call like this: (this is the relevant part of my code, NASM syntax)


%define f ebp + 8 ; this is my function pointer
%define a ebp + 12 ; this is where the double was pushed
%define b ebp + 20 ; a second parameter, but not important

as the first one doesnt work yet :P

segment .data

a_lim dd 0.0
b_lim dd 0.0

neg_treshold dd -1.e-10
pos_treshold dd 1.e-10

segment .text

global _bisection


push ebp
mov ebp, esp

push dword [a] <------ heres where Im stuck. I guess I

just cant push a qword to the stack right? So how can I feed f1 with the double X it needs If I can only push 32 bit values on to the stack???
call [f]
add esp, ????

I appreciate any help you could provide. Thanks


  • Shawn CarterShawn Carter Member Posts: 0

    _______ { } free video tutorials and ebooks about \ Go, Ruby, Visual Basic .NET, Assembly, MATLAB, Perl, Objective-C, C#, Python, Visual Basic, C++, Delphi, PL/SQL, Java, JavaScript, C, PHP, R, Swift, Scratch Scala, ABAP, Julia, Logo, Dart, Fortran, Lua, SAS, COBOL, Kotlin, Erlang, LabVIEW, Prolog, Awk, VBScript, Transact-SQL, Apex, Bash, D, Scheme, Hack, Lisp, Rust, FoxPro, Crystal, ML, F#, Ada, Alice, Clojure \

Sign In or Register to comment.