|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Accessing Array from ASM passed from C++?
I've been studying assemby for about a semester now. I am having a horrible time figuring out how to access the data I pass from C++ to ASM. The data 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:
extern "C" int Sort (char [] [20], int, int); Code:
Sort (Strings, 10, 20); cout << "Sorted Strings are" << endl; for (i = 0; i < 10; i++) cout << '\t' << Strings [i] << endl; You can probably ignore my code, but I figure I would put it anyways; Code:
_Sort proc push ebp mov ebp, esp push edi mov eax, [ebp+08] mov array_ptr, eax mov eax, [ebp+12] mov array_length, eax mov eax, [ebp+16] mov bytes_per_line, eax mov eax, array_length cmp eax, 0 ;jump if array has length of 0 jnae EndTRow mov ebx, found_length inc ebx ;add 1 to found_length's sum cmp ebx, eax ;jump if at last row ja EndTrow ; mov found_length, ebx Tcolumns: mov eax, char_position mov ebx, bytes_per_line cmp eax, ebx jnb TRows ... ...and it becomes useless jargon here EndTrow: pop edi pop ebp ret _Sort endp |
|
#2
|
|||
|
|||
|
[ebp+08] point to your array of 20 byte elements right?
Put that in a reg where you can reference it without needing to slosh it back and forth to memory. In this case EDX or EBX will be a good choice. ESI and EDI you'll be using for REP CMPSB's. ECX will be used for the string compare byte counts. so you can access the first array element with say [EDX+0], the next with [EDX+20], then [EDX+40]etc, etc. The LEA instruction can advance you through the array. If EBX held a pointer to some array element do a LEA EBX,[EBX+20] would load EBX with the address of the next element. Alternatively, you could just ADD 20 to EBX. LEA makes it clearer that you're doing address arithmetic though. |
|
#3
|
|||
|
|||
|
Thanks so much for your reply! I have already passed the class with a 'B', I ended up figring out my problem....Thanks again though!
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Other Programming Languages > Accessing Array from ASM passed from C++? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|