The challenge exposes you to IBM Z Assembler. Learning to be an assembler programmer takes significant time and repetition.
Learning assembler is harder than learning other programming languages.
The reason is that assembler requires the programmer to learn about the machine specific:
- Assembler instructions
- Assembler directives
- Assembler macros
- Hardware architecture
IBM Z Assembler coding and debugging requires:
- Decimal/Hexadecimal conversion
- Hexadecimal arithmetic applied to memory addressibility
- Binary format representation and binary arithmetic such as two's complement
There are employers that want and need technicians with IBM Z Assembler skills.
A humorous youtube video related to the above statement follows:
"The code I write runs on the mainframe."
A deceptively simple assembler program will be used and explained. The deceptively simple assembler program includes many technical elements of IBM Z Assembler.
The first red outline is an assembler coding technique to save register content of the program that gives execution control to this assembler program. One exception is the USING statement which is an assembler directive as is the END statement at the bottom.
The second red outline restores register content of the program that gave control to this assembler program.
The third red outline gives control back to the program that originally gave control to this assembler program.
- Compile assembler program source code
tso submit 'zos.public.jcl(ch14)'
- Screen shots of the compile output follow focusing on machine instructions and assembler mnemonics.
Figure 4. Outlined in red on the right side are the assembler mnemonics.Figure 4.
Outlined in red on the left side are the corresponding machine instructions.
An example is the left side x'90' that is the machine instruction for assembler mnemonic STM on the right side.
- Screen shots of the compile output follow focusing on program instruction memory address locations.
- Screen shots of the compile output follow focusing on assembler directives and macros.
- Screen shots of the compile output follow focusing on assembler program defined storage areas.
- Screen shots of how to use the TSO TEST facility.
Relative address locations range from x'00000' to x'00009E' which is also the length of the program, CH14.
Also, outlined in red is an assembler macro (WTO).
Outlined in red 16+ to 22+ are statements included in the program as a result of the macro.
Assembler macros are reusable code.
Each storage area has an address location and a label.
The assembler mnemonics can use either labels or relative address locations of storage areas. Writing an assembler program using labels is much easier. The compiler translates the labels into relative address locations.
TEST can list program execution registers and storage locations.
Use the TEST facility on the executable program (CH14) as follows:
Get a TSO Ready prompt by terminating the ISPF session.=x
Start the TSO TEST facility as shown below - replacing Z99999 with your IDFigure 8.
In the above display - observe the following:
- list +0 length(158) displays relative address location +0 for a
length of 158 which is the machine instructions and storage areas in the program.
The program length is x'9E' which is equivalent to decimal 158.
As mentioned before, the need to convert between hexadecimal and decimal is required because of instances where a value is decimal when the operating system is working in hexadecimal.
Hexadecimal/Decimal Converter - try converting x'9E' to a decimal value
- The hexadecimal values between +0 and +9E map directly to the compile object code (machine instructions) in Figure 7.
- list 0r:15r displays the content of the 16 program execution registers, 0-15.
TEST initializes registers 2 through 12 with X'FFFFFFFF' to allow you to see register content changes during the program execution.
List instruction located at +14
List storage area located at +92 for a length of decimal 7
List storage area located at +92 for a length of decimal 7 in character format
Try what you see in Figure 11. to:
List of all registers which includes register 15 with the address of program CH14 to be loaded for execution
NOTE: Enter end to exit the TSO test facility
- Set break points at specific the program execution address locations
- List of all registers at each break point
- The first go loads and begins to execute CH14
- at +14 is LH 3,HALFCON where the result will be to load register 3 with value from storage location HALFCON
- The stop at +18 shows register 3 changed as a result of go to continue with execution of machine instruction at +14.
- HALFCON is DC H'32'. However, HALFCON storage address (+90) shows x'20' - one those hex/dec conversion things
- at +18 is A 3,FULLCON where the result will be to ADD to register 3 the value from storage location FULLCON
- The stop at +1C shows register 3 changed as a result of go to continue with execution of machine instruction at +18.
- FULLCON value is -1. Adding x'20' to -1 resulted in x'1F'
* Where FULLCON at +88 is a hexadecimal full binary word x'FFFFFFFF'
* Confused-normal-it is two's complement arithmetic.
* Understanding is not necessary to complete the challenge
* If you want to understand, start with following youtube
"Two's Complement Explained"
- While at +1C, list content at storage address +8C, associate with label HEXCON.
* Instruction ST 3,HEXCON is at +1C, waiting to be executed on next go at bottom of Figure 12.
- The assembler code ST 3,HEXCON located at +1C was executed.
- The content at +8C, HEXCON was changed from x'0000FD38' to x'0000001F'.
- The assembler ST instruction stores content of register 3 into storage memory location at +8C, HEXCON
- END terminates TSO TEST facility execution returning to TSO Ready.
Modify CH14 assembler program as instructed below.
- Edit hlq.SOURCE member name CH14
- Change the A 3,FULLCON assembler statement to a statement that will subtract register 2 from itself. -- Note: Internet search "z assembler subtract register instruction" for the assembler syntax
- Change the ST 3,HEXCON assembler statement to store register 2 into HEXCON.
- Submit ; =sd; st and review CH14 output for successful compile and execution. -- If compile and execution is successful, proceed to 5.
- Use TSO TEST to validate the successful assembler changes and debug as needed. -- Subtract register instruction has a shorter instruction length than the add instruction
- If register 2 is NOT x'00000000' or HEXCON is NOT x'00000000', then correct CH14 source code.
- If register 2 is x'00000000' and HEXCON is x'00000000', then
-- JCL job ch14x writes output to hlq.P3.OUTPUT(#14)
-- If compile and execution is unsuccessful, then identify and correct the error
** Carefully review compile output for changes in program address locations
-- Register 2 should be x'00000000'
-- Storage location associated with label HEXCON, should be x'00000000'
Congratulations! You are most likely in a fraction of the contestants advancing to the
last challenge in Part 3.
Completing all Part 3 challenges qualifies you to be among the group judged and selected as the Part 3 contest winners.
Best of luck with the final challenge.
The last chapter is presented in a tutorial form.
Chapter 17. A Tutorial Using the TEST Command