Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old November 26th, 2006, 11:47 PM
of1983vintage of1983vintage is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 2 of1983vintage User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 46 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old February 15th, 2007, 11:27 PM
Purple Avenger Purple Avenger is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 271 Purple Avenger User rank is Sergeant (500 - 2000 Reputation Level)Purple Avenger User rank is Sergeant (500 - 2000 Reputation Level)Purple Avenger User rank is Sergeant (500 - 2000 Reputation Level)Purple Avenger User rank is Sergeant (500 - 2000 Reputation Level)Purple Avenger User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 1 h 51 m 31 sec
Reputation Power: 9
[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.

Reply With Quote
  #3  
Old February 18th, 2007, 08:17 PM
of1983vintage of1983vintage is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 2 of1983vintage User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 46 sec
Reputation Power: 0
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!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Accessing Array from ASM passed from C++?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway