News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

UASM and translated SDKRC100

Started by TouEnMasm, July 06, 2020, 03:35:27 AM

Previous topic - Next topic

TouEnMasm

Hello,
I Had a discussion with hutch on that subject here http://masm32.com/board/index.php?topic=8629.0
and after some tests he appeared that he couldn't be more simple.

The New CRT had put me on the trouble but now it is solved :

You have two choice ,link statically on it or link dynamically on it:
Dynamically:
Quote
include sdk64.inc
includelib ucrt.lib
includelib msvcrt.lib
    .data

;----------------------- addded -------------------------------------
rajoutphrase db "500h in base 10",0
output db 100 dup(0)
;-------------------------------------------------------------------
    .code
OPTION PROC:NONE
main proc
    sub rsp, 28h        ; space for 4 arguments + 16byte aligned stack
    invoke _i64toa,500H,addr output,10
    ;---------------- added to show the use of headers with UASM -----
    invoke MessageBox,NULL,addr rajoutphrase,addr output,MB_OK
    ;------------------------------------------------------------------
    invoke ExitProcess,NULL
main endp

    end
Advantage,You get a very little execute (3k) but if you run it on a system without the New CRT,you get "Couldn't find ..."

The twice solution is to link statically:

Quote

include sdk64.inc
includelib libucrt.lib
includelib libcmt.lib
    .data

;----------------------- addded -------------------------------------
rajoutphrase db "500h in base 10",0
output db 100 dup(0)
;-------------------------------------------------------------------
    .code
OPTION PROC:NONE
main proc
    sub rsp, 28h        ; space for 4 arguments + 16byte aligned stack
   invoke _i64toa,500h,addr output,10        
    ;---------------- added to show the use of headers with UASM -----
    invoke MessageBox,NULL,addr rajoutphrase,addr output,MB_OK
    ;------------------------------------------------------------------
    invoke ExitProcess,NULL
main endp
Advantage,The code is in the executable and you avoid the "Couldn't find"
Inconvenient the executable is bigger 44,5Ko


In the two case you need a different couple of LIB and the option "OPTION PROC NONE"

attached are the samples

Fa is a musical note to play with CL

jj2007

Quote from: TouEnMasm on July 06, 2020, 03:35:27 AMAdvantage,You get a very little execute (3k) but if you run it on a system without the New CRT,you get "Couldn't find ..."

Even if you link it statically, you will get that message.

TouEnMasm


This one, to use the same function enclosed in a Library C++.
He show how to create your own library in c++.
In the .cpp
Quote
#include "pch.h"   //given by VS
#include "framework.h"  //given by VS
#include "stdlib.h"      //added

// TODO: Il s'agit d'un exemple de fonction de bibliothèque
// extern "C" is what which allow you to use the function in your .exe

extern "C" char * vc__i64toa(_In_   __int64 _Value, _Pre_notnull_ _Post_z_ char*   _Buffer, _In_  int _Radix)
{
   _i64toa(_Value, _Buffer, _Radix);
   return _Buffer;
};

It is the extern "c" who allow you to use the function in your .exe .The name is not decorated.
in the header:
Quote
#pragma once

#define WIN32_LEAN_AND_MEAN             // Exclure les en-têtes Windows rarement utilisés
#include <corecrt.h>
#include <corecrt_malloc.h>
#include <corecrt_search.h>
#include <corecrt_wstdlib.h>
#include <limits.h>

extern "C" _Success_(return == 0)
char* __cdecl vc__i64toa(
   _In_                   __int64 _Value,
   _Pre_notnull_ _Post_z_ char*   _Buffer,
   _In_                   int     _Radix
);


Fa is a musical note to play with CL

TouEnMasm

Hello,
And now prepare you to have a BIG SURPRISE,this one is a ML64 sample.
I must choose my words but is difficult with my poor english,so i say you it brutally.
I am at an end of my study promise to hutch and here is the conclusion.
The msvcrt.inc with it's exotic defines is not needed,THE NEW CRT can be used with ml64 in a normal way.
I have made the choice of "cproto equ <fastcall>" for the translated SDK in 64 bits,there is a few years ago.
I don't remember how i find this and I have applied it to ML64,it work.Here is the sample who make proof of that.
ALL is build with the VC2017 envirronment 64 ,ml64,link,rc,cvtres..
Quote
include masm64rt.inc
includelib ucrt.lib
includelib msvcrt.lib
cproto equ <fastcall>
_i64toa PROTO cproto :QWORD ,:QWORD ,:DWORD
;vc__i64toa PROTO cproto :QWORD ,:QWORD ,:DWORD

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@@@@@@                              ;@@@@@@
;@@@@@@ here,there is no need of the msvcrt.inc with this sort of defines:   ;@@@@@@
;@@@@@@    externdef __imp__i64toa:PPROC               ;@@@@@@
;@@@@@@      vc__i64toa equ <__imp__i64toa>               ;@@@@@@
;@@@@@@                              ;@@@@@@
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    .data

;----------------------- addded -------------------------------------
rajoutphrase db "500h in base 10",0
output db 100 dup(0)
;-------------------------------------------------------------------
    .code
main proc
   ; ------------- NOT to do -------sub rsp, 28h        ; space for 4 arguments + 16byte aligned stack
    invoke _i64toa,500H,addr output,10 ;It's work ------------------------
    ;---------------- added to show the use of headers with UASM -----
    invoke MessageBox,NULL,addr rajoutphrase,addr output,MB_OK
    ;------------------------------------------------------------------
    invoke ExitProcess,NULL
   ret
main endp

    end

Fa is a musical note to play with CL

jj2007

Quote from: TouEnMasm on July 07, 2020, 06:26:24 PM
include masm64rt.inc
includelib ucrt.lib
includelib msvcrt.lib

Where are these files? I want to test your code.

TouEnMasm

The masm64rt.inc is in the C:\install64  masm64 package downloadable in the subforum dedicated to masm64.
http://masm32.com/board/index.php?topic=7558.0,Take care of the possible update needed.
Others are in the visual studio C++ 2017,there is a 2019 version that you can prefered.
The crt is not in the windows Kit but you can download it also,There is a good speed of transfer with the microsoft site.
Fa is a musical note to play with CL

jj2007

Oh no... you mean the includes and libs and exes etc are spilled all over the place? No way... I prefer it simple :cool:

include \Masm32\MasmBasic\Res\JBasic.inc ; ## console demo, builds in 32- or 64-bit mode with UAsm, ML, AsmC ##
rajoutphrase db "500h in base 10",0
db 100 dup(?)
output db 200 dup(0)
.code
Init    jinvoke _i64toa,500H, addr output,10 ;It's work ------------------------
    jinvoke crt_lstrcat, addr rajoutphrase, Chr$(" - this program was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format.")
    ;---------------- added to show the use of headers with UASM -----
    jinvoke MessageBox,NULL,addr rajoutphrase,addr output,MB_OK
    ;------------------------------------------------------------------
    jinvoke ExitProcess,NULL
EndOfCode


Output: 1280 plus...
500h in base 10 - this program was assembled with UAsm64 in 64-bit format.
500h in base 10 - this program was assembled with ml64 in 64-bit format.

TouEnMasm


If you aren't at your ease with numerous files and declarations,this one is made for you.
You need no other files,except the build environment.
Useful to made Tests and learn how it work.
Fa is a musical note to play with CL

jj2007

"except the build environment" - you are a joker, Yves :tongue:

@echo off
SET PROGNAME=MinimaMasm64

SET PATH=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64;C:\Program Files (x86)\Windows Kits\8.1\bin\x64
SET INCLUDE=C:\install64\include64;c:\install64\macros64;c:\install64\m64lib

SET LIB=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\ucrt\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x64;C:\install64\m64lib
ml64 /c /nologo /Fl /Fr %PROGNAME%.asm
link /NOLOGO /SUBSYSTEM:WINDOWS  /entry:main /LARGEADDRESSAWARE %PROGNAME%.obj
pause