c++.dos.16-bits - Calling assembly functions from C++.
- Noob_programmer (79/79) Jun 11 2004 hi,
hi, I am trying to call an assembly function I made, from a c++ program. I get an error message from the DM compiler that states diag01.obj(diag01) Error 42: Symbol Undefined _memSize --- errorlevel 1 I use the command: dmc diag01.cpp -msd But it creates an executable that seems to run. Here is the assembly code: Public _memSize data buffer1 BYTE 20 DUP(?) count DWORD 0 code _memSize PROC NEAR, C PUSH EBP MOV EBX, 00000000h MOV AX, SEG buffer1 MOV ES, AX MOV AX, OFFSET buffer1 MOV DI, AX L1: MOV EAX, 0000E820h MOV EDX, 534D4150h ;'SMAP' MOV ECX, SIZEOF buffer1 INT 15h JC L2 CMP EBX, 0 JZ L2 MOV EAX, OFFSET buffer1 + 8 MOV ECX, [EAX] ;Dereference EAX ADD count, ECX JMP L1 L2: POP EBP RET _memSize ENDP END And here is the C++ code: #include <iostream.h> #include <stdlib.h> extern "C" void memSize(); int main() { unsigned int choice; unsigned long count = 0; system ("CLS"); do { cout << "Choose something. "; cin >> choice; switch(choice) { case 1: system ("CLS"); cout << "Option 1\n"; break; case 2: system ("CLS"); cout << "Option 2\n"; memSize(); break; case 3: system ("CLS"); cout << "Option 3\n"; break; case 0: system ("CLS"); cout << "Exiting!!!\n"; break; default: system ("CLS"); cout << "Not a valid selection, please re-choose!\n"; } }while(choice != 0); return 0; } Could someone please look at my code and tell me what I am doing wrong. Also, could someone tell me how to return values from the assembly funtion back to the C++ calling program. Thanks BTW: The assembly funtion finds the total system memory(conventional, reserved, and extended).
Jun 11 2004