The MASM Forum

64 bit assembler => UASM Assembler Development => Topic started by: daydreamer on February 06, 2020, 08:00:25 PM

Title: cant I just replace ml with uasm?
Post by: daydreamer on February 06, 2020, 08:00:25 PM
isnt it possible to just replace ml with uasm?
I took a look at uasm and its packed with features and latest opcodes
Title: Re: cant I just replace ml with uasm?
Post by: johnsa on February 06, 2020, 08:26:57 PM
By and large yes..

There are a few caveats here and there, but you should expect 99% compatibility between the two.
Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on February 06, 2020, 09:10:59 PM
it works beside link error,cant find
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
project2020.exe : fatal error LNK1120: 1 unresolved externals
_
tried polink too, it reports error '.obj' file not found

Title: Re: cant I just replace ml with uasm?
Post by: LiaoMi on February 06, 2020, 09:55:10 PM
Quote from: johnsa on February 06, 2020, 08:26:57 PM
By and large yes..

There are a few caveats here and there, but you should expect 99% compatibility between the two.

Hi johnsa,

there was a major update on github, should we test the last master ?!
Title: Re: cant I just replace ml with uasm?
Post by: jj2007 on February 06, 2020, 10:43:53 PM
I build everything with UAsm by default, and occasionally check if it's still working with MASM and AsmC.  Beware of recent MASM versions, they tend to be buggy and crippled.
Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on February 06, 2020, 11:00:48 PM
Quote from: jj2007 on February 06, 2020, 10:43:53 PM
I build everything with UAsm by default, and occasionally check if it's still working with MASM and AsmC.  Beware of recent MASM versions, they tend to be buggy and crippled.
thats why I go latest uasm,instead of latest masm probably break code,lacking some macros
also likes lots of SSE/avx macros and other things too
also want access to latest SIMD to try to make a faster version of simple scalar version

maybe I should start with a main uasm .asm windows program instead and include my several .inc files into that instead?
Title: Re: cant I just replace ml with uasm?
Post by: LiaoMi on February 06, 2020, 11:53:26 PM
Quote from: daydreamer on February 06, 2020, 09:10:59 PM
it works beside link error,cant find
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
project2020.exe : fatal error LNK1120: 1 unresolved externals
_
tried polink too, it reports error '.obj' file not found

Hi daydreamer,

you use /SUBSYSTEM:WINDOWS, how is your main procedure and entry point defined?
Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on February 07, 2020, 03:56:48 AM
Quote from: LiaoMi on February 06, 2020, 11:53:26 PM
Quote from: daydreamer on February 06, 2020, 09:10:59 PM
it works beside link error,cant find
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
project2020.exe : fatal error LNK1120: 1 unresolved externals
_
tried polink too, it reports error '.obj' file not found

Hi daydreamer,

you use /SUBSYSTEM:WINDOWS, how is your main procedure and entry point defined?
its a masm32 program that worked before,newbie when it comes to uasm,maybe its just "main proc" thats the problem?
or incompatible linker?
start:
after that
call Main
invoke exitprocess,eax

Proc main calls some initializing and calls getmessage/translatemessage/dispatchmessage
end start
lack some Cruntime?
Title: Re: cant I just replace ml with uasm?
Post by: LiaoMi on February 07, 2020, 04:15:10 AM
Quote from: daydreamer on February 07, 2020, 03:56:48 AM
Quote from: LiaoMi on February 06, 2020, 11:53:26 PM
Quote from: daydreamer on February 06, 2020, 09:10:59 PM
it works beside link error,cant find
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
project2020.exe : fatal error LNK1120: 1 unresolved externals
_
tried polink too, it reports error '.obj' file not found

Hi daydreamer,

you use /SUBSYSTEM:WINDOWS, how is your main procedure and entry point defined?
its a masm32 program that worked before,newbie when it comes to uasm,maybe its just "main proc" thats the problem?
or incompatible linker?
start:
after that
call Main
invoke exitprocess,eax

Proc main calls some initializing and calls getmessage/translatemessage/dispatchmessage
end start
lack some Cruntime?

link /entry:start  :rolleyes: should work
Title: Re: cant I just replace ml with uasm?
Post by: Vortex on February 07, 2020, 04:37:18 AM
Hi daydreamer,

Could you post the source code?
Title: Re: cant I just replace ml with uasm?
Post by: morgot on February 07, 2020, 05:14:09 AM
for masm I use .bat files as example
Build gui win32
SET PATH=C:\Masm32\bin

cd $(CURRENT_DIRECTORY)
$(PATH)\ML /nologo -c -coff "$(FULL_CURRENT_PATH)"

$(PATH)\LINK /nologo "$(CURRENT_DIRECTORY)\$(NAME_PART).obj" /SUBSYSTEM:WINDOWS
cmd /c del "$(CURRENT_DIRECTORY)\$(NAME_PART).obj"


and run it from notepad++

Can anybody write such to Uasm?  Just to open in notepad and compile.
Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on February 07, 2020, 05:28:33 AM
Quote from: Vortex on February 07, 2020, 04:37:18 AM
Hi daydreamer,

Could you post the source code?
I have researched uasm example win32 program uses protos for wndproc and winmain,its old masm32 program,which I run .inc files from
I rather want to start with a fresh uasm win32 main program to include them into,than wrestle differences between masm32 includes,libs and ways vs uasm style

Title: Re: cant I just replace ml with uasm?
Post by: jj2007 on February 07, 2020, 05:34:18 AM
Magnus,

There are no significant differences between UAsm and MASM that would require other includes or libraries. They are fully compatible (with rare glitches, mostly because of old MASM bugs).

If you want to test it, just rename ML.EXE to CrappyOldMasm.exe, and UAsm.exe to ML.exe. Then use your IDE or whatever as if nothing happened, and tell us here about the results of your endeavour. Including your source code, of course.
Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on February 07, 2020, 06:33:50 AM
Quote from: jj2007 on February 07, 2020, 05:34:18 AM
Magnus,

There are no significant differences between UAsm and MASM that would require other includes or libraries. They are fully compatible (with rare glitches, mostly because of old MASM bugs).

If you want to test it, just rename ML.EXE to CrappyOldMasm.exe, and UAsm.exe to ML.exe. Then use your IDE or whatever as if nothing happened, and tell us here about the results of your endeavour. Including your source code, of course.

I have found the problem in one of the include files I included,that was originally a program,so I had to remove "end" in this file,this was included before main proc,so now it works,thanks
Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on February 08, 2020, 03:04:12 AM
got trouble with load or use memory variables when using movapd and when using addpd
movapd xmm0,comp1
addpd xmm3,compa

variables look like this
.data
align 16
compa real8 1.0,1.0,1.0,1.0
comp1 real8 2.0,3.0,4.0,5.0

I have read pdf file,so it seems I need to get habit to use macros for loading xmm registers instead and maybe need to use 128bit types instead

funny it works with movaps instead
Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on February 09, 2020, 02:07:51 AM
so in what way should I code this instead,so I can use movapd,well more important to be able to use addpd xmm0,compa,without error?
Title: Re: cant I just replace ml with uasm?
Post by: nidud on February 09, 2020, 02:33:14 AM
deleted
Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on February 09, 2020, 04:24:16 AM
Quote from: nidud on February 09, 2020, 02:33:14 AM
The source is 64-bit (compa) and the target is 128-bit.

    movapd xmm0,xmmword ptr compa ; mov two 64-bit items from compa to xmm0
    addpd  xmm0,xmmword ptr compa

thanks it works
but isnt it also good to get habit to used xmmword type instead of several real8's or real4's?
LOADPD also would be nice to have
Title: Re: cant I just replace ml with uasm?
Post by: nidud on February 09, 2020, 04:45:20 AM
deleted
Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on February 09, 2020, 09:04:06 PM
thanks
maybe use macros like FP8(3.14) could be an option making code more readable too
Title: Re: cant I just replace ml with uasm?
Post by: johnsa on February 12, 2020, 08:29:19 PM
In UASM we have built-in structs already defined for _m128, _m256 which you can use as well.. for other asssemblers you'd have to just create those struct/unions yourself but would still be compatible.
Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on February 12, 2020, 08:37:35 PM
thanks johnsa
for loops wont work as I want
examples,I am used to C syntax
.for(ecx:ecx<Lmaxmem:ecx++)

.for(esi:esi<maxi:esi++)
Title: Re: cant I just replace ml with uasm?
Post by: habran on February 12, 2020, 09:26:38 PM
.for(ecx=Lstartmem:ecx<Lmaxmem:ecx++)
  do something
.endfor


.for(esi=mini:esi<maxi:esi++)
  do something
.endfor

lea esi,mini
.for(:esi<maxi:esi++)
  do something
.endfor

.for(::)
  do something
  .break .if (!eax)
