IBM Basic assembly language and successors
BAL (Basic Assembly Language) is a low-level language used on IBM z/Series mainframes. The earliest version was provided with the System/360 in 1964; the latest version is known as the High Level Assembler.
General characteristics
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 preserved 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 "load" (copy a value from memory to a register), "store" (copy a value from a register to memory), "compare" (compare two values), "shift" (move the bits of a register left or right), and "execute channel program" (an I/O operation such as reading data from a disk or tape). 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.
A small example
The following fragment shows how the logic "if SEX = 'M', add 1 to MALES; else, add 1 to FEMALES" would be performed in Assembler.
CLI SEX,'M' Male? BNO IS_FEM If not, branch around L 7,MALES Load MALES into register 7; LA 7,1(,7) add 1; ST 7,MALES and store the result B GO_ON Finished with this portion IS_FEM L 7,FEMALES If not male, load FEMALES into register 7; LA 7,1(,7) add 1; ST 7,FEMALES and store GO_ON EQU *
Types of instructions
Four main types of instructions are found in an Assembler program.
Machine instructions
The heart of Assembler programming is understanding the machine instructions. These are described in the Principles of Operation manual for each processor. The target for an instruction appears first, then the source on the right, like "a = 6" in C or Algol. For instance, "L 3,ZIGGY" means "load the integer stored at location ZIGGY into register 3"; "SLA 4,5" means "shift the value in register 4 left by 5 bits."
Assembler instructions
The assembler itself provides instructions too. For instance, CSECT means "start a section of code here"; DC declares a constant value to be placed in the object code.
Macros and conditional assembly
The programmer can group instructions together into macros, which can then be invoked in other programs, much like the preprocessor facilities in C and related languages. Macros can include conditional assembler instructions, such as AIF (an IF construct), which can be used to generate different code under different conditions.
Operating system macros
Most programs will require services from the operating system, and the OS provides macros for requesting the services. These are analogous to Unix system calls. For instance, in MVS (later z/OS), GETMAIN allocates a block of memory, and GET gets the next logical record from a file.
External links
z/OS library—look for "High Level Assembler" and "Principles of Operation" on the left