x86 Assembler stdcall/cdecl

hi, here is the program i have so far. i need to implement an stdcall/cdecl subroutine call convention. could someone please show me how to do this, im really confused.

#include <conio.h> // for kbhit
#include <iostream> // for cin >> and cout <<
#include <iomanip> // for fancy output
using namespace std;

#define MAXCHARS 6 // feel free to alter this, but 6 is the minimum
#define dollarchar '$' // string terminator

char OChars[MAXCHARS],
EChars[MAXCHARS],
DChars[MAXCHARS] = "Soon!"; // Global Original, Encrypted, Decrypted character strings

//----------------------------- C++ Functions ----------------------------------------------------------

void get_char(char& a_character)
{
cin >> a_character;
while (((a_character < '0') | (a_character > 'z')) && (a_character != dollarchar))
{
cout << "Alphanumeric characters only, please try again > ";
cin >> a_character;
}
}
//-------------------------------------------------------------------------------------------------------------

void get_original_chars(int& length)
{
char next_char;
length = 0;
get_char(next_char);

while ((length < MAXCHARS) && (next_char != dollarchar))
{
OChars[length++] = next_char;
get_char(next_char);
}
}

//---------------------------------------------------------------------------------------------------------------
//----------------- ENCRYPTION ROUTINES -------------------------------------------------------------------------

void encrypt_chars(int length, char EKey)
{
char temp_char; // char temporary store

for (int i = 0; i < length; i++) // encrypt characters one at a time
{
temp_char = OChars[i]; //
__asm { //
push eax // save register values on stack to be safe
push ecx //
//
movzx ecx, temp_char // set up registers (Nb this isn't StdCall or Cdecl)
lea eax, EKey //
call encrypt3 // encrypt the character
mov temp_char, al //
//
pop ecx // restore original register values from stack
pop eax //
}
EChars[i] = temp_char; // Store encrypted char in the encrypted chars array
}
return;


// Encrypt subroutine. You should paste in the encryption routine you've been allocated from Bb and
// overwrite this initial, simple, version. Ensure you change the ‘call’ above to use the
// correct 'encryptnn' label where nn is your encryption routine number.
// Inputs: register EAX = 32-bit address of Ekey,
// ECX = the character to be encrypted (in the low 8-bit field, CL).
// Output: register EAX = the encrypted value of the source character (in the low 8-bit field, AL).
__asm {

encrypt3: push edx //push
push ecx //back the character to be encrypted up onto the stack
push eax //back the character to be encrypted up onto the stack
movzx eax, byte ptr[eax] //copy the character with zero extend onto the stack
rol al, 1 //rotate left
rol al, 1 //rotate left
rol al, 1 //rotate left
mov edx, eax //move
pop eax //pop from stack memory
mov byte ptr[eax], dl //move
pop ecx //pop from stack memory
xor ecx, edx //bitwise exclusive OR
mov eax, ecx //move/copy
ror al, 1 //rotate right
ror al, 1 //rotate right
ror al, 1 //rotate right
pop edx //pop from stack memory
ret //return form subroutine

//--- End of Assembly code
}
// end of encrypt_chars function
//---------------------------------------------------------------------------------------------------------------




//---------------------------------------------------------------------------------------------------------------
//----------------- DECRYPTION ROUTINES -------------------------------------------------------------------------
//
void decrypt_chars(int length, char EKey);
{
/*** to be written by you ***/

return;
}
// end of decrypt_chars function
//---------------------------------------------------------------------------------------------------------------





int main(void)
{
int char_count; // The number of actual characters entered (upto MAXCHARS limit).
char EKey; // Encryption key.

cout << "\nPlease enter your Encryption Key (EKey) letter: "; get_char(EKey);

cout << "\nNow enter upto " << MAXCHARS << " alphanumeric characters:\n";
get_original_chars(char_count);
cout << "\n\nOriginal source string = " << OChars << "\tHex = ";
for (int i = 0; i<char_count; i++) cout << hex << setw(2) << setfill('0') << ((int(OChars[i])) & 0xFF) << " ";

encrypt_chars(char_count, EKey);
cout << "\n\nEncrypted string = " << EChars << "\tHex = ";
for (int i = 0; i<char_count; i++) cout << ((int(EChars[i])) & 0xFF) << " ";

decrypt_chars(char_count, EKey);
cout << "\n\nDecrypted string = " << DChars << "\tHex = ";
for (int i = 0; i<char_count; i++) cout << ((int(DChars[i])) & 0xFF) << " ";

cout << "\n\nPress a key to end...";
while (!_kbhit()); //hold the screen until a key is pressed
return (0);


} // end of whole encryption/decryption program --------------------------------------------------------------------
Topic archived. No new replies allowed.