.endfor
Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on February 12, 2020, 10:06:36 PM
thanks Habran
so variable stepping you just use ecx+stepping,for dwords,real4s,real8s,real10's
Title: Re: cant I just replace ml with uasm?
Post by: habran on February 12, 2020, 10:52:41 PM
yes:
rcx+8
ecx+4
rsi+16
ecx--
ecx-4
you can use .continue or .break
.for loop is actually using built in .while but gives you more options to set up variables and increase or decrease counters.
You can use more vars at the same time, like:

.for (rsi=src,rdi=dest,ecx=count:ecx:rsi++,rdi++,ecx--)
   mov al,[rsi]
   mov [rdi],al
.endfor
you get this:

000000013F4851D4 48 8B 35 D5 B6 00 00 mov         rsi,qword ptr [src (013F4908B0h)] 
000000013F4851DB 48 8B 3D CE AE 00 00 mov         rdi,qword ptr [dest (013F4900B0h)] 
000000013F4851E2 8B 0D B0 63 00 00    mov         ecx,dword ptr [count (013F48B598h)] 
000000013F4851E8 EB 0C                jmp         WndProc+3Dh (013F4851F6h) 
000000013F4851EA 8A 06                mov         al,byte ptr [rsi] 
000000013F4851EC 88 07                mov         byte ptr [rdi],al 
000000013F4851EE 48 FF C6             inc         rsi 
000000013F4851F1 48 FF C7             inc         rdi 
000000013F4851F4 FF C9                dec         ecx 
000000013F4851F6 85 C9                test        ecx,ecx 
000000013F4851F8 75 F0                jne         WndProc+31h (013F4851EAh) 
Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on February 13, 2020, 12:20:32 AM
thanks,for loop has always been my favourite loop,and its even better than C version
good,because otherwise before I used bare metal version about the same as code produced by the forloop
Title: Re: cant I just replace ml with uasm?
Post by: jj2007 on February 13, 2020, 01:33:28 AM
I like the Basic one-liners :tongue:
  If_ Filter$(L$(), "MACRO", 1, 4) Then For_ each esi in L$(): PrintLine esi ; list all macros in \Masm32\macros\macros.asm
Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on February 15, 2020, 07:31:49 AM
I broke the code, too many switch,for loops???
http://masm32.com/board/index.php?topic=8222.15 (http://masm32.com/board/index.php?topic=8222.15)
:sad:
Title: Re: cant I just replace ml with uasm?
Post by: habran on February 15, 2020, 01:40:18 PM
If you are not using CSTYLE switch don't use .break
only if you specify  CSTYLE than you need it
option SWITCHSTYLE: CSTYLE

you don't need to use:
option SWITCHSTYLE : ASMSTYLE  because it is a default, which doesn't require .break

I did not test your code but with a quick look I saw that you calculate maxi and maxj, so you don't really know what you get and you don't know if numbers are positive or negative, I would at least check what I get and make sure it doesn't overwrite memory.

I would also avoid using several LOCAL variables in one line, I have noticed that assembler get confused there
I would use instead of:     LOCAL maxi:DWORD,maxj:DWORD,istep:DWORD,jstep:DWORD
LOCAL maxi:DWORD
LOCAL maxj:DWORD
LOCAL istep:DWORD
LOCAL jstep:DWORD

it is also more readable


Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on February 18, 2020, 08:11:11 PM
I have somehow wrecked it
it stopped display assembled in 2 or 3 passes in millisecond
and linker complain about maybe corrupt .obj file
Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on June 14, 2020, 05:40:31 AM
must I change to some unicode as standard to replace
db "this is ascii string",0

dw "this is a unicode string",0 ?
dw "一二三四五六七八九十百千万",0
so line 2 and 3 kind of text can be mixed in api calls that use WCHAR as standard?
Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on March 14, 2022, 07:50:53 AM
I got a strange bug,I call a proc in a different source file and it breaks code,so it suddenly exits
wrong epilog setting?,but if I insert
jmp main
Label:


ret
main:
call label
it works

Title: Re: cant I just replace ml with uasm?
Post by: johnsa on March 16, 2022, 02:38:31 AM
Can you sure a bit more of a complete example?
Title: Re: cant I just replace ml with uasm?
Post by: rsala on March 16, 2022, 07:47:29 PM
Hi daydreamer,

I think you should define unicode strings like this:

dw "t", "h", "i", "s", " ", "i", "s", " ", "a", " ", "u", "n", "i", "c", "o", "d", "e", " ", "s", "t", "r", "i", "n", "g", 0
dw "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "百", "千", "万", 0
Title: Re: cant I just replace ml with uasm?
Post by: johnsa on March 16, 2022, 08:33:03 PM
From the regression test pack in UASM, we have the following test-case/example file:

You should be able to use dw that way to declare WCHAR strings, and with OPTION LITERALS:ON + L prefix you can directly insert them into INVOKEs.

option casemap : none
option frame : auto; generate SEH - compatible prologues and epilogues
option win64 : 11; init shadow space, reserve stack at PROC level
option literals : ON
option evex:1
includelib msvcrt.lib
printf proto : vararg;
includelib kernel32.lib
includelib user32.lib

ExitProcess   proto : dword
MessageBoxExW proto : ptr, : ptr, : ptr, : dword, : word
MessageBoxExA proto : ptr, : ptr, : ptr, : dword, : word
testi proto :dword, :dword
; wprintf proto : QWORD
; swprintf_l proto : QWORD, : QWORD, : word
; swprintf(buf, 100, L"%s", L"Hello\xffff world");
; SetConsoleOutputCP proto : dword
; SetConsoleCP  proto : dword
 

.data
;mylab dq myadr1,myadr2,myadr3
one dw  "Kuća", 0
two dw "abcdef", 0
three dw "Am mulți bani", 0;
four dw "У меня много денег",0
five dw "Sok pénzem van",0
format db "%s", 13, 10, 0
; 0x0419 Russian(ru)    0x19    LANG_RUSSIAN    Russia(RU) 0x01    SUBLANG_RUSSIAN_RUSSIA
; WINAPI MessageBoxEx(
; _In_opt_ HWND    hWnd,
; _In_opt_ LPCTSTR lpText,
; _In_opt_ LPCTSTR lpCaption,
; _In_     UINT    uType,
; _In_     WORD    wLanguageId

    .code
    main proc
   ; mov edx,2
    ;lea    rax,mylab
    ;jmp QWORD PTR[rax+rdx*8]
    invoke MessageBoxExA, 0, "This is a test", "heading", 0, 0
    invoke MessageBoxExW, 0, L"У меня много денег", ADDR one, 0, 0
myadr1:   
    invoke MessageBoxExW, 0, L"لدي الكثير من المال", ADDR four, 0, 0
    invoke MessageBoxExW, 0, L"Kuća", ADDR three, 0, 0
    invoke MessageBoxExW, 0, L"Imam puno novaca", ADDR two, 0, 0
    invoke MessageBoxExW, 0, L"我有很多钱", ADDR three, 0, 0
    invoke MessageBoxExW, 0, L"Имам пуно новаца", ADDR five, 0, 0
.data
mylab dq myadr1,myadr2,myadr3
.code

myadr2:
    invoke MessageBoxExW, 0, L"Sok pénzem van", ADDR three, 0, 0
    invoke MessageBoxExW, 0, L"Am mulți bani", ADDR three, 0, 0
    invoke MessageBoxExW, 0, L"Tengo mucho dinero", ADDR three, 0, 0
    invoke MessageBoxExW, 0, L"Tengo mucho dinero", ADDR three, 0, 0
myadr3:
    invoke MessageBoxExW, 0, L"Kuća", ADDR three, 0, 0
    invoke MessageBoxExW, 0, L"Sok pénzem van", ADDR three, 0, 0
    invoke MessageBoxExW, 0, L"Am mulți bani", ADDR three, 0, 0
    ;invoke printf, addr format, lengthof three
    ;invoke printf, addr format, lengthof four
    invoke ExitProcess, 0
    ret
    main endp
    end
Title: Re: cant I just replace ml with uasm?
Post by: jj2007 on March 16, 2022, 09:31:35 PM
Quote from: daydreamer on June 14, 2020, 05:40:31 AM
must I change to some unicode as standard to replace
db "this is ascii string",0

dw "this is a unicode string",0 ?
dw "一二三四五六七八九十百千万",0
so line 2 and 3 kind of text can be mixed in api calls that use WCHAR as standard?

Posting code that doesn't assemble in a very old stale thread is a bad habit, daydreamer :cool:

include \masm32\MasmBasic\MasmBasic.inc         ; download (http://masm32.com/board/index.php?topic=94.0)
  Init
  uMsgBox 0, "一二三四五六七八九十百千万", "This is Unicode, and it works:", MB_OK
EndOfCode
Title: Re: cant I just replace ml with uasm?
Post by: daydreamer on March 29, 2022, 10:17:21 PM
Quote from: johnsa on March 16, 2022, 02:38:31 AM
Can you sure a bit more of a complete example?
I put lots of pushes after label and pops before ret and it works,could been the problem,main loop uses most registers and call proc