c++ - Hybrid program (asm+cpp): sending and receiving an array pointer -
(intel x86. turbo assembler , borlandc compilers, turbo linker.)
my question how modify f1.asm
(and possibly main1.cpp
) code.
in main1.cpp
input integer values send function in f1.asm
, add them, , send , display result in main1.cpp
.
main1.cpp:
#include <iostream.h> #include <stdlib.h> #include <math.h> extern "c" int f1(int, int, int); int main() { int a,b,c; cout<<"w = a+b+c" << endl ; cout<<"a = " ; cin>> a; cout<<"b = " ; cin>>b; cout<<"c = " ; cin>>c; cout<<"\nw = "<< f1(a,b,c) ; return 0; }
f1.asm:
.model small, c .data .code public f1 f1 proc push bp mov bp, sp mov ax,[bp+4] add ax,[bp+6] add ax,[bp+8] pop bp ret f1 endp .stack db 100(?) end
i want make such function arbitrary number of variables sending pointer array of elements f1.asm
.
question: if make int f1(int, int, int)
function in main1.cpp
int f1( int* )
, , put pointer array containing to-be-added values, how should .asm
code access first (and subsequent) array elements?
how pointer stored? because tried treating offeset, , offsett of offset, , tried few other things still couldn't access array's elements.
(if can access first few, can take care of rest of problem.)
...or should i, in particular case, use else .cpp
's side pointer?
ouch, long time haven't seen call 16 bits c assembly ...
c or c++ allows passing variable number of arguments provided callee can determine number because pushes arguments in opposite order before calling function, , caller cleans stack after function returned.
but passing array totally different : pass 1 single value address (a pointer ...) of array
assuming pass array of 3 ints - 16 bits small model (int, data pointers, , code addresses 16 bits)
c++
int arr[3] = {1, 2, 3} int cr; cr = f1(arr);
asm
push bp mov bp, sp mov ax,[bp+4] ; address of array mov bp, ax ; bp points array mov ax, [bp] ; value of first element add ax,[bp+2] ; add remaining elements add ax,[bp+4] pop bp ret
Comments
Post a Comment