Hi, I currently have an task to complete on Assembly.

I have been supplid the following code

#include <iostream>		//for cin >> and cout <<
#include <conio.h>		//for _kbhit
using namespace std;

#define dollarchar '$'

const int maxchars = 5; // you may alter this but it should be at least 5!

//----------------------------- Subroutines C++ ----------------------------------------------------------

void get_char (char& a_character)		// check your ASCII tables to help make sense of this
{	cin >> a_character;
	while ((a_character < '0' | a_character > 'z') && (a_character != dollarchar))
	{	cout << "Alphanumeric characters only please > ";
		cin >> a_character;
	}
}

void show_char (char a_character)
{
	cout << a_character ;
}


void show_string (char a_string[], int upto_here)
{	//cout << "\n\n";
	int i;
	for (i=0; i<upto_here; i++)
		cout << a_string [i];
	cout << "\n\n";
}

//----------------------------- End of Subroutines -------------------------------------------------------------


int main()
{
	int  charcount;
	char EKey;													// Encryption key,
	char SChars[maxchars], EChars[maxchars], DChars[maxchars];	// Source, Encrypted, Decrypted character string
	char s_char, e_char, d_char;								// source, encrypted, decrypted char

	cout << "\nPlease enter your Encryption Key (EKey) letter then <enter>: ";
	cin  >> EKey;
	cout << "\nNow enter upto " << maxchars << " alphanumeric characters and press enter:\n\n";

	charcount = 0;
	get_char (s_char);					    // Get a character from user

	while ((charcount < maxchars) && (s_char != dollarchar))
	{
		SChars [charcount] = s_char;		// Store in the source chars array

		__asm {				// call the encrypt subroutine
			push   eax						// save register values on stack to be safe
			push   ecx
			movsx  ecx,s_char				// enregister the source character and encryption key
			movsx  eax,EKey
			call   encrypt11					// encrypt (s_char,e_char,EKey);
			mov    e_char,al				// only need lower half of EAX to return result to e_char
			pop    ecx						// restore original register values from stack
			pop	   eax
		}

		EChars [charcount] = e_char;		// Store in the encrypted chars array
		get_char (s_char);					// Get next character from user
		charcount++;						// Maintain count of characters entered
	}

	cout << "Original source string = ";
	show_string (SChars, charcount);
	cout << "Encrypted string =       ";
	show_string (EChars, charcount);
	while ( !_kbhit());						//hold the screen until a key is pressed
	return (0);

//----------------------------- ASM Subroutines ------------------------------------------------------

__asm {

// Encrypt subroutine. You should paste in the encryption routine you've been allocated from BB and
// overwrite this initial version. Leave on the appended number but change the 'call' above to use the
// correct 'encryptnn' label.
// Inputs: register EAX = Encryption Key value, and ECX = the character to be encrypted.
// Outputs: register EAX = the encrypted value of the source character.

Encrypt11:
		push edx  
           		push ecx  
           		ror al,1   
           		ror al,1   
           		ror al,1   
           		mov edx,eax     
           		pop eax     
           		sub eax,0x02   
           		xor eax,edx   
           		rol al,1       
           		rol al,1   
           		rol al,1   
          		 pop edx     
           		ret  	
}

//----------------------------- End of ASM Subroutines -----------------------------------------------

} // end of whole program

First of all I need to figure out what the code after Encrpyt11 does.

Second, I need to implement the standard call method. I need to alter the program so that it adopts the accepted C++ standard calling procedure (i.e. ‘_stdcall’) for passing parameters into the subroutine. This uses the stack and the EBP register rather than the general purpose registers.

And thirdly, I need to add a decryption subroutine written in assembler that reverses the encryption. Also, add C++ code to put the decrypted char (d_char) into the appropriate array (DChars, already declared in the C++ program).

I've been looking at some guides and tutorials and stuff online but struggling with all three tasks. Any help would be greatly appreciated.

The code after Encrypt11 is one of the old ways of encryption in which u take a encryption key as input from the user... rotate your data to be encrypted and then perform an arithmetic operation like addition and finally xor with the encryption key so as to get the encrypted data which is rotated in opp. way compared to earlier....
At the decryption side the key shud remain the same but whole process shud be reversed ...
sorry i can't be of much help in rest two probs.... :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.