IBM Basic assembly language

From Wikipedia, the free encyclopedia

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 IBM High Level Assembler (HLASM).

Contents

[edit] 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.

[edit] 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   *

The following is the ubiquitous Hello world program, and would, under such IBM Operating systems as OS VS/1 and MVS, display the words 'Hello World' on the operator's console:

HELLO    CSECT               The name of this program is 'HELLO'
         USING *,12          Tell assembler what register we are using
         SAVE (14,12)        Save registers
         LR    12,15         Use Register 12 for this program  
         WTO   'Hello World' Write To Operator
         RETURN (14,12)      Return to calling party
         END  HELLO          This is the end of the program           

Note that because of the method of defining programs by saving registers and returning, this small program is usable either to be directly executed from a batch program called from the operating system or can be used as a subroutine from another program.

[edit] Types of instructions

Four main types of instructions are found in an Assembler program.

[edit] 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."

[edit] 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.

[edit] 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.

[edit] 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.

[edit] External links