News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Assembly code for a simple function (32 + 64 bit).

Started by zmau, March 25, 2020, 12:22:56 AM

Previous topic - Next topic

mineiro

Quote from: jj2007 on May 17, 2020, 08:14:35 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:


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

Hi mineiro,

QuoteCan 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?

string1     db 'What_is_the_<matrix>?',0

Siekmanski

Quote from: Vortex on May 18, 2020, 12:31:19 AM
Hi mineiro,

QuoteCan 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?

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

Quote from: Vortex on May 18, 2020, 12:31:19 AM
Hi mineiro,
Kindly, could you test your function with the string below?
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

Explaining why askm's "mov rcx,rax;" works:

#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;
}


gcc -c -o InlineAsm.o InlineAsm.c -masm=intel
objconv.exe -fmasm InlineAsm.o Disasm.txt


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.