BAL (Basic Assembly Language) is a low-level language used on IBM mainframes from the earliest 360 series, through systems 370, 390 and z/Series. The earliest version was provided with the System/360 in 1964; the latest version is known as the IBM High Level Assembler (HLASM). Programmers utilizing this family of assemblers refer to them as ALC, for Assembly Language Common, or simply "assembler".
The architecture of IBM mainframes has taken many forms over the years, including System/360, System/370 XA, ESA/390, and z/Architecture. Each of these architectures has retained compatibility with most of the features of its predecessor. "BAL" uses the native instruction set of these machines. It is thus as close to the hardware as a typical programmer is likely to get.
The instruction set consists of the low-level operations supported by the hardware, such as
The extreme simplicity of these operations means that a program written in Assembler will usually be much longer and harder to read than an equivalent program in, say, COBOL or Fortran. In the past, the speed of hand-coded Assembler programs was often felt to make up for this drawback, but with the advent of optimizing compilers, "C" for the mainframe, and other advances, Assembler has lost much of its appeal. IBM continues to upgrade the Assembler, however, and it is still used when the need for speed or very fine control is paramount.
CLI SEX,'M' Male?BNE IS_FEM If not, branch aroundL 7,MALES Load current value of MALES into register 7LA 7,1(,7) add 1 (pre-XA max value 24 bits)ST 7,MALES and store back the resultB GO_ON Finished with this portionIS_FEM EQU * A labelL 7,FEMALES If not male, load current value in FEMALESLA 7,1(,7) add 1 (pre-XA max value 24 bits)ST 7,FEMALES and storeGO_ON EQU * - rest of program - * MALES DC F'0' defines 31 bit memory location (initially=0) FEMALES DC F'0' "" ""
HELLO CSECT The name of this program is 'HELLO'
USING *,12 Tell assembler what register we are using for pgm. base
STM 14,12,12(13) Save registers 14,15,and 0 thru 12 in callers Save area
LR 12,15 Set up base register with programs entry point address
LA 15,SAVE Now Point at our own save area
ST 15,8(13) Set forward chain
ST 13,4(15) Set back chain
LR 13,15 Now switch to new save area
WTO 'Hello World' Write To Operator (Operating System macro)*
L 13,4(13) point at caller's-provided save area
LM 14,12,12(13) Restore registers as on entry
BR 14 Return to caller
SAVE DS 18A Define 18 fullwords for calling
END HELLO This is the end of the programNote: "WTO" is an Assembler macro that generates an Operating System call Because of saving registers and later restoring and returning, this small program is usable as a batch program invoked directly by the operating system Job control language (JCL) like this
// EXEC PGM=HELLOor, alternatively, it can be CALLed as a subroutine from such a program.
* This is a comment line
L 3,ZIGGY load the fullword integer stored at location labeled 'ZIGGY' into general register 3
SLA 4,5 shift the value in general register 4 left by 5 bits
MVC TARGET,SOURCE move characters from memory location 'SOURCE' to 'TARGET'
AP COUNT,=P'1' add 1 to value in memory location 'COUNT' (packed decimal format)
B NEXT unconditional branch to label 'NEXT'
HERE EQU * This is a label
CLC TARGET,=C'ADDRESS' Compare memory location 'TARGET' to string 'ADDRESS'
BE THERE branch if equal to program label 'THERE'