Just for fun, I asked Google's AI (bard.google.com) the following:
"What is the format of a linux environment block? How could I
navigate an environment block in 370 assembler? The code it returned
is half GCC assembler code, and something more like 370 ASM code.
Cheers, Clem Clarke
edit
(This looks like GCC Assembler - Clem)
||
1.
2. ||
3. ||
4.
* ||
* ||
*
5.
||
||
||
||
||
1.
2. ||
3. ||
4. ||
5.
6.
||
||||||
||
volume_up
The format of a Linux environment block in 370 assembler is as follows:
|ENV_BLOCK: .LONG 0 # Length of environment block .LONG ADDR_ENV_VARS #
Address of first environment variable ADDR_ENV_VARS: .LONG ENV_VAR_1 #
Address of first environment variable .LONG ENV_VAR_2 # Address of
second environment variable ... .LONG ENV_VAR_N # Address of last
environment variable ENV_VAR_1: .BYTE 'H' # Environment variable name
'HOME' .BYTE 'O' .BYTE 'M' .BYTE 'E' .BYTE '=' .BYTE 0 # Null terminator
.BYTE '/H' .BYTE 'O' .BYTE 'M' .BYTE 'E' .BYTE '/' .BYTE 'U' .BYTE 'S'
.BYTE 'E' .BYTE 'R' .BYTE 'N' .BYTE '.' .BYTE 'B' .BYTE 'I' .BYTE 'N'
.BYTE 0 # Null terminator ENV_VAR_2: ... ENV_VAR_N: .BYTE 0 # Null
terminator |
To navigate an environment block in 370 assembler, you can use the
following steps:
1. Load the address of the environment block into a register.
2. Use the|LH|instruction to load the length of the environment block
into another register.
3. Use the|LA|instruction to load the address of the first environment
variable into another register.
4. Iterate over the environment block using a loop.
* Use the|LH|instruction to load the address of the current
environment variable into a register.
* Use the|MVC|instruction to copy the environment variable name
and value into memory.
* Increment the register containing the address of the current
environment variable.
5. Exit the loop when you reach the end of the environment block.
The following 370 assembler code shows how to navigate an environment
block and print the value of each environment variable:
|LH R1, ENV_BLOCK_LENGTH # Load length of environment block LA R2,
ENV_VARS # Load address of first environment variable LOOP: LH R3, 0(R2)
# Load address of current environment variable MVC P1, 1(R3) # Copy
environment variable name to P1 MVC P2, 3(R3) # Copy environment
variable value to P2 WTO P1, P2, 3 # Print environment variable LA R2,
4(R2) # Increment to next environment variable BCT R1, LOOP # Loop until
end of environment block |
Output:
|HOME=/home/user PATH=/usr/bin:/bin|
Colin Paice wrote:
See getenv()
<https://www.ibm.com/docs/en/zos/3.1.0?topic=functions-getenv-get-value-environment-variables>.
I dont know about assembler.
On Mon, 2 Oct 2023 at 08:27, David Cole <[email protected]> wrote:
We are beginning to write support for USS. I personally don't know
much at all about USS (there are others here who do), so please help
me along if there are terms I'm not using quite correctly.
We have a need for our code to access environment variables. I am
being told that they can be accessed easily by C programs but are
unavailable to Assembler programs.
Is this true? Is there no way whatsoever for an Assembler program to
gain access to environment variables? Is this truly an issue that no
one has solved?
Inquiring minds want to know.
Thanks,
Dave Cole, Developer
[email protected] (personal)
[email protected] (business)
540-456-6518 (cell)
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN