Author Topic: @Environ  (Read 1595 times)

StillLearningMasm

  • Regular Member
  • *
  • Posts: 40
@Environ
« on: May 07, 2022, 08:10:53 AM »
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

  • Member
  • ****
  • Posts: 958
Re: @Environ
« Reply #1 on: May 07, 2022, 10:15:44 AM »
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--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: @Environ
« Reply #2 on: May 07, 2022, 11:31:00 AM »
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 at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: @Environ
« Reply #3 on: May 07, 2022, 12:01:07 PM »
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 -------------------
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

Gunther

  • Member
  • *****
  • Posts: 4198
  • Forgive your enemies, but never forget their names
Re: @Environ
« Reply #4 on: May 07, 2022, 03:17:33 PM »
Steve,

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

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: @Environ
« Reply #5 on: May 07, 2022, 05:26:58 PM »
There are 13 usage examples in the latest \Masm32\MasmBasic\MasmBasic.inc

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: @Environ
« Reply #6 on: May 07, 2022, 05:35:31 PM »
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

hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: @Environ
« Reply #7 on: May 07, 2022, 10:38:11 PM »
Code: [Select]
include \masm32\include\masm32rt.inc
.code
start:
  tmp$ CATSTR <chr$(">, @Environ(PROCESSOR_IDENTIFIER), <")>
  MsgBox 0, tmp$, "Your cpu:", MB_OK
  ret
end start

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: @Environ
« Reply #8 on: May 13, 2022, 08:48:35 PM »
This works OK as well.

    mov pbuf, ptr$(ebuf)
    invoke GetEnvironmentVariable,"PROCESSOR_IDENTIFIER",pbuf,260
    conout pbuf,lf
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: @Environ
« Reply #9 on: May 13, 2022, 08:50:12 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--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: @Environ
« Reply #10 on: May 13, 2022, 09:33:45 PM »
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 at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: @Environ
« Reply #11 on: May 13, 2022, 09:38:23 PM »
 :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
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: @Environ
« Reply #12 on: May 13, 2022, 09:41:10 PM »
So how does the assembler distinguish between "PATH" (=address to a string) and "PATH" (=a DWORD passed by value)? Just curious :rolleyes:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: @Environ
« Reply #13 on: May 13, 2022, 09:46:03 PM »
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 at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: @Environ
« Reply #14 on: May 13, 2022, 09:47:31 PM »
To your question, either quoted text or a QWORD ptr to the text.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy: