HLASM Statement Format: Labels, Operation Codes, and Operands

TT

HLASM Statement Format: Labels, Operation Codes, and Operands

Every HLASM statement follows a rigid column-based format inherited from the punched-card era of mainframe computing. Understanding this format is the foundation of reading and writing HLASM code.

The Four Fields

An HLASM statement has four fields, separated by spaces:

text
name      operation   operands              remarks
LOOP      LA          3,0                   Initialize counter
FieldColumnsDescription
Name1–8Optional label for this statement
Operation10–14Instruction mnemonic or assembler directive
Operands16–71Comma-separated operand list
RemarksAfter operandsComment text (after a space following operands)

The fields are position-sensitive up to column 71. Column 72 is the continuation indicator. Columns 73–80 are the sequence number.

The Name Field (Labels)

Labels in the name field mark the address of a statement. They are used as branch targets, data references, and USING anchors:

hlasm
START    CSECT
         STM   14,12,12(13)    No label — this statement has no address reference
MAINLOOP LA    3,0             Label MAINLOOP marks this instruction's address
         A     3,=F'1'
         C     3,=F'100'
         BL    MAINLOOP        Branch back to MAINLOOP if register 3 < 100

Label rules:

  • 1 to 8 characters
  • First character must be alphabetic (A–Z) or national characters (@, #, $)
  • Remaining characters: alphanumeric or national
  • Must start in column 1

The Operation Field

The operation field names the instruction or directive. HLASM operations fall into three categories:

Machine instructions — real z/Architecture instructions:

hlasm
         L     2,MYDATA        Load register 2 from storage
         AR    3,4             Add register 4 to register 3
         B     LOOP            Branch to LOOP

Assembler instructions (directives) — control the assembly process:

hlasm
MYCSECT  CSECT                 Begin a control section
         USING MYCSECT,12      Establish base register
MYDATA   DC    F'42'           Define a fullword constant
MYSTORE  DS    CL80            Reserve 80 bytes of storage
         END   MYCSECT         End of source

Macro instructions — expand into multiple statements:

hlasm
         WTO   'HELLO WORLD'   Write To Operator macro
         RETURN (14,12)        Return macro

The Operands Field

Operands specify the data for the instruction. Most machine instructions use register and storage operands:

hlasm
* Register operand: just the register number
         LR    3,4             Register 3 = source, Register 4 = destination? No:
*                              LR R1,R2 means: load R1 from R2. First = target.

* Storage operand: D(B) — displacement from base register
         L     3,0(12)         Load reg 3 from address in reg 12 + offset 0
         L     3,8(12)         Load reg 3 from address in reg 12 + offset 8

* Storage operand: D(X,B) — displacement with index
         L     3,4(4,12)       Load reg 3 from reg12 + reg4 + 4

* Immediate operand: literal value
         LA    3,42            Load value 42 into register 3 (not from storage)
         MVI   0(12),X'40'     Move immediate hex 40 to byte at address in reg 12

* Label operand: assembler resolves to address
         L     3,MYDATA        Load reg 3 from the address labelled MYDATA
         B     LOOP            Branch to instruction labelled LOOP

Comment Statements

A statement with * in column 1 is a comment:

hlasm
* =====================================================
* PROGRAM: MYPROG
* PURPOSE: Demonstrate HLASM statement format
* AUTHOR:  Mainframe Team
* =====================================================
         CSECT
* Initialize base register
         LR    12,15
         USING *,12

Inline comments follow the operands after at least one space:

hlasm
         LA    3,0             Initialize loop counter to zero
         L     4,MAXVAL        Load maximum value from storage

Continuation Lines

If an operand list is too long for one line, continue on the next line. Place a non-blank character in column 72 and start the continuation in column 16:

hlasm
         MVC   OUTPUT(80),=CL80'NAME        DEPARTMENT  X
                              SALARY      YEARS'

The X in column 72 signals continuation. The continuation begins at column 16 of the next line.

The CSECT and END Directives

Every HLASM program needs a CSECT (start) and END (finish):

hlasm
MYPROG   CSECT                 Program starts here
* ... instructions and data ...
         END   MYPROG          End of source; MYPROG is the entry point

END label tells the assembler where the entry point is. The linker uses this when building the load module.

Frequently Asked Questions

Q: Why does HLASM use column-based formatting instead of free-form? HLASM's column-based format descends directly from the 80-column punched card used with System/360 in the 1960s. Each card had 80 columns, and the assembler source conventions were designed around this physical constraint. The format was preserved through all subsequent assembler versions for backward compatibility — assembler programs written in 1968 still assemble correctly today.

Q: What happens if I put a label in the wrong column? If a label starts anywhere other than column 1, the assembler treats it as part of the operation field (if it's in the right place) or generates an error. Most errors from column misalignment produce cryptic messages. Modern editors with HLASM syntax support highlight column-sensitive fields, which prevents most formatting mistakes.

Q: Can I use lowercase in HLASM source? By default, HLASM treats lowercase and uppercase identically for operation codes and register names — both LA and la work. However, character constants are case-sensitive: DC C'hello' and DC C'HELLO' generate different data. The convention is to write all HLASM keywords and labels in uppercase for readability.


Part of HLASM Mastery Course — Module 3 of 22.