Author Topic: Assembly code for a simple function (32 + 64 bit).  (Read 535 times)

mineiro

  • Member
  • ****
  • Posts: 577
Re: Assembly code for a simple function (32 + 64 bit).
« Reply #15 on: May 17, 2020, 11:52:41 PM »
- everybody happy and celebrating the World's best Assembly forum :thumbsup:
Now it's up to you to decide if you want to become a member of the gang :thup:

Can I be from your gang!?
I choose mineiro Capone pseudonym (aka Scarface).
Now we can walk happily and smiling through the enchanted forest.
Camorra gang is on. :greenclp:

Code: [Select]
public upper ;rcx = ptr string
align 16
upper:: ;space or zero, return in rax strlen
mov rax,rcx
align 4 ;nop
@@:
and byte ptr [rax],0dfh
jz @F
add rax,1
jmp @B
@@:
align 4 ;nop
sub rax,rcx
ret
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

Vortex

  • Member
  • *****
  • Posts: 2212
Re: Assembly code for a simple function (32 + 64 bit).
« Reply #16 on: May 18, 2020, 12:31:19 AM »
Hi mineiro,

Quote
Can I be from your gang!?
I choose mineiro Capone pseudonym (aka Scarface).

You are welcome.  :thumbsup:

Kindly, could you test your function with the string below?

Code: [Select]
string1     db 'What_is_the_<matrix>?',0

Siekmanski

  • Member
  • *****
  • Posts: 2130
Re: Assembly code for a simple function (32 + 64 bit).
« Reply #17 on: May 18, 2020, 12:57:00 AM »
Hi mineiro,

Quote
Can I be from your gang!?
I choose mineiro Capone pseudonym (aka Scarface).

You are welcome.  :thumbsup:

Kindly, could you test your function with the string below?

Code: [Select]
string1     db 'What_is_the_<matrix>?',0

Depends on the pill color you take.  :biggrin:
Creative coders use backward thinking techniques as a strategy.

mineiro

  • Member
  • ****
  • Posts: 577
Re: Assembly code for a simple function (32 + 64 bit).
« Reply #18 on: May 18, 2020, 01:04:20 AM »
Hi mineiro,
Kindly, could you test your function with the string below?
Code: [Select]
string1     db 'What_is_the_<matrix>?',0
Yes sir Vortex, that's function was wrong, my fault.
This is whats happen when leaders don't give us bullets or pills. :toothy:
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

Vortex

  • Member
  • *****
  • Posts: 2212
Re: Assembly code for a simple function (32 + 64 bit).
« Reply #19 on: May 22, 2020, 09:40:10 PM »
Explaining why askm's "mov rcx,rax;" works:

Code: [Select]
#include <windows.h>

char* UpperCase(char* szText)
{
    asm(
        "mov    rcx,rax;"
        "sub    rcx,1;"
"1:"
        "add    rcx,1;"
        "cmp    BYTE PTR [rcx],0;"
        "je     2f;"
        "cmp    BYTE PTR [rcx],97;"
        "jb     1b;"
        "cmp    BYTE PTR [rcx],122;"
        "ja     1b;"
        "sub    BYTE PTR [rcx],32;"
        "jmp    1b;"
"2:"
);
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
char msg[]="inline assembly programming";
MessageBox(0,UpperCase(msg),"Hello!",MB_OK);
return 0;
}

Code: [Select]
gcc -c -o InlineAsm.o InlineAsm.c -masm=intel
objconv.exe -fmasm InlineAsm.o Disasm.txt

Code: [Select]
WinMain PROC

push    rbp
mov     rbp, rsp
sub     rsp, 64
mov     qword ptr [rbp+10H], rcx
mov     qword ptr [rbp+18H], rdx
mov     qword ptr [rbp+20H], r8
mov     dword ptr [rbp+28H], r9d
mov     rax, 6120656E696C6E69H 
mov     qword ptr [rbp-20H], rax
mov     rax, 20796C626D657373H 
mov     qword ptr [rbp-18H], rax
mov     rax, 6D6D6172676F7270H 
mov     qword ptr [rbp-10H], rax
mov     dword ptr [rbp-8H], 6778473
lea     rax, ptr [rbp-20H]
mov     rcx, rax
call    UpperCase

Above, lea rax, ptr [rbp-20H] points to the string to be converted to uppercase. Naturally, what is correct is to leave intact rcx at the beginning of the inline function UpperCase.