News:

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

Main Menu

@Environ

Started by StillLearningMasm, May 07, 2022, 08:10:53 AM

Previous topic - Next topic

StillLearningMasm

Has anybody tried to use the "built-in" macro @environ?

I tried to use it by using EQU and TEXTEQU. This is the code fragment I used:

En1 equ @Environ
En2 equ "@Environ"
En3 equ <@Environ>
En4 equ <"@Environ">
En5 textequ @Environ
En6 textequ "@Environ"
En7 textequ <@Environ>
En8 textequ <"@Environ">

The results after assembly:
En1 thru En4 sets the equate to @Environ or "@Environ"
En5 and En6 results in error : error text item required
En7 and En8 sets the text equate to @Environ and "@Environ"

so how do you use it? Masm has NO info!

mineiro

You can set LIB,INCLUDE,BIN variables in environment and get that.

%echo @Environ(<windir>)
%incpath textequ <@Environ(<windir>)>
%include <incpath\\masm32rt.inc>

output in my machine while assembling is:
C:\windows
: fatal error A1000: cannot open file : C:\windows\masm32rt.inc     <<<<<yes, this file is sitting in other directory

;------------------------------------------
~/.wine/drive_c$ wine cmd
Microsoft Windows 5.2.3790
C:\>set include=c:\masm32\include
C:\>set lib=c:\masm32\lib
C:\>set bin=c:\masm32\bin
C:\>echo %bin%
c:\masm32\bin
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

hutch--

Look here.

https://docs.microsoft.com/en-us/cpp/assembler/masm/at-environ?view=msvc-170

Build this as a console app in MASM32.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    .data?
      value dd ?

    .data
      item dd 0

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

; @Environ Returns values of environment variables during assembly.

main proc

    % echo -------------------
    % echo @Environ(path)
    % echo -------------------

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start


hutch--

get ancient stuff like this from the following URL.

https://www.mikrocontroller.net/attachment/450367/MASM61PROGUIDE.pdf

Some extra variations.

    % echo -------------------
    % echo path = @Environ(path)
    % echo tmp  = @Environ(tmp)
    % echo OS   = @Environ(OS)
    % echo CPU  = @Environ(PROCESSOR_IDENTIFIER)
    % echo Ver  = @Environ(PROCESSOR_REVISION)
    % echo Arch = @Environ(PROCESSOR_ARCHITECTURE)
    % echo Pshl = @Environ(PSModulePath)
    % echo WinD = @Environ(windir)
    % echo -------------------

Gunther

Steve,

Quote from: hutch-- on May 07, 2022, 12:01:07 PM
Some extra variations.

    % echo -------------------
    % echo path = @Environ(path)
    % echo tmp  = @Environ(tmp)
    % echo OS   = @Environ(OS)
    % echo CPU  = @Environ(PROCESSOR_IDENTIFIER)
    % echo Ver  = @Environ(PROCESSOR_REVISION)
    % echo Arch = @Environ(PROCESSOR_ARCHITECTURE)
    % echo Pshl = @Environ(PSModulePath)
    % echo WinD = @Environ(windir)
    % echo -------------------


wow, I didn't know that. Good work.  :thumbsup:
You have to know the facts before you can distort them.

jj2007

There are 13 usage examples in the latest \Masm32\MasmBasic\MasmBasic.inc

hutch--

Works in 64 bit MASM as well.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    USING r12

    SaveRegs

    conout "Howdy, your new console template here.",lf,lf

    % echo -------------------
    % echo path = @Environ(path)
    % echo tmp  = @Environ(tmp)
    % echo OS   = @Environ(OS)
    % echo CPU  = @Environ(PROCESSOR_IDENTIFIER)
    % echo Ver  = @Environ(PROCESSOR_REVISION)
    % echo Arch = @Environ(PROCESSOR_ARCHITECTURE)
    % echo Pshl = @Environ(PSModulePath)
    % echo WinD = @Environ(windir)
    % echo -------------------

    waitkey
    RestoreRegs
    .exit

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end


jj2007

include \masm32\include\masm32rt.inc
.code
start:
  tmp$ CATSTR <chr$(">, @Environ(PROCESSOR_IDENTIFIER), <")>
  MsgBox 0, tmp$, "Your cpu:", MB_OK
  ret
end start

hutch--

This works OK as well.

    mov pbuf, ptr$(ebuf)
    invoke GetEnvironmentVariable,"PROCESSOR_IDENTIFIER",pbuf,260
    conout pbuf,lf

jj2007

Quote from: hutch-- on May 13, 2022, 08:48:35 PM
    invoke GetEnvironmentVariable,"PROCESSOR_IDENTIFIER",pbuf,260

How would the Assembler interpret invoke GetEnvironmentVariable,"PATH",pbuf,4096 ? On my machine, using ML64, it crashes in RtlInitAnsiStringEx.

hutch--

Here are a few more.

    LOCAL hLib   :QWORD
    LOCAL pGetActiveProcessorCount :QWORD
    LOCAL pGetMaximumProcessorCount :QWORD

    SaveRegs

    mov hLib, rvcall(GetModuleHandle,"kernel32.dll")
    mov pGetActiveProcessorCount, rvcall(GetProcAddress,hLib,"GetActiveProcessorCount")
    mov pGetMaximumProcessorCount, rvcall(GetProcAddress,hLib,"GetMaximumProcessorCount")

    mov pbuf, ptr$(ebuf)
    invoke GetEnvironmentVariable,"PROCESSOR_IDENTIFIER",pbuf,260
    conout pbuf,lf

    invoke GetEnvironmentVariable,"PROCESSOR_REVISION",pbuf,260
    conout "cpu revision ",pbuf,lf

    invoke GetEnvironmentVariable,"PROCESSOR_ARCHITECTURE",pbuf,260
    conout "cpu architecture ",pbuf,lf

    rcall pGetActiveProcessorCount,0FFFFh
    conout "active cpu count ",str$(rax),lf

    rcall pGetMaximumProcessorCount,0FFFFh
    conout "maximum cpu count ",str$(rax),lf

hutch--

 :biggrin:

    mov pbig, ptr$(bpth)
    invoke GetEnvironmentVariable,"PATH",pbig,4096
    conout pbig,lf

Result

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;d:\syspath\;C:\Program Files\dotnet\;C:\Users\hutch\AppData\Local\Microsoft\WindowsApps

jj2007

So how does the assembler distinguish between "PATH" (=address to a string) and "PATH" (=a DWORD passed by value)? Just curious :rolleyes:

hutch--

Huh ?

The code works on one of my Xeon's as well, no problems.

Intel64 Family 6 Model 63 Stepping 2, GenuineIntel
C:\Users\hutch\AppData\Local\ActiveState\StateTool\release;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;d:\syspath;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Windows\System32\OpenSSH\;C:\Users\hutch\AppData\Local\Microsoft\WindowsApps;
cpu revision 3f02
cpu architecture AMD64
active cpu count 24
maximum cpu count 24
Press any key to continue...

hutch--

To your question, either quoted text or a QWORD ptr to the text.