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

nidud

  • Member
  • *****
  • Posts: 1800
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #180 on: April 20, 2019, 05:38:34 AM »
Nidud,

I am a fan of AsmC (and of UAsm), you should know that.
And also a contributor.

Asmc Macro Assembler Version 2.30
Copyright (C) The Asmc Contributors. All Rights Reserved.

Quote
If I see loads of error messages, I make an effort to find a workaround, and often I find one with my decades of expertise.

Tell me about it.

Quote
Now imagine what will be the reaction of somebody exploring (without being already a fan) whether AsmC would be a valid replacement for his recent buggy ML.exe versions. Imagine what that person thinks when seeing endless error messages. This is why features that can and do break existing code should be disabled by default. Fortunately I kept version 23 March 2019, which works perfectly.
Masm compatibility is not the intent but a feature of the software. In order to integrate assembler as an alternative programming language for the future it must be able to interact with the current HLL source base. As this grows in both size and complexity the software and naming convention becomes more important, hence the problem with these names.

nidud

  • Member
  • *****
  • Posts: 1800
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #181 on: April 20, 2019, 06:08:32 AM »
Added a new release: https://github.com/nidud/asmc/releases

New non-reserved words:
c name size type length this mask width low high page title subtitle subttl

The command line switch /Xc is removed: use /Zne instead.
New pragma directive added and OPTION ASMC removed.

.pragma asmc(push, 0)
include some_old_masm_stuff.asm
.pragma asmc(pop)

nidud

  • Member
  • *****
  • Posts: 1800
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #182 on: April 23, 2019, 12:51:51 AM »
Added memory to memory operands.

This currently apply to MOV, ADD, SUB, AND, OR, XOR, CMP, and TEST. It uses AX so this is not allowed in the first operand. The default size is byte if no size is given.

    add [rdx],[rax] -- add byte - RAX trashed..
    mov [rax],[rdx] -- error

Test case.

EDIT

The line queue needed to be flushed in order for this to work with the HLL directives.

foo proc a:ptr, b:ptr

  local c:ptr

    .if ( c == a || c > b )

        nop
    .endif
    ret

foo endp

   0: sub    rsp,0x8
   4: mov    rax,[rsp+0x10]
   9: cmp    [rsp],rax
   d: je     0x1a
   f: mov    rax,[rsp+0x18]
  14: cmp    [rsp],rax
  18: jbe    0x1b
  1a: nop
  1b: add    rsp,0x8
  1f: ret
« Last Edit: April 23, 2019, 03:27:58 AM by nidud »

nidud

  • Member
  • *****
  • Posts: 1800
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #183 on: April 30, 2019, 10:18:58 PM »
Some new changes.

The releases are now deleted. The binaries are added to the source instead (as before):
ASMChttps://github.com/nidud/asmc/raw/master/bin/asmc.exe
ASMC64https://github.com/nidud/asmc/raw/master/bin/asmc64.exe

The Asmc Macro Assembler Reference is now available online.

Directive .CLASSDEF is renamed to .CLASS.
.UNTILAXZ, .UNTILDXZ, and .UNTILBXZ is removed.

nidud

  • Member
  • *****
  • Posts: 1800
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #184 on: May 22, 2019, 11:29:12 PM »
Some new updates.

Added switch /nolib - ignore INCLUDELIB directive.

Made some changes to the .GOTOSW directive.

.GOTOSW1, .GOTOSW2, and .GOTOSW3 are now removed. The new syntax is similar to .BREAK[[(n)]] and .CONTINUE[[(n)]] with an added colon.

    .gotosw[[([[n:]]label)]] [[.IF[[xx]] expression]]

Renamed NOTEST to JMP as .SWITCH argument.

    .switch [[jmp]] [[c|pascal]]

This basically creates a simple jump table if the argument is a register. EAX to EDI in 32-bit + RAX to R15 (-R11) in 64-bit, which also accept EAX to EDI (assuming the upper 32-bits is zero (unsigned value)).

    .switch jmp pascal eax
      .case 0
      .case 1
      .case 2
    .endsw

The jump table do not have a start label so this is added for .gotosw(forward label).

    * @C0003:

In 32-bit a direct jump is used.

    * jmp [eax*4+@C0001-(MIN@C0001*4)]

In 64-bit the jump-address is calculated from the exit-label.

    * lea r11,@C0002
    * sub r11,[rax*8+r11-(MIN@C0001*8)+(@C0001-@C0002)]
    * jmp r11


Pascal entries auto exits.

    * @C0004: ; .case 0
    * jmp @C0002
    * @C0005: ; .case 1
    * jmp @C0002
    * @C0006: ; .case 2
    * jmp @C0002


Jump table entries in 64-bit are distance from case to exit, normally DWORD sized but DQ used here to simplify the jump code.

    * ALIGN 8
    * @C0001:
    * MIN@C0001 equ 0
    * dq @C0002-@C0004
    * dq @C0002-@C0005
    * dq @C0002-@C0006
    * @C0002:


In 32-bit the table entry is an address. If not Pascal (no auto exit) the table is created in the data segment.

    .switch jmp eax
    * @C0003:
    * jmp [eax*4+DT@C0001-(MIN@C0001*4)]
    * @C0004: ; .case 0
    * @C0005: ; .case 1
    * @C0006: ; .case 2
    * @C0001:
    * @C0002:


Using .GOTOSW() forward and backward.

      .case 0
      .gotosw(1) .if cl ; forward jump
      .case 1
      .gotosw(0) .if cl ; direct jump (case 0 exist)
    * @C0004:
    * mov eax,1 ; set switch argument to target
    * test cl, cl
    * jnz @C0003
    * @C0005:
    * test cl, cl
    * jnz @C0004



nidud

  • Member
  • *****
  • Posts: 1800
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #185 on: May 23, 2019, 02:49:01 AM »
Added .CASE [[<label_name>]] -- naming a case label.

In case of access to a case from outside the block:

    jmp name

    .switch eax
      .case 0
      .case 1
      .case <name> 2


nidud

  • Member
  • *****
  • Posts: 1800
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #186 on: May 23, 2019, 04:41:01 AM »
Example on how to use a switch with a named case. In this case two branches are taken (if all goes well). In the 32-bit sample above (.switch jmp eax) only one branch (the first) would be used.
Code: [Select]
;
; build: asmc -win64 -pe asmcraw.asm
;
include windows.inc
include wininet.inc
include stdio.inc
include tchar.inc

    .code

main proc argc:int_t, argv:array_t

  local wsaData:WSADATA
  local hINet:HINTERNET
  local hFile:HANDLE
  local dwNumberOfBytesRead:uint_t
  local size:uint_t
  local fp:LPFILE
  local buffer[1024]:char_t
  local url[128]:char_t
  local file:string_t
  local retval:int_t

    mov retval,1
    jmp entry

    .switch eax

      .case 0
        printf("Downloads files from https://github.com/nidud/asmc/raw/master/bin/\n")
        printf("example: ASMCRAW asmc.chm\n\n")
        .endc
      .case 1
        printf("WSAStartup failed with error: %d\n", eax)
        .endc
      .case 2
        perror("InternetOpen()")
        .endc
      .case 3
        perror("InternetOpenUrl()")
        .gotosw(6)
      .case 4
        perror(file)
        .gotosw(6)

      .case <entry> 5
        .gotosw(0) .if ( ecx != 2 )
        mov file,[rdx+8]
        .gotosw(1) .ifd WSAStartup(2, &wsaData)
        .gotosw(2) .if !InternetOpen("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0)
        mov hINet,rax
        strcat(strcpy(&url, "https://github.com/nidud/asmc/raw/master/bin/"), file)
        .gotosw(3) .if !InternetOpenUrl(hINet, rax, NULL, 0, 0, 0)
        mov hFile,rax
        .gotosw(4) .if !fopen(file, "wb")
        mov fp,rax
        mov size,0
        .while 1
            InternetReadFile(hFile, &buffer, 1024, &dwNumberOfBytesRead)
            .break .if !dwNumberOfBytesRead
            add size,dwNumberOfBytesRead
            fwrite(&buffer, dwNumberOfBytesRead, 1, fp)
        .endw
        fclose(fp)
        mov retval,0
      .case 6
        InternetCloseHandle(hINet)
        WSACleanup()
        .if ( retval == 0 )
            printf("%s %d\n", file, size)
        .endif
    .endsw
    mov eax,retval
    ret

main endp

    end _tstart

nidud

  • Member
  • *****
  • Posts: 1800
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #187 on: May 25, 2019, 09:28:03 PM »
Added .RETURN [[value]] [[.IFxx ...]]

This adds a label on top of the RET directive within a PROC.

In the quest of removing labels the [.REPEAT/.UNTIL 1] frame is used to be able to exit using .BREAK.

    .repeat
        .if error
            mov eax,1
            .break
        .endif
        ...
        xor eax,eax
    .until 1
    ret

Using .RETURN

    .return 1 .if error
    ...
    xor eax,eax
    ret

nidud

  • Member
  • *****
  • Posts: 1800
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #188 on: July 04, 2019, 12:40:08 AM »
Added some changes to 64-bit SWITCH. There was a bug in detecting a memory operand size if a register was used:

    assume rcx:ptr T
    .switch [rcx].Type ; -- assumed to be QWORD.

R10 is removed from the switch code so now only R11 is used.

Added function calls to .RETURN

      .case WM_MOUSEMOVE
        .return [rcx].OnMouseMove(edx, r8, r9)
      .case WM_SYSCHAR
        .return [rcx].OnSysChar(edx, r8, r9)
    ...
    .return [rcx].PostQuit(0) .if !( [rcx].Flags & W_CHILD )
    .return [rbx].PutPath(x, y, edi, rsi) .ifd strlen(rsi) > edi

A new startup module is added for a Console class emulating a message loop. This uses cmain and the link configuration is tcon_64. The name of the class is TWindow and the first instance is the console window.

test.exe:
    asmc64 -nologo $*.asm
    linkw sys tcon_64 file $*

MessageBox sample: The methods preserve RCX.

include twindow.inc

    .code

    assume rcx:window_t

cmain proc hwnd:window_t, argc:int_t, argv:array_t, environ:array_t

    [rcx].Clear(' ')
    [rcx].PutFrame(MTRECT(9, 9, 13, 3), 0, 0x1F)
    [rcx].PutString(10, 10, 0x1E1F, 0, " &Some &Text ")
    [rcx].Show()
    [rcx].MessageBox(MB_YESNOCANCEL or MB_USERICON, "TWindow::MessageBox",
            " MB_YESNOCANCEL or MB_USERICON \n"
            " USERICON == TRANSPARENT " )
    ret

cmain endp

    end

nidud

  • Member
  • *****
  • Posts: 1800
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #189 on: August 31, 2019, 05:26:25 AM »
Added some extension to the .return directive and "mem2mem" operands.

return2.asm

  local b:byte
  local w:word
  local s:sword
  local o:oword
  local h:real2
  local f:real4
  local d:real8
  local q:real16

    .return b ; eax - movzx
    .return w ; eax - movzx
    .return s ; eax - movsx
    .return o ; rdx:rax
    .return h ; ax
    .return f ; xmm0 - movss
    .return d ; xmm0 - movsd
    .return q ; xmm0 - movaps

WORD is sign-extended and bytes zero-extended to EAX.
OWORD is returned in RDX:RAX and floats in XMM0.

Memory operands zero-extends source (second operand) to EAX if byte or word size.

This is used in the parser, codegen, and expreval files now written in assembler.

HSE

  • Member
  • *****
  • Posts: 1148
  • <AMD>< 7-32>
Re: Asmc source and binaries
« Reply #190 on: September 04, 2019, 10:16:01 AM »
This is used in the parser, codegen, and expreval files now written in assembler.

 :thumbsup:

When macro.asm?  :biggrin: :biggrin:

nidud

  • Member
  • *****
  • Posts: 1800
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #191 on: September 05, 2019, 07:13:45 AM »
When macro.asm?  :biggrin: :biggrin:

Well, here's some new macro stuff  :biggrin:

Added float as numeric values for symbols.

    x = 1.0
    y = 2.0
    e = x - y

This is a 16 byte value in memory so to extract sign and exponent:

    exp  = highword(high32(high64(e)))
    sign = .high(exp) and 0x80 shr 7

Floats may also now be printed.

    %echo value: @CatStr(%e)
    %echo exp.:  @CatStr(%exp)
    %echo sign:  @CatStr(%sign)
---
value: -1.0
exp.:  49151
sign:  1

The assigned value is resized according to target:

    mov ax,x    ; REAL2 - 0x3C00
    mov eax,x   ; REAL4 - 0x3F800000
    mov rax,x   ; REAL8 - 0x3FF0000000000000

The quad value:

    mov rdx,HIGH64(x) ; 0x3FFF000000000000
    mov rax,LOW64(x)  ; 0x0000000000000000

HSE

  • Member
  • *****
  • Posts: 1148
  • <AMD>< 7-32>
Re: Asmc source and binaries
« Reply #192 on: September 05, 2019, 07:46:18 AM »
A lot of posibilities that will take some time to learn   :thumbsup:

I'm refering to file translation to asm. Because I maked a rustic "expansor" to preprocessing some conditionals and includes but still not macros  :biggrin:

nidud

  • Member
  • *****
  • Posts: 1800
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #193 on: September 05, 2019, 08:53:56 AM »
A lot of posibilities that will take some time to learn   :thumbsup:

It will simplify MREAL and similar macros I guess.

Quote
I'm refering to file translation to asm. Because I maked a rustic "expansor" to preprocessing some conditionals and includes but still not macros  :biggrin:

Most of the changes goes towards making that easier but some lengthy or more complex code needs to be written to test how this plays out. Macro.c is around 20K, parser.c 100K, and expreval.c 64K so this should be trivial to convert.

HSE

  • Member
  • *****
  • Posts: 1148
  • <AMD>< 7-32>
Re: Asmc source and binaries
« Reply #194 on: September 05, 2019, 10:29:10 AM »
It will simplify MREAL and similar macros I guess.

Translating this:
Code: [Select]
MR_CREATE Fa_facmul
MR_FROM_STR FaNuevo, 0.271
MR_FROM_STR FaOrig, 0.256
MR_DIV Fa_facmul, FaNuevo, FaOrig

MR_CREATE OXFACDc
MR_FROM_STR OXFACDo, 23.0
MR_MUL OXFACDc, OXFACDo, Fa_facmul

ConstantR8 OXFACD, MR_TO_IEEE(<REAl8>,OXFACDc)
to this:
Code: [Select]
x1 = 23.0
x2 = 0.271
x3 = 0.256
x4 = x2/x3
OXFACDc = x1 * x4
ConstantR8 OXFACD, OXFACDc
dont'work or it's not posible with /Zne option?