How to pass an array reference as a parameter from assembly to a c++ function -


i have 2 separate files in 2 visual studio 2012 projects. 1 masm , other c++. masm program supposed call displayboard function in c++ program , needs pass reference array displaying. can't figure out need make work. program created in entirety c++ program , works way should, supposed majority of coding in masm , have minimal c++ functions, trying these 2 files talking having issues. here skeleton codes masm , c++ files. not sure if c++ file needs main, compile without one. also, board array need declared in c++ file if passed in parameter? think doesn't, not sure. don't know if array parameter referenced correctly in c++ file or not.

assembly code:

title hexassemblytest    (hexassemblytest.asm)     .586     .model flat,c  includelib kernel32.lib includelib irvine32.lib  showboard proto near c, hexboard:sdword  .data  board sdword 121 dup (0)        ;array hold hex board   .code  main proc       invoke showboard, addr board    ;display board  retn main endp  end main 

c++ code:

#include "stdafx.h" #include<iostream> #include<iomanip> #include<windows.h> #include<stack>  using namespace std;  extern "c" void showboard(int hex_array[]);    //class dfs definition class dfsalgorithm{  public: int board[121]; //board array   //function display board      void showboard(int hex_array[]){      //code here...      } //other functions...removed     }  };//end dfsalgorithm class 

this error get:

------ build started: project: hexassembly, configuration: debug win32 ------ 1> assembling hexassemblytest.asm... 1>hexassemblytest.obj : error lnk2019: unresolved external symbol _showboard referenced in function _main 1>c:\irvine\examples\assembly hex programming\debug\hexassembly.exe : fatal error lnk1120: 1 unresolved externals ========== build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

i think got working correctly now... modified dfsalgorithm.cpp , dfsalgorithm.h, compiled c++ file , added dfsalsogrithm.obj file project has assembly file. linking, i'm getting "deque iterator not dereferenceable" error message when c++ dfs search runs. worked fine while entire program in c++ i'm not sure need change make work correctly array being accessed assembly file. while stepping through debugger, can see generating adjacency arrays don't think array being accessed...

title hexassemblytest    (hexassemblytest.asm)  include irvine32.inc  printsomething proto c ;displays "goobersx" dfs proto c, color:byte, bptr:ptr dword, index:sdword  pdword typedef ptr dword  .data  bptr pdword board    board sdword 121 dup (0)        ;array hold hex board arrayindex sdword 0         ;variable hold arrayindex     .code  main proc   invoke printsomething   ;tests if masm , c++ talking  start:               call placered       ;prompt user place red stone     call clrscr     call crlf     call showboard      ;redraw board      ;check if there valid path using c++ dfs      push edx     push ebx     push ecx     invoke dfs, 1, addr board, 0    ;color red, board address, arrayindex 0     pop ecx     pop ebx     pop edx     cmp eax,1       ;if eax == 1 winning path found     jne continue        ;eax != 1 no valid path...continue game    ;the rest of code removed brevity  end_game:  retn main endp 

my c++ header file looks this:

c++ header file dfsalgorithm.h  #ifndef dfsalgorithm_h #define dfsalgorithm_h extern "c" void printsomething(); extern "c" int dfs(int color, int hex_array[], int array_index);  #endif 

and c++ cpp file (abbreviated) looks this:

#include "stdafx.h" #include<iostream> #include<stack> #include "dfsalgorithm.h"//include definition of class dfsalgorithm using namespace std;  int adjacency[6]; stack<int> path; //stack hold last hex visited  //test printsomething extern "c" void printsomething(){     cout<<"goobers2014"; }  //first call of dfs starts array_index ==  0 extern "c" int dfs(int color, int hex_array[], int array_index){          if (hex_array[array_index] == color){ //if hex has appropriately colored stone          hex_array[array_index] += 3;    //mark hex visited          path.push(array_index); //push hex onto path stack     }     if ((color == 1 && array_index % 11 == 10 && hex_array[array_index] == 4) ||          (color == 2 && array_index / 11 == 10 && hex_array[array_index] == 5)){      return 1; //winner base case==>reached other side     }  //if visited/unvisited hex has stone of correct color==> search adjacent hexes if ((color == 1 &&  hex_array[array_index] == 4)  ||      (color == 2  &&  hex_array[array_index] == 5)){      //get adjacencies     //removed code brevity         }      /*initialize adjacenthexes zero: if == 0 after 6 adjacencies      checked dead end there no unvisited adjacent hexes      correct color stone*/     int adjacenthexes = 0;           for(int b = 0; b < 6; b++){//traverse adjacency array of passed in index  //if 1 of adjacent hexes has red/blue stone     if((color == 1 && hex_array[adjacency[b]] == color) ||     (color == 2 && hex_array[adjacency[b]] == color )){           adjacenthexes++;    //increment adjacenthexes count          hex_array[adjacency[b]] += 3;   //mark hex visited          path.push(adjacency[b]); //push visited adjacent hex onto path           //recursively call dfs adjacent hex index                 return dfs(color, hex_array,adjacency[b]);                    }             }         //if adjacenthexes == 0 ==> dead-end                 if(adjacenthexes == 0 && path.size() > 1){          path.pop();//pop top hex stack if stack > 1          //recursive call of dfs new top red/blue hex         return dfs(color, hex_array,path.top());                     }         if(adjacenthexes == 0 && path.size() == 1){//back row 0/column 0                      //make array_index = top of path stack       //+++++this line generates "deque iterator not dereferenceable" error++++++++++++++                     array_index = path.top();                      //pop remaining element stack path 0                     path.pop();                 }     }         //if checking red path , path empty         if (color == 1 ){              //search remaining column 0 hexes unvisited red hex              for(array_index ; array_index <= 99; ){                   //recursively call dfs next column 0 hex                 return dfs(color, hex_array, array_index + 11);                 }         }          //if checking blue path , path empty         if (color == 2){          //search remaining row 0 hexes unvisted blue hex             for(array_index ; array_index <= 9; ){                  //recursively call dfs next row 0 hex                 return dfs(color, hex_array, array_index + 1);                 }             }             //traverse hex_array , reset visited hexes unvisited             for(int = 0; < 121; a++){                 if(hex_array[a] >= 4)//if hex has been visited                     hex_array[a] -= 3;//remove visited designation               }          return -1;//return false no path exists  } 

i'm not sure why fails on line set array_index path.top() , pop top off stack because worked fine when entire file in c++ i'm not sure why not working now. assume has how c++ function accessing array_index.

the error tells problem clearly; have no definition of global function showboard.

if expecting dfsalgorithm::showboard's definition, disappointed 2 reasons:

  1. dfsalgorithm::showboard not global function, member function (on instance of dfsalgorithm operate?);
  2. showboard , showboard spelt differently.

as main, c++ file should not define main because assembly file does, , want one such definition across program.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -