Author Topic: Asmc source and binaries  (Read 28876 times)

jj2007

  • Member
  • *****
  • Posts: 9686
  • Assembler is fun ;-)
    • MasmBasic
Re: Asmc source and binaries
« Reply #150 on: February 15, 2019, 06:49:19 AM »
Let's hope that nidud is doing OK

Last Active: October 03, 2018. And no recent activity on github :(

nidud

  • Member
  • *****
  • Posts: 1735
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #151 on: February 18, 2019, 11:16:49 PM »
Let's hope that nidud is doing OK. The latest release of asmc can be obtained from :

https://github.com/nidud/asmc

Thanks.

I added the (missing) olectl.inc include file and used your sample as a test case for Asmc. Hope you don't mind.

Code: [Select]
include windows.inc
include olectl.inc

    .code

WinMain proc WINAPI hInstance:HINSTANCE, hPrevInstance:HINSTANCE, lpCmdLine:LPSTR, nCmdShow:int_t

  local pd:PICTDESC, pBitmap:ptr IPicture, pStream:ptr IStream,
        pcbSize:LONG, hGlobal:HGLOBAL, IconAddr:LPVOID, hFile:HANDLE, bWritten:DWORD

    ;; load the test executable and the associated icon

    .if LoadLibrary("C:\\Windows\\regedit.exe")

        ;; initialize the PICTDESC structure

        mov pd.cbSizeofstruct,sizeof(PICTDESC)
        mov pd.picType,PICTYPE_ICON
        mov pd.icon.hicon,LoadIcon(eax, MAKEINTRESOURCE(100))

        ;; create the OLE image

        .ifd OleCreatePictureIndirect(&pd, &IID_IPicture, TRUE, &pBitmap) == S_OK

            ;; create the destination stream to save the icon

            CreateStreamOnHGlobal(NULL, TRUE, &pStream)

            ;; save the icon to the stream

            pBitmap.SaveAsFile(pStream, TRUE, &pcbSize)

            ;; get the address of the icon in memory

            GetHGlobalFromStream(pStream, &hGlobal)
            mov IconAddr,GlobalLock(hGlobal)

            ;; write the icon to disc

            mov hFile,CreateFile("regedit.ico", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0)
            WriteFile(hFile, IconAddr, pcbSize, &bWritten, 0)
            CloseHandle(hFile)

            ;; release the pointers

            pBitmap.Release()
            pStream.Release()

            xor eax,eax

        .endif
    .endif
    ret

WinMain endp

    end

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6659
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Asmc source and binaries
« Reply #152 on: February 19, 2019, 01:18:34 AM »
I am glad you have re-appeared, I thought you must have been ambushed by a blonde.  :biggrin:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

Vortex

  • Member
  • *****
  • Posts: 1996
Re: Asmc source and binaries
« Reply #153 on: February 19, 2019, 04:24:13 AM »
Hi nidud,

I am happy to see you back here in the forum.

Quote
I added the (missing) olectl.inc include file and used your sample as a test case for Asmc. Hope you don't mind.

Many thanks for the new Asmc example :t

TimoVJL

  • Member
  • ***
  • Posts: 432
Re: Asmc source and binaries
« Reply #154 on: February 19, 2019, 06:55:43 AM »
Where is x64 version of quadtoh.asm ?
It don't exist in lib64\math\quad
May the source be with you

nidud

  • Member
  • *****
  • Posts: 1735
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #155 on: February 19, 2019, 08:10:38 AM »
Where is x64 version of quadtoh.asm ?
It don't exist in lib64\math\quad

The half precision (real2) was only implemented in 32-bit. I converted quadtoh.asm to 64-bit (untested) so it should be possible to build a 64-bit version now.

However, the 64-bit version is somewhat experimental and the MS build is bloated and slow compare to the 32-bit. The regression test also create some noise so the 32-bit version is a better option for now.

TimoVJL

  • Member
  • ***
  • Posts: 432
Re: Asmc source and binaries
« Reply #156 on: February 19, 2019, 08:24:02 AM »
Thanks. I test it with PellesC 9.
Code: [Select]
5.350s        asmc.exe
8.221s        asmcpoc64.exe
8.283s        asmcpoc.exe
maybe later is time to check that LIBC.
« Last Edit: February 20, 2019, 12:46:57 AM by TimoVJL »
May the source be with you

TimoVJL

  • Member
  • ***
  • Posts: 432
Re: Asmc source and binaries
« Reply #157 on: February 20, 2019, 06:41:57 AM »
I didn't find this function from libc x64 sources:
extern void __cdecl __va_start(va_list *, ...);
May the source be with you

nidud

  • Member
  • *****
  • Posts: 1735
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #158 on: February 22, 2019, 04:26:08 AM »
I didn't find this function from libc x64 sources:
extern void __cdecl __va_start(va_list *, ...);

Yes, also missing in 16/32-bit.

These functions are not very useful in assembler but I added strtok() to lib64, so now you can tokenize your source code instead  :t

Here's a simple method to snarf up all directives and instructions from the Asmc header files:
Code: [Select]
token struct
count int_t ?
tname string_t ?
token ends

.data

P macro id
  local a
    .const
    a db "&id&",0
    .data
    exitm<a>
    endm

res macro tok, string, type, value, bytval, flags, cpu, sflags
    token <0, P(string)>
    endm
insa macro tok, string, opcls, byte1_info, op_dir, rm_info, opcode, rm_byte, cpu, prefix, evex
    token <0, P(string)>
    endm
insx macro tok, string, opcls, byte1_info, op_dir, rm_info, opcode, rm_byte, cpu, prefix, evex, flgs
    token <0, P(string)>
    endm
insv macro tok, string, opcls, byte1_info, op_dir, rm_info, opcode, rm_byte, cpu, prefix, evex, flgs, rex
    token <0, P(string)>
    endm
insn macro tok, suffix, opcls, byte1_info, op_dir, rm_info, opcode, rm_byte, cpu, prefix, evex
    endm
insm macro tok, suffix, opcls, byte1_info, op_dir, rm_info, opcode, rm_byte, cpu, prefix, evex
    endm
avxins macro op, tok, string, cpu, flgs
    token <0, P(string)>
    endm
OpCls macro op1, op2, op3
    exitm<0>
    endm

table label token
include ../../asmc/src/h/mktok/directve.inc
include ../../asmc/src/h/instruct.h

TOKENCOUNT equ ($ - table) / sizeof(token)

TimoVJL

  • Member
  • ***
  • Posts: 432
Re: Asmc source and binaries
« Reply #159 on: February 22, 2019, 04:47:32 AM »
I just test code with PellesC.
Is the asmc64.exe 2.28.16 available for compiling asm-files using option -r ?
May the source be with you

nidud

  • Member
  • *****
  • Posts: 1735
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #160 on: February 22, 2019, 05:26:29 AM »
Is the asmc64.exe 2.28.16 available for compiling asm-files using option -r ?

No, there is currently only one release (2.28.13), so you need to build it from the updated source.

TimoVJL

  • Member
  • ***
  • Posts: 432
Re: Asmc source and binaries
« Reply #161 on: February 22, 2019, 08:08:32 AM »
OK.
A commandline problem (*.asm) solved with this change:
Code: [Select]
char *strfcat( char *buffer, const char *path, const char *file )
{
    char *p = buffer;

    if ( path && *path) {
do {
    *p++ = *path++;
} while( *path );
    } //else {
// while( *p ) p++;
//    }
    if ( p != buffer && *(p-1) != '/' && *(p-1) != '\\' )
#ifdef __UNIX__
*p++ = '/';
#else
*p++ = '\\';
#endif
    do {
*p++ = *file;
    } while ( *file++ );
    return buffer;
}

int __cdecl main(void)
{
char buf[256];
char *fname = strfcat(buf, "", "*.asm");
puts(fname);
return 0;
}
EDIT: PellesC 9 x64 optimizer fails in parser.c with ParseLine() :(
Time to give up :(
« Last Edit: February 22, 2019, 07:45:06 PM by TimoVJL »
May the source be with you

nidud

  • Member
  • *****
  • Posts: 1735
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #162 on: March 06, 2019, 02:49:09 AM »
I also implemented defined() as a inline directive suggested by Biterider. This will only work if defined is not, well, defined.

Test case:
Code: [Select]
    .486
    .model flat
    .code

__SYM__ equ 3

if defined(__SYM__) and __SYM__ ge 3
    mov eax,__SYM__
else
    .err <error>
endif

undef __SYM__

if defined(__SYM__) and __SYM__ ge 3
    .err <error>
else
    nop
endif

__SYM__ equ 2
if defined(__SYM__) and __SYM__ eq 2
    mov eax,__SYM__
else
    .err <error>
endif

undef __SYM__
__SYM__ equ <>
if defined(__SYM__)
    nop
else
    .err <error>
endif

if defined(__SYM2__) or defined(__SYM__)
    nop
else
    .err <error>
endif

if not defined(__SYM2__) and defined(__SYM__)
    nop
else
    .err <error>
endif

if defined(__SYM2__) and not defined(__SYM__)
    .err <error>
else
    nop
endif

    end

Source code for the implementation.

The source above returns 1 if defined, should be -1.
Code: [Select]
_A_ equ 1
if not defined(_A_)
_A_ equ 2
endif
This is corrected in v2.28.17

nidud

  • Member
  • *****
  • Posts: 1735
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #163 on: March 16, 2019, 10:50:04 PM »
Seems like Raymond Chen is on to us:
Quote
Even if your assembly language code doesn’t call any Windows APIs, you still have to follow the ABI

You’re not off by yourself; you’re part of a society.

So, I made some improvements for the FRAME directive, allowing optimization and use of the /Cs switch. This should synchronize the prologue and epilogue handling for FRAME/NOFRAME options.

Be interesting to use the unwind information to actually unwind an exception.

Quote
Certainly you have more flexibility in assembly language, but that doesn’t give you freedom to do anything you want.

 :biggrin:

Well, on that note lets use some flexibility,
try popping the whole circus off the stack instead:
Code: [Select]
include stdio.inc

    .code

__try proc frame:__except use:byte

  local x:dword

    xor eax,eax
    mov [rax],al
    ret

__except:
    mov eax,-1
    ret

__try endp

main proc frame:__except

    .ifd ( __try(1) == -1 )

        printf("__except(): %d\n", eax)
    .endif
    ret

__except: ;; (EXCEPTION_EXECUTE_HANDLER) {
          ;; Intercept ANY exception from main()
          ;; Deliberately do nothing
    retn  ;; }

main endp

    end

jj2007

  • Member
  • *****
  • Posts: 9686
  • Assembler is fun ;-)
    • MasmBasic
Re: Asmc source and binaries
« Reply #164 on: March 17, 2019, 12:39:01 AM »
Chen has written lots of goodies, but ...
Quote
If the system thinks that you are a lightweight leaf function, but you didn’t follow the rules for a lightweight leaf function, then bad things will happen
... here he exaggerates. "Bad things"? Will the computer throw tomatoes at me? Electrical shocks through the touchpad or the mouse? Or will it just show me that greyish standard box "your program has stopped functioning" that I see so often when running "professional" Windows software? Re exception handlers: Yes, exceptionally lousy coders need them. We don't.