IBM Basic assembly language
BAL (Basic Assembly Language) is a low-level language used on IBM mainframes from the earliest 360 series, through systems 370, 390, zSeries and System z, 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 |
[edit] A note on the name
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.
[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 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
- "Load" (L) - copy a value from memory to a register,
- "Store" (ST) - copy a value from a register to memory,
- "Compare" (C) - compare a register value with a value in memory,
- "Shift" (SLL, SRL) - move the bits of a register left or right and
- "Start Sub Channel" (SSCH) - start a sub-channel operation such as an I/O operation using a connected string of Channel Command Words (CCW).
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.
[edit] Assembler Statement Format
The format of assembler language statements reflects the layout of an 80-column punched card, though successive versions have relaxed most of the restrictions.
- The optional statement label or name was one to six alphanumeric characters beginning in column 1. The first character had to be alphabetic.
- The operation code or mnemonic could begin in any column to the right of column 1, separated from the statement label by a blank.
- The operand field could begin in any column to the right of the operation code, separated from the operation code by at least one blank. Blanks were invalid in operands except in character constants. The operand field, consisting of one or more operands, was optional depending on the operation code.
- Optional comments could appear to the right of the operand field, separated by at least one blank.
- Basic Assembly Language did not allow statement continuation. Later versions of the assembler indicated continuation by the appearance of any character in column 72 of the statement being continued. Basic Assembly Language required that column 72 be blank.
- A "full-card comment" was indicated by an asterisk (*) in column 1.
- Card columns 73-80, called the identification-sequence field could be used by the programmer for any purpose, but usually contained sequence numbers for resorting a jumbled card deck.
Basic Assembly language also permitted an alternate statement format with the statement starting in column 25, allowing the assembled instruction to be punched into the same card beginning in column 1. This option was not continued in later versions of the assembler.
[edit] Types of instructions
Three main types of instructions are found in the source code of a program written in assembler.
[edit] Machine instructions (mnemonic)
There is a "one-to-one" relationship with machine instructions. The full mnemonic instruction set is described in the Principles of Operation manual for each processor. Examples:
* This is a comment line
* Load the fullword integer stored at the
* 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 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 mnemonic '"R" through EQU statements elsewhere in the program to ease the readability of assembler language programs and provide a cross-reference of register usage. Thus typically you may see the following in an assembler program:-
L R3,ZIGGY
[edit] Assembler instructions
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.
[edit] Macros and conditional assembly
Basic assembler language did not support macros. Later assembler versions allowed the programmer to 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.
[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?
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
[edit] Operating system macros
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.
[edit] External links
| Wikibooks has a book on the topic of |