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

Vortex

  • Member
  • *****
  • Posts: 2283
Re: Asmc source and binaries
« Reply #210 on: December 06, 2019, 04:34:03 AM »
Hi nidud,

Thanks for the info :thumbsup:

2B||!2B

  • Member
  • **
  • Posts: 75
Re: Asmc source and binaries
« Reply #211 on: December 06, 2019, 03:00:43 PM »
If you look at the _aligned_malloc test you'll see it uses SYSTEM which is a link macro defined in linkw.lnk.

makefile

_aligned_malloc.exe:
    asmc64 $*.asm
    linkw system con_64 file $*

con_64:

# Win64 console application
system begin con_64
    option  quiet
    libpath %ASMCDIR%\lib\amd64
    library libc,kernel32,user32
    symt    cstart
    format  windows pe ^
    runtime console=4.0
end

cstart

mainCRTStartup proc frame

   _initterm( &__xi_a, &__xi_z )
   exit( main( __argc, __argv, _environ ) )

mainCRTStartup endp

   end cstart


C:\masm32\asmc\bin\linkw.exe system gui_64 file Test.obj
Warning! W1115: system block gui_64: environment name ASMCDIR not found
Warning! W1008: cannot open libc.lib : No such file or directory
Warning! W1008: cannot open kernel32.lib : No such file or directory
Warning! W1008: cannot open user32.lib : No such file or directory
Warning! W1008: cannot open gdi32.lib : No such file or directory
Error! E2028: WinStart is an undefined reference
Error! E2028: printf is an undefined reference

The system gui_64 uses WinStart so con_64 should be used here and ASMCDIR needs to be set correctly. The shell (DZ) sets ASMCDIR and so do also MAKE but LINKW do not.

Something like this:

    set ASMCDIR=C:\masm32\asmc
    C:\masm32\asmc\bin\linkw.exe system con_64 file Test.obj


start:
main proc
...
main endp

    end start

You using a startup module here so start has to be removed.

I have fixed the error ASMCDIR not found. The set ASMCDIR=C:\masm32\asmc does not work.
I had to add it manually through Environment variables. However, the libraries still not found.

Code: [Select]
C:\masm32\bin\asmc\LINKW.EXE system con_64 file "C:\64Bit test\64Bit\64Bit.obj"
Warning! W1008: cannot open kernel32.lib : No such file or directory
Warning! W1008: cannot open user32.lib : No such file or directory
Warning! W1008: cannot open ntdll.lib : No such file or directory
Warning! W1008: cannot open advapi32.lib : No such file or directory
Warning! W1008: cannot open gdi32.lib : No such file or directory
Warning! W1008: cannot open version.lib : No such file or directory
Warning! W1008: cannot open mpr.lib : No such file or directory
Warning! W1008: cannot open winmm.lib : No such file or directory
Warning! W1008: cannot open netapi32.lib : No such file or directory
Warning! W1008: cannot open rpcrt4.lib : No such file or directory
Warning! W1008: cannot open shell32.lib : No such file or directory
Warning! W1008: cannot open Ws2_32.lib : No such file or directory
Warning! W1008: cannot open comdlg32.lib : No such file or directory
Warning! W1008: cannot open uuid.lib : No such file or directory
Warning! W1008: cannot open ole32.lib : No such file or directory
Warning! W1008: cannot open oleaut32.lib : No such file or directory
Error! E2028: GetModuleFileNameA is an undefined reference
Error! E2028: GetCommandLineA is an undefined reference
Error! E2028: WideCharToMultiByte is an undefined reference
Error! E2028: GetProcessHeap is an undefined reference
Error! E2028: HeapAlloc is an undefined reference
Error! E2028: HeapFree is an undefined reference
Error! E2028: GetEnvironmentStringsA is an undefined reference
Error! E2028: FreeEnvironmentStringsA is an undefined reference
Error! E2028: ExitProcess is an undefined reference
Error! E2028: GetLastError is an undefined reference
Error! E2028: CloseHandle is an undefined reference
Error! E2028: SetFilePointer is an undefined reference
Error! E2028: WriteFile is an undefined reference
Error! E2028: SetErrorMode is an undefined reference
Error! E2028: GetStdHandle is an undefined reference
Error! E2028: GetProcAddress is an undefined reference
Error! E2028: GetModuleHandleExW is an undefined reference
Error! E2028: SetFilePointerEx is an undefined reference
file libc.lib(stdlib\__argv.asm): undefined symbol GetCommandLineA
file libc.lib(stdlib\__argv.asm): undefined symbol GetModuleFileNameA
file libc.lib(stdio\_output.asm): undefined symbol WideCharToMultiByte
file libc.lib(malloc\malloc.asm): undefined symbol GetProcessHeap
file libc.lib(malloc\malloc.asm): undefined symbol HeapAlloc
file libc.lib(malloc\malloc.asm): undefined symbol HeapFree
file libc.lib(stdlib\__setenvp.asm): undefined symbol GetEnvironmentStringsA
file libc.lib(stdlib\__setenvp.asm): undefined symbol FreeEnvironmentStringsA
file libc.lib(crtl\__crtExitProcess.asm): undefined symbol ExitProcess
file libc.lib(io\_close.asm): undefined symbol CloseHandle
file libc.lib(io\_close.asm): undefined symbol GetLastError
file libc.lib(stdio\_flsbuf.asm): undefined symbol SetFilePointer
file libc.lib(io\_write.asm): undefined symbol WriteFile
file libc.lib(io\_write.asm): undefined symbol GetLastError
file libc.lib(io\_ioinit.asm): undefined symbol GetStdHandle
file libc.lib(io\_ioinit.asm): undefined symbol SetErrorMode
file libc.lib(crtl\__crtCorExitProcess.asm): undefined symbol GetModuleHandleExW
file libc.lib(crtl\__crtCorExitProcess.asm): undefined symbol GetProcAddress
file libc.lib(io\_lseeki64.asm): undefined symbol SetFilePointerEx
file libc.lib(io\_lseeki64.asm): undefined symbol GetLastError

AW

  • Member
  • *****
  • Posts: 2583
  • Let's Make ASM Great Again!
Re: Asmc source and binaries
« Reply #212 on: December 06, 2019, 06:50:20 PM »
This builds fine with a notepad++ script. It simply sets 3 environment variables and unsets them in the end leaving the system clean. This is important because some of these variables have names used elsewhere. It is not nice ASMC trying to hijack them, in addition to hijack some well known name extension like .cmd and even the shortcut extension .lnk. Please invent your own!


nidud

  • Member
  • *****
  • Posts: 1980
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #213 on: December 06, 2019, 10:23:16 PM »
However, the libraries still not found.

Maybe they don't exist?
Should be in C:\masm32\asmc\lib\amd64
There's a MAKEFILE there if not.

2B||!2B

  • Member
  • **
  • Posts: 75
Re: Asmc source and binaries
« Reply #214 on: December 07, 2019, 03:23:13 PM »
However, the libraries still not found.

Maybe they don't exist?
Should be in C:\masm32\asmc\lib\amd64
There's a MAKEFILE there if not.

This is what i have in C:\masm32\asmc\lib\amd64


and in C:\masm32\asmc\lib


nidud

  • Member
  • *****
  • Posts: 1980
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #215 on: December 08, 2019, 12:10:35 AM »
Yes, the imports is missing.

In the release version (and later updates) the build directory for imports will be located in ./source/import/.

you may use the batch file (./asmc-2.30.cmd) to build the imports or simply execute DZ, browse to the ./lib/amd64/ directory, select the makefile and hit Enter.

Note: The import libraries are build from system-dll's so you'll need Win64.

2B||!2B

  • Member
  • **
  • Posts: 75
Re: Asmc source and binaries
« Reply #216 on: December 08, 2019, 07:36:37 AM »
Yes, the imports is missing.

In the release version (and later updates) the build directory for imports will be located in ./source/import/.

you may use the batch file (./asmc-2.30.cmd) to build the imports or simply execute DZ, browse to the ./lib/amd64/ directory, select the makefile and hit Enter.

Note: The import libraries are build from system-dll's so you'll need Win64.

I already executed that makefile in ./lib/amd64.
Ah, i have 32bit. That must be why the import libraries failed to build.
I will be installing 64bit Windows then will see.
Thanks for the help.

nidud

  • Member
  • *****
  • Posts: 1980
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #217 on: December 08, 2019, 11:31:44 PM »
Ah, i have 32bit. That must be why the import libraries failed to build.
I will be installing 64bit Windows then will see.

You don't really need Win64 to use (or build) Asmc. You may also build 64-bit binaries but you wont be able to execute them. As for import libraries the reason why it's not included is the share size of it and only a selected few are even included in the build-list so you'll need a mechanism to add imports dynamically. This means Win64 is needed to add 64-bit libraries.

To build the current sample using Win32 add the following changes to the MAKEFILE:

_aligned_malloc.exe:
    asmc64 $*.asm
    linkw system con_64 file $*
    asmc -Fitchar.inc $*.asm
    linkw system con_32 file $*

2B||!2B

  • Member
  • **
  • Posts: 75
Re: Asmc source and binaries
« Reply #218 on: December 09, 2019, 08:18:56 AM »
Ah, i have 32bit. That must be why the import libraries failed to build.
I will be installing 64bit Windows then will see.

You don't really need Win64 to use (or build) Asmc. You may also build 64-bit binaries but you wont be able to execute them. As for import libraries the reason why it's not included is the share size of it and only a selected few are even included in the build-list so you'll need a mechanism to add imports dynamically. This means Win64 is needed to add 64-bit libraries.

To build the current sample using Win32 add the following changes to the MAKEFILE:

_aligned_malloc.exe:
    asmc64 $*.asm
    linkw system con_64 file $*
    asmc -Fitchar.inc $*.asm
    linkw system con_32 file $*


It works 32bit.
Code: [Select]
This pointer, 00275800, is aligned on 512
But i needed 64bit. So i needed those libs for 64bit.
I have a question, is asmc able to convert a 32bit project to 64bit or vice versa? because i see this aligned malloc project is 64bit and after i used that command you sent, it built 32bit without modifying the source.

nidud

  • Member
  • *****
  • Posts: 1980
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #219 on: December 09, 2019, 10:29:55 AM »
I have a question, is asmc able to convert a 32bit project to 64bit or vice versa? because i see this aligned malloc project is 64bit and after i used that command you sent, it built 32bit without modifying the source.

They use the same include files and libraries so the only difference is the registers used. The Forced included file (-Fitchar.inc) defines 64-bit registers as macros if assembled in 32-bit.

ifndef _WIN64
ifndef _REGS6432
    rax equ <eax>
    rbx equ <ebx>
    rcx equ <ecx>
    rdx equ <edx>
    rdi equ <edi>
    rsi equ <esi>
    rbp equ <ebp>
    rsp equ <esp>
_REGS6432 equ 1
endif
endif

It works for some of the samples specifically made for this but it's mostly just macros.

2B||!2B

  • Member
  • **
  • Posts: 75
Re: Asmc source and binaries
« Reply #220 on: December 09, 2019, 12:06:31 PM »
I have a question, is asmc able to convert a 32bit project to 64bit or vice versa? because i see this aligned malloc project is 64bit and after i used that command you sent, it built 32bit without modifying the source.

They use the same include files and libraries so the only difference is the registers used. The Forced included file (-Fitchar.inc) defines 64-bit registers as macros if assembled in 32-bit.

ifndef _WIN64
ifndef _REGS6432
    rax equ <eax>
    rbx equ <ebx>
    rcx equ <ecx>
    rdx equ <edx>
    rdi equ <edi>
    rsi equ <esi>
    rbp equ <ebp>
    rsp equ <esp>
_REGS6432 equ 1
endif
endif

It works for some of the samples specifically made for this but it's mostly just macros.

So if i have 32bit project i must re write it from scratch for a 64bit?

jj2007

  • Member
  • *****
  • Posts: 10468
  • Assembler is fun ;-)
    • MasmBasic
Re: Asmc source and binaries
« Reply #221 on: December 09, 2019, 07:47:43 PM »
So if i have 32bit project i must re write it from scratch for a 64bit?

Yessss! Technically, it is possible to use one source for both 32- and 64-bit assembly, but it would require a consistent set of headers and macros. In practice, you are running into lots of problems in the moment when you leave the macros and approach the "bare metal".

Here is a demo showing what would be possible (note the use of if @64):

Code: [Select]
include \Masm32\MasmBasic\Res\JBasic.inc ; ## console demo, builds with UAsm, ML, AsmC ##
Init ; OPT_64 1 ; put 0 for 32 bit, 1 for 64 bit assembly
  PrintLine Chr$("This program was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format.")
  Print ComCtl32$("It uses common controls version %i.%i\n")
  mov al, 123
  movzx eax, al
  if @64 ; use @64 (set by opt_64 n) for conditional assembly
Print Str$("If al is 123, then rax is %lli\n\n", rax)
mov rax, 1234567890123456789
Print Str$("rax can be a really big number: %lli\n\n", rax)
  else
Print Str$("If al is 123, then rax is %i\n\n", rax)
mov eax, 123456789
Print Str$("eax has only 32 bits, big enough: %i\n\n", eax)
  endif
  fldpi
  sub rsp, QWORD ; surprisingly enough, this works as 64- and 32-bit code
  fld st
  fistp qword ptr [rsp]
  movlps xmm0, qword ptr [rsp]
  fst qword ptr [rsp]
  movlps xmm1, qword ptr [rsp]
  add rsp, QWORD
  usedeb=1 ; enable debugging
  deb 4, "Even dual assembly has a deb macro:", x:rbp, x:rsp, x:rip, xmm0, f:xmm1, ST(0)
  jinvoke MessageBox, 0, Chr$("That was easy"), Chr$("Welcome to Dual Assembly:"), MB_OK ; WinAPI call
EndOfCode XP

Output when assembled as 32-bit code:
Code: [Select]
This program was assembled with UAsm64 in 32-bit format.
It uses common controls version 6.16
If al is 123, then rax is 123

eax has only 32 bits, big enough: 123456789

Even dual assembly has a deb macro:
x:rbp   18ff94h
x:rsp   18ff8ch
x:rip   4011eah
xmm0    3
f:xmm1  3.141592654
ST(0)   3.141592654

Same source but assembled as 64-bit code (using, just for fun, the buggy MASM assembler):
Code: [Select]
This program was assembled with ml64 in 64-bit format.
It uses common controls version 6.16
If al is 123, then rax is 123

rax can be a really big number: 1234567890123456789

Even dual assembly has a deb macro:
x:rbp   12ff50h
x:rsp   12ff00h
x:rip   1400012b6h
xmm0    3
f:xmm1  3.141592654
ST(0)   3.141592654

nidud

  • Member
  • *****
  • Posts: 1980
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #222 on: December 09, 2019, 10:37:37 PM »
So if i have 32bit project i must re write it from scratch for a 64bit?

Most likely yes unless it's specifically written for this.

The Asmc include files is equal to the standard C headers so this includes the portable string macros defined in tchar.inc. This enables multiple targets to be built from the same source. Many of the samples in the test directory uses this header but here's a small example:

include stdio.inc
include tchar.inc

    .code

_tmain proc

    _tprintf( "Hello World!\n" )
    ret

_tmain endp

    end _tstart

Eighth targets from the same source:

assemblelinklibrarybitsU/Adefined by asmc
asmc-pemsvcrt.dll32Ascii__PE__
asmc -ws-pemsvcrt.dll32Unicode__PE__, _UNICODE
asmc64-pemsvcrt.dll64Ascii__PE__, _WIN64
asmc64 -ws-pemsvcrt.dll64Unicode__PE__, _WIN64, _UNICODE
asmccon_32libc.lib32Ascii
asmc -wscon_32Wlibc.lib32Unicode_UNICODE
asmc64con_64libc.lib64Ascii_WIN64
asmc64 -wscon_64Wlibc.lib64Unicode_WIN64, _UNICODE

nidud

  • Member
  • *****
  • Posts: 1980
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #223 on: December 12, 2019, 03:22:41 AM »
Upgraded LIBW to version 2.0.

Reference to procedure entry point for getch() is not found

Using the switch -i6 (generate AMD64 import records) the type was set to a 32-bit decorated symbol so leading underscores and @ was stripped from the name.

Vortex

  • Member
  • *****
  • Posts: 2283
Re: Asmc source and binaries
« Reply #224 on: December 14, 2019, 06:28:15 AM »
Hi nidud,

Trying to build the 16-bit CRT ibrary with Doszip from the source files in \asmc-master\source\lib16\lib, I received some error messages :

Code: [Select]
src\conio\dledit.asm(23) : error A2206: missing operator in expression
src\conio\dledit.asm(23) : error A2033: invalid INVOKE argument : 1

Code: [Select]
src\wsub\drvinfo.asm(50) : error A2206: missing operator in expression
The .err files :
Code: [Select]
dledit.err
dlevent.err
dlinit.err
drvinfo.err
editpal.err
fballoc.err
nalloc.err
oinitst.err
opfilter.err
scan_io.err
tosetbit.err
wdlgopen.err
wsread.err
_getst.err

asmc-master.zip file dating 11 Dec 2019