1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Accessing Array from ASM passed from C++?

Discussion in 'Assembly Language Programming (ALP) Forum' started by of1983vintage, Nov 27, 2006.

  1. of1983vintage

    of1983vintage New Member

    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
     

Share This Page