Free2Code
 
Time: 2009-01-05, 11:44pm
Accessing Array from ASM passed from C++?
Subject: Accessing Array from ASM passed from C++?  ·  Posted: 2006-11-26, 05:21pm
Rank: ? (1)
Member #: 29207
I've been studying assemby for about a semester now. I am having a horrible time figuring out how to access the array of data I pass from C++ to ASM. It is a array of strings which I will have to sort in ASM and return a sorted array back to C++. The biggest problem I am having is accessing the data itself. The array is being passed at [ebp+8]... Any help with this is appreciated.

This is the C++ code I'm working with;
Code:
  1. extern "C" int Sort (char [] [20], int, int);


Code:
  1. Sort (Strings, 10, 20);
  2.     cout << "Sorted Strings are" << endl;
  3.     for (i = 0; i < 10; i++)
  4.         cout << '\t' << Strings [i] << endl;


You can probably ignore my code, but I figure I would put it anyways;
Code:
  1. _Sort proc
  2.         push        ebp
  3.         mov            ebp, esp 
  4.         push        edi
  5.         
  6.         mov            eax, [ebp+08]
  7.         mov            array_ptr, eax
  8.         mov            eax, [ebp+12]
  9.         mov            array_length, eax
  10.         mov            eax, [ebp+16]
  11.         mov            bytes_per_line, eax
  12.     
  13.         mov            eax, array_length
  14.         cmp            eax, 0            ;jump if array has length of 0
  15.         jnae        EndTRow
  16.         
  17.         mov            ebx, found_length
  18.         inc            ebx            ;add 1 to found_length's sum
  19.         cmp            ebx, eax    ;jump if at last row
  20.         ja            EndTrow
  21. ;        mov            found_length, ebx
  22. Tcolumns:
  23.         mov            eax, char_position
  24.         mov            ebx, bytes_per_line
  25.         cmp            eax, ebx
  26.         jnb            TRows
  27. ... ...and it becomes useless jargon here
  28. EndTrow:
  29.         pop            edi        
  30.         pop            ebp
  31.         ret
  32. _Sort endp


 
  Reply to this ·  Post link ·  Top
Subject: Re: Accessing Array from ASM passed from C++?  ·  Posted: 2006-12-23, 09:55pm
Rank: ? (119)
Member #: 28292
You should put the pointer passed to stack in a register. For example edx. For addressing of an element of array of chars use e.g. byte ptr [edx + ecx]. In ecx is the number of the element you want to use.

 
  Reply to this ·  Post link ·  Top

Pages: 1

Please login or register to post a reply.

icons