home *** CD-ROM | disk | FTP | other *** search
- // This code is best compiled using:
- // bcc32 -WX -B -3 filename filename.asm
-
- #include <iostream.h>
- #include <conio.h>
- #include <stdio.h>
- #include <string.h>
- #include <dos.h>
-
- // define a structure of various size elements.
- struct mystruct{
- char c;
- unsigned char uc;
- short s;
- unsigned short us;
- long l;
- unsigned long ul;
- char string [80];
- };
-
- // This will be a simple function for preformatting our screen.
- void format();
-
- // The assembler routine must be declared as "extern". I'll use the
- // "C" type calling convention, since I concider it much easier to not
- // have to fiddle with the leading underscores in code of this type.
- extern "C" void fill_struct (mystruct *);
- extern "C" unsigned long get_stack_pntr(void);
- extern "C" print_stack_value();
-
- main()
- {
- format();
-
- char fill[45]=" + this portion added by the C++ module";
-
- static unsigned long stack_pntr;
- long save_esp;
-
- // Declare a pointer of a type to match my C++ structure.
- mystruct * struct_ptr;
-
- // And create one object.
- mystruct struct_out;
-
- // I'm going to go ahead and define all the members here.
- struct_out.c = 0;
- struct_out.uc = 0;
- struct_out.s = 0;
- struct_out.us = 0;
- struct_out.l = 0;
- struct_out.ul = 0;
- for (int i = 0; i < 80; i++) struct_out.string[i] = '0';
-
- // And assign the address of the copy of this structure that I'll be dealing
- // with here to a pointer that I can pass around.
-
- struct_ptr = &struct_out;
-
- // Go get the address of the assembler module's stack. I'll use it to pass
- // data to that stack in the inline .asm code below.
- stack_pntr = get_stack_pntr();
-
- asm{
- sub eax, eax
- mov eax, 3
- mov [save_esp], esp
- mov edx, [stack_pntr]
- mov esp, edx
- push eax
- mov esp, [save_esp]};
-
- // Here is a call to the assembler procedure to print out the value that I
- // I just passed using the inline .asm code above.
-
- print_stack_value();
-
- // Now I'm going to call the assembler function, passing it a pointer to the
- // structure within this module.
-
- fill_struct (struct_ptr);
-
- // The assembler module filled my array with material. I'll add to that here.
-
- strcat(struct_out.string, fill);
-
- // These are the screen printing routines. They look a bit sloppy here,
- // but I wasn't sure how to keep this source any more tidy, and still
- // deal with line wrap when others view this code.
-
-
- cout << "\nThe values below are those passed to the \"C\" structure\n"
- "from within the assembler routine.\n\n";
-
- cout << "char : " << (int)struct_out.c << " to "
- << -((int)struct_out.c) << " ascii character ' ~ '" << endl
-
- << "unsigned char : " << (int)struct_out.uc << endl
-
- << "short : " << struct_out.s << " to "
- << -struct_out.s << endl
-
- << "unsigned short: " << struct_out.us << endl
-
- << "long : " << struct_out.l << " to " << -struct_out.l
- << endl
-
- << "unsigned long : " << struct_out.ul << endl;
- cout << struct_out.string << endl ;
-
- getch ();
- clrscr();
- return 0;
- }
-
- void format()
- {
- clrscr();
- for(int a = 0; a < 8; a++) cout << endl;
- }
-
-
-
-