0
__asm {                         //
        push   eax                  //
            push   ecx              //
            movsx  ecx, temp_char   //
            lea    eax, EKey        //
            call   encryptX         // encrypt the character
            mov    temp_char, al    //
            pop    ecx              //
            pop    eax              //
    }
    EChars[i] = temp_char;          // Store encrypted char in the encrypted chars array
}
return;

// ---------------------------- start of ASM code ---------------------------------------------------------------encryptX:  push ecx                    //push to manipulate
    xchg eax, ecx                   //exchange values in eax and ecx / eax holds old ecx 
    neg  al                         //twos complement least most eax byte (old ecx)
    ror  al, 1                      //rotate right least most byte by 1 of eax 
    xor  al, byte ptr[ecx]          //exlcusive or least most byte against ecx value being pointed at
    push edx                        //push edx onto stack for manipulatio
    mov  edx, eax                   //move eax into edx
    xchg eax, ecx                   //swap values of ecx and eax
    rol  byte ptr[eax], 3           //rotate left the byte being pointed at 3 times
    xor  dl, byte ptr[eax]          //xor the least byte by pointed value in eax
    rol  dl, 2                      //rotate left the least byte in edx by 2
    mov  eax, edx                   //move edx value into eax
    pop  edx                        //pop values out
    pop  ecx                        //pop values out
    ret                             //return
}

i have the task of implementing a standard call in this code - be that cdecl or std call

'mov eax, [ebp+8] // get first parameter that was pushed'

i understand the idea of pushing the pointers location but i am unsure of where i would tell the pointer to look.

be that mov eax, [ebp+4/8/12] or what have you

any help in telling me how i would do this would be greatly appreciated, similarly if one of you kind folk do solve this could an explanation be added

Thanks

  • The only thing machine code level is used for here is rotate. Just use an intrinsic for that and code it all in C++. E.g. https://msdn.microsoft.com/en-us/library/t5e2f3sc.aspx – Cheers and hth. - Alf Jul 12 '15 at 10:29
  • Are you asking how to call another function from your code fragment, or how to make a function that can be called? And are you trying to make a function that works for both calling conventions at once? You seem to be asking something about pointers, but IDK what address you should pass, since you didn't give any info about what you want your pointer to point to. – Peter Cordes Jul 12 '15 at 10:30
  • Also, I have to agree with @Alf. Using `xchg` twice, in a short function with no branches, is a clear sign your code is inefficient. Just have the following instructions use the opposite registers, since none of them implicitly use eax or edx. Also, aren't you loading al with an `xor`, then after an `xchg`, using the same memory address as a destination? And *then* using it as a source? Load your data, work in registers, store when done. – Peter Cordes Jul 12 '15 at 10:36
  • without me trying to fancy the words up like i have (because it probably and seemingly has made it harder to understand sorry) i need to implement either a stdcall or a cdecl convention into my code here ||| peter the code currently isnt meant to be a perfect code as of yet, it needs a few stages of editing and to whittle away the nonsense in there to make in inline and efficient later on – George Cawdron Jul 12 '15 at 10:36
  • What do you ACTUALLY need, though? To get this algorithm to run fast? If so, making a function for it with the overhead of a function call per byte isn't the way to do it. Just write the whole thing in C, and let the compiler inline/optimize. IDK how well compilers do at recognizing shift/OR patterns that can be implemented with a rotate, but if it does badly, use the MSVC intrinsic. – Peter Cordes Jul 12 '15 at 10:40
  • 1
    https://en.wikipedia.org/wiki/X86_calling_conventions tell you how to pass/receive args in a function call, and which regs you can use without saving/restoring. – Peter Cordes Jul 12 '15 at 10:41
  • If you want to operate on a whole buffer or string, doing it with vector registers would probably be a win, even though you'd have to emulate a rotate with a left shift and a right shift of byte elements, then OR the results together. Or maybe not: there's no byte-granularity shifts, only word (`PSLLW`) and larger, so you'd have to mask off the bits that entered each element from a neighbour before combining with `POR`. – Peter Cordes Jul 12 '15 at 10:57

0 Answers0