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, as well as the Univac 90/60, 90/70 and 90/80 mainframes made by Sperry Corporation. 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 Coding, or simply "assembler".
Contents |
Properly speaking, "Basic Assembly Language" was the name of the extremely restricted dialect designed to be assembled on early System/360 machines with only 8KiB of main memory, and only a card reader, a card punch, and a printer for input/output: thus the word "Basic". However, the full name and the initialism "BAL" somehow almost immediately attached themselves in popular use to all assembly-language dialects on the System/360 and its descendants.
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 closer to the hardware than third-generation languages such as COBOL.
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.
Another reason to use assembler is that not all operating system functions can be accessed in high level languages, Basically, the application program interface of mainframe operating systems is defined as a (large) set of assembly language "macro" instructions, that typically invoke Supervisor Call (SVC) hardware instructions, that in turn invoke operating system routines through the interrupt system. But it is possible to invoke assembler subroutines from programs written in high-level languages.
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? BNE IS_FEM If not, branch around L 7,MALES Load current value of MALES into register 7 LA 7,1(,7) add 1 (pre-XA max value 24 bits) ST 7,MALES and store back the result B GO_ON Finished with this portion IS_FEM EQU * A label L 7,FEMALES If not male, load current value in FEMALES LA 7,1(,7) add 1 (pre-XA max value 24 bits) ST 7,FEMALES and store GO_ON EQU * - rest of program - * MALES DC F'0' defines 31 bit memory location (initially=0) FEMALES DC F'0' "" ""
The following is the ubiquitous Hello world program, and would, executing under an IBM operating system such as OS VS/1 or MVS, display the words 'Hello World' on the operator's console:
HELLO CSECT The name of this program is 'HELLO' * Register 15 points here on entry from Op/sys or caller. 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 * -end of housekeeping (similar for most programs) - 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 SR 15,15 Set register 15 to 0 so that the return code is Zero BR 14 Return to caller * SAVE DS 18A Define 18 fullwords for calling END HELLO This is the end of the program
Note: "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=HELLO
or, alternatively, it can be CALLed as a subroutine from such a program.
CALL HELLO
Three main types of instructions are found in the source code of a program written in assembler.
As with any language, the heart of assembler programming is understanding the instructions that usually have, in this case, a "one-to-one" relationship with machine instructions. The full mnemonic instruction set is described in the Principles of Operation manual for each processor. In most instructions, the target for an instruction appears first, then the source on the right (as with "a = 6" in C or Algol programming). After one or more blanks, any comment may follow on the same line. A line starting with an asterisk (*) is considered entirely comments. Examples:
* This is a comment line * Load the fullword integer stored at location labeled 'ZIGGY' into general register 3: L 3,ZIGGY 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'
Generally accepted standards, although by no means mandatory, include the identification of general purpose registers with the nemonic '"R" through EQU statements elsewhere in the program to ease the readability of assember language programs. Thus typically you may see the following in an assembler program:-
L R3,ZIGGY
The assembler itself needs instructions from the programmer too. For instance, CSECT means "start a section of code here"; DC defines a constant to be placed in the object code.
The programmer can group instructions together into macros and add them to a library, which can then be invoked in other programs, usually with parameters, like the preprocessor facilities in C and related languages. Macros can include conditional assembler instructions, such as AIF (an IF construct), used to generate different code according to the chosen parameters. That makes the macro facility of this assembler very powerful. While multiline macros in C are an exception, macro definitions in assembler can easily be hundreds of lines.
Most programs will require services from the operating system, and the OS provides standard macros for requesting those services. These are analogous to Unix system calls. For instance, in MVS (later z/OS), STORAGE (with the OBTAIN parameter) dynamically allocates a block of memory, and GET retrieves the next logical record from a file.
Unlike Unix system calls, macros are not standardized across operating systems though. Even something as simple as writing a "sequential file" is coded differently e.g. in Z/OS than in Z/VSE.