GIDForums

Go Back   GIDForums > Computer Programming Forums > Assembly Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 24-Mar-2008, 22:04
TransformedBG TransformedBG is offline
Member
 
Join Date: Oct 2006
Posts: 108
TransformedBG is on a distinguished road

Help writing the Assembly in Mix Mode code


I get a little lost in assembly land, im trying to square any negative numbers that a user put into an array of 10 values... I know i need to use a decrementing counter from MAX till it = 0 and then if its negative square it, any help would be great!

CPP / C++ / C Code:
// Description: this program will load 10 16 bit values and replace
//				the negative with their squares then print out the array
//				before and after
//

#include <iostream>
#include <string>

using namespace std;					//Introduces namespace std

const int MAX = 10;						//sets max length to 10
short myArray[MAX]; 

void chcknsqr()
{
	__asm{
			 START: lea ebx, myArray	//loads ptr to array in memory
			  	    mov ecx, MAX		//move count into ecx
					sub	dx, dx
			  
			   TOP: cmp dx,[ebx]	   	    //compares ebx to 0
				    jl  LESSTHAN	    // jump if less than
					add ebx, 2			//up the count on myArray
					loop TOP

		  LESSTHAN: mul [ebx], [ebx]		// square the problem.
					dec ecx
					jmp TOP
		
			  DONE:
	     }
}
int main()
{
	cout << "this program will load 10 16 bit values and replace" << 
		"the negative with their squares then print out the array" <<
		"before and after." << endl;

	for(int i = 0; i < MAX; i++)
	{
		cout << "Please input a value for position " << i << " of the array:";
		cin >> myArray[i];
	}

	cout << "The before values look like: " << endl;
	for(int i = 0; i < MAX; i++)
	{
		cout << "\t\tPositions [" << i << "] is : " << myArray[i] << endl;
	}

	chcknsqr();

	cout << "The after values look like: " << endl;
	for(int i = 0; i < MAX; i++)
	{
		cout << "\t\tPositions [" << i << "] is : " << myArray[i] << endl;
	}
	
	return 0;
}
  #2  
Old 26-Mar-2008, 07:26
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 353
Peter_APIIT is on a distinguished road

Re: Help writing the Assembly in Mix Mode code


I wonder you are using 16 bit 0r 32 bit assembly and How to embed assembly into C code ?

Thanks for your help.
__________________
Linux is the best OS in the world.
  #3  
Old 28-Mar-2008, 11:47
TransformedBG TransformedBG is offline
Member
 
Join Date: Oct 2006
Posts: 108
TransformedBG is on a distinguished road

Re: Help writing the Assembly in Mix Mode code


Quote:
Originally Posted by Peter_APIIT
I wonder you are using 16 bit 0r 32 bit assembly and How to embed assembly into C code ?

Thanks for your help.

CPP / C++ / C Code:
void chcknsqr()   //function call
{
	__asm{
                     //code
	     }
}
  #4  
Old 02-Apr-2008, 05:58
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 353
Peter_APIIT is on a distinguished road

Re: Help writing the Assembly in Mix Mode code


Thanks for your help.
__________________
Linux is the best OS in the world.
 

Recent GIDBlogGoing to Iraq by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to view assembly code for c++ program inevitable Assembly Language 3 17-Dec-2007 17:46
How to sort random access file? wmmccoy0910 C Programming Language 12 04-Sep-2006 03:40
Here it is again! 35% - 40% off For Life! my-e-space Web Hosting Advertisements & Offers 0 20-Apr-2006 14:48
Guidelines for posting requests for help - UPDATED! WaltP C Programming Language 0 21-Apr-2005 02:44

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:18.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.