IBM Basic Assembly Language and successors

From HandWiki
Short description: Assembly languages for IBM System/360 and successor mainframes

Basic Assembly Language (BAL) is the commonly used term for a low-level programming language used on IBM System/360 and successor mainframes. Originally, "Basic Assembly Language" applied only to an extremely restricted dialect designed to run under control of IBM Basic Programming Support (BPS/360) on systems with only 8 KB 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" almost immediately attached themselves in popular use to all assembly-language dialects on the System/360 and its descendants. BAL for BPS/360 was introduced with the System/360 in 1964.

Assemblers on other operating systems for System/360 through IBM Z, for the UNIVAC Series 90 mainframes made by Sperry Corporation, and for the BS2000 Mainframes currently made by Fujitsu, inherited and extended its syntax. The latest derived language is known as the IBM High-Level Assembler (HLASM). Programmers utilizing this family of assemblers also refer to them as ALC, (for Assembly Language Coding), or simply "assembler".

General characteristics

The architecture of IBM mainframes has undergone several extensions over the years, including System/360, System/370, System/370 XA, ESA/370, 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 architecture, such as:

Instruction Mnemonic Description
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
Start subchannel SSCH start a sub-channel I/O operation using a string of channel command words

The extreme simplicity of these operations means that the source code of a program written in assembler will usually be much longer 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. However, all of the IBM successors to BAL have included a sophisticated macro facility that allows writing much more compact source code.

Another reason to use assembler is that not all operating system functions can be accessed in high level languages. The application program interface of mainframe operating systems is defined as a set of assembly language "macro" instructions, that typically invoke Supervisor Call (SVC) [e.g., on z/OS] or Diagnose (DIAG) [on, e.g., z/VM] instructions to invoke operating system routines. It is possible to use operating system services from programs written in high-level languages by use of assembler subroutines.

Assembler statement format

Keypunch cards and a printed assembly listing were common during IBM 370 assembly language use in the 1970s

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 is a string alphanumeric characters beginning in column 1. The first character has to be alphabetic. Later versions added @, #, $, and _ to the legal characters used in labels, and increased the size from the initial six, to eight characters, then to almost unlimited lengths.
  • The operation code or "mnemonic" can begin in any column to the right of column 1, separated from the statement label by a blank. The operation code would be only a machine instruction (macros were not available), making it usually 1, 2, 3, or rarely 4 letters. The operation code was enhanced to allow up to eight characters, then later to effectively unlimited lengths.
  • The operand field can begin in any column to the right of the operation code, separated from the operation code by at least one blank. Blanks are invalid in operands except in character constants. The operand field, consisting of one or more operands, is optional depending on the operation code.
  • Optional comments can appear to the right of the operand field, separated by at least one blank.
  • Basic Assembly Language does not allow statement continuation. Later versions of the assembler indicate continuation by the appearance of any non-blank character in column 72 of the statement being continued. Basic Assembly Language requires that column 72 be blank.
  • A "full-card comment" is indicated by an asterisk (*) in column 1.
  • Card columns 73–80, called the identification-sequence field can be used by the programmer for any purpose, but usually contain sequence numbers for resorting a jumbled card deck.

Basic Assembly language also permits 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.

Types of instructions

Three main types of instructions are found in the source code of a program written in assembler.

Assembler instructions

Assembler instructions, sometimes termed directives, pseudo operations or pseudoops on other systems, are requests to the assembler to perform various operations during the code generation process. For instance, CSECT means "start a section of code here"; DC defines a constant to be placed in the object code.

One of the more important assembler instructions is USING, which supports the truncated addressing of the S/360 architecture. It guides the assembler in determining what base register and offset it should use for a relative address. In BAL, it was limited to the form

USING base,reg-1,...,reg-n

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[1] 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 mnemonics. Unlike assemblers for some other systems, such as X86 assembly language, register mnemonics are not reserved symbols but are defined through EQU statements elsewhere in the program. This improves readability of assembler language programs and provides a cross-reference of register usage. Thus typically you may see the following in an assembler program:

R3    EQU  3
       ...
       L    R3,ZIGGY

Some notable instruction mnemonics are BALR[lower-alpha 1] for a call storing the return address and condition code in a register, SVC,[lower-alpha 2] DIAG,[lower-alpha 3] and ZAP.[2] The latter inspired the name of the SuperZAP utility by a programmer using the pseudonym WAMOZART, cf. SuperZap at the Free On-line Dictionary of Computing .

System/360 machine instructions are one, two, or three halfwords in length (two to 6 bytes). Originally there were four instruction formats, designated by the first two bits of the operation code field; z/Architecture added additional formats.

Macros and conditional assembly

Basic assembler language does not support macros. Later assembler versions allow 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.

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.

Examples

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,C'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 
          ST    7,MALES        store back the result
          B     GO_ON          Finished with this portion
 IS_FEM   EQU   *              A label
          L     7,FEMALES      Load current value in FEMALES into register 7 
          LA    7,1(7)         add 1 
          ST    7,FEMALES      store back the result
 GO_ON    EQU   *              - rest of program -
 MALES    DC    F'0'           Counter for MALES (initially=0)
 FEMALES  DC    F'0'           Counter for FEMALES (initially=0)

The following is the ubiquitous Hello world program, and would, executing under an IBM operating system such as OS/VS1 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 OPSYS or caller.
          STM   14,12,12(13)  Save registers 14,15, and 0 thru 12 in caller's Save area
          LR    12,15         Set up base register with program's entry point address
          USING HELLO,12      Tell assembler which register we are using for pgm. base
          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         Set R13 to address of new save area
 *                            -end of housekeeping (similar for most programs) -
          WTO   'Hello World' Write To Operator  (Operating System macro)
          L     13,4(13)      restore address to caller-provided save area
          XC    8(4,13),8(13) Clear forward chain
          LM    14,12,12(13)  Restore registers as on entry
          DROP  12            The opposite of 'USING'
          SR    15,15         Set register 15 to 0 so that the return code (R15) is Zero
          BR    14            Return to caller
 SAVE     DS    18F           Define 18 fullwords to save calling program registers 
          END  HELLO          This is the end of the program

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'

Versions

Batch job printout showing identification page for Assembler G

With the exception of the assemblers for the IBM System/360 Model 20, the IBM assemblers were largely upward-compatible. The differences were mainly in the complexity of expressions allowed and in macro processing. OS/360 assemblers were originally designated according to their memory requirements.

7090/7094 Support Package assembler

This cross-assembler runs on a 7090 or 7094 system and was used while System/360 was in development.[3][4]

Basic Programming Support assembler

The assembler for BPS is the true "basic assembler." It was intended to be loaded from cards and would run on an 8 KB System/360 (except Model 20). It has no support for macro instructions or extended mnemonics (such as BH in place of BC 2 to branch if condition code 2 indicates a high compare). It can assemble only a single control section and does not allow dummy sections (structure definitions). Parenthesized expressions are not allowed and expressions are limited to three terms with the only operators being '+', '-', and '*'.[3]:pp.59–61

Basic Operating System assembler

The Basic Operating System has two assembler versions. Both require 16 KB memory, one is tape resident and the other disk.[5]:pp.7–8

Assembler D

Assembler D was the DOS/360 assembler for machines with a memory size of 16 KB. It came in two versions: A 10 KB variant for machines with the minimum 16 KB memory, and a 14 KB variant for machines with 24 KB. An F-level assembler was also available for DOS machines with 64 KB or more. D assemblers offered nearly all the features of higher versions.[6]:p.7

Assembler E and F

Assembler E was designed to run on an OS/360 system with a minimum of 32 KB of main storage, with the assembler itself requiring 15 KB.[7]:p.2 Assembler F can run under either DOS/360 or OS/360 on a system with a 64 KB memory, with the assembler requiring 44 KB.[8][9][10] These assemblers are a standard part of OS/360; the version that was generated was specified at system generation (SYSGEN).

Model 44 Programming System Assembler

"With certain exceptions, the IBM System/360 Model 44 Programming System Assembler Language is a selected subset of the languages available in the IBM System/360 programming support." Most significantly the Model 44 assembler lacked support for macros and continuation statements. On the other hand it had a number of features not found in other System/360 assemblers—notably instructions to update a card image source dataset, named common, and implicit definition of SETA assembler variables.[11]

Assembler G

"Assembler G" is a set of modifications made to Assembler F in the 1970s by the University of Waterloo (Assembler F was/is open source). Enhancements are mostly in better handling of input/output and improved buffering which speed up assemblies considerably.[12] "Assembler G" was never an IBM product.

Assembler H

Assembler H Version 2 was announced in 1981 and includes support for Extended Architecture (XA), including the AMODE and RMODE directives.[13]:p.3–28 It was withdrawn from marketing in 1994 and support ended in 1995. It was replaced by High Level Assembler.[14]

Assembler XF

Assembler XF is an upgrade of Assembler F which includes the new System/370 architecture instructions. This version provides a common assembler for OS/VS and DOS/VS systems. Other changes include relaxing restrictions on expressions and macro processing. Assembler XF requires a minimum partition/region size of 64 KB (virtual). Recommended size is 128 KB.[15]:p.73

High Level Assembler

Main page: IBM High Level Assembler

High Level Assembler (HLASM), announced in 1992 as a licensed program "becomes the default translator for System/370 (TM) and System/390 (TM) operating environments." The assembler supports the MVS, VSE, and VM operating systems and successors. As of Release 6 it now is able to run under Linux on IBM Z and generate ELF or GOFF object files.[16] It features a long list of mostly usability enhancements, and incorporates the SLAC (Stanford Linear Accelerator) modifications to Assembler H. Among features added were an indication of CSECT/DSECT for location counter, dependent[lower-alpha 4] and labelled[lower-alpha 5] USING statements, a list of USING statements currently active, an indication of whether a variable is read or written in the cross-reference, and allowing mixed-case symbol names.[17] The RSECT directive (Read-only Control Section) allows the assembler to check reentrancy on a per-section basis. RSECT was previously "undocumented and inconsistently implemented in Assembler H."[18]:p.43 HLASM is the current assembler for IBM mainframe systems as of 2012.

Specialized versions

IBM System/360 Model 44 PS assembler

The IBM System/360 Model 44 Programming System Assembler processes a language that is a "selected subset" of OS/360 and DOS/360 assembler language. It has no support for storage-to-storage (SS) instructions or the convert to binary (CVB), convert to decimal (CVD), read direct (RDD) and write direct (WRD) instructions.[19] It does include four instructions unique to the Model 44: Change Priority Mask (CHPM), Load PSW Special (LPSX), Read Direct Word (RDDW), and Write Direct Word (WRDW). It also includes directives to update the source program, a function performed by utility programs in other systems (SKPTO, REWND, NUM, OMIT and ENDUP). It provides named common and implicitly defined &SETA symbols, but has some restrictions as well.[19]:pp.53,73

IBM System/360 TSS assembler

The assembler for the System/360 Model 67 Time Sharing System has a number of differences in directives to support unique TSS features. The PSECT directive generates a Prototype Control Section containing relocatable address constants and modifiable data used by the program.[20]:p.143

Non-IBM assemblers

There have been several IBM-compatible assemblers for special environments.[21]

  • The Univac 90/60, 90/70 and 90/80 series from Unisys was designed to accept IBM-format assembler, as the machine series was a workalike to the S/360 and S/370.
  • The Fujitsu BS2000 series was also built as a 370 workalike from the same resource as Univac, and is still in use in some parts of Europe.[22]
  • Dignus LLC Systems/ASM is an HLASM-compatible assembler that can run natively on IBM systems or as a cross-assembler.[23]
  • Freeware PC/370, written by Don Higgins, was later purchased by Micro Focus.
  • z390 is an assembler and System 390 emulator also written by Don Higgins and is programmed in Java. It is open source and available from http://www.z390.org/
  • Penn State University authored a package called ASSIST, which includes a System 370 assembler and interpreter.
  • Tachyon Software LLC markets the Tachyon Assembler Workbench which runs on Windows, Linux/x86, Linux for S/390 and zSeries, AIX and Solaris.[24]
  • GNU Assembler (gas) is part of the GNU Compiler Collection (gcc) for Linux on OS/390 and IBM Z. This assembler has a unique syntax that is incompatible with other assemblers for IBM architectures.

Trivia

BAL is also the mnemonic of the "Branch And Link" instruction.[2]

See also

Notes

  1. Most uses of BALR have been replaced by BASR and similar instructions.
  2. Many uses of SVC have been replaced by a PC instruction.
  3. VM repurposes DIAG as an HVC instruction.
  4. A dependent USING is one that specifies a relocatable expression instead of a list of registers:
    USING IHADCB,SYSPRINT
             ...
             TM    DCBOPTCD,DCBOPTC       Test OPTCD in SYSPRINT
             ...
  5. A labelled USING is one that only affects instructions that explicitly refer to it by qualifying an expression with a label:
    LA    R4,SYSIN
             LA    R5,SYSPRINT
    IN       USING IHADCB,R4
    OUT      USING IHADCB,R5
             ...
             TM    IN.DCBOFLGS,DCBOFTM        Test OFLGS in SYSIN
             ...
             TM    OUT.DCBOPTCD,DCBOPTC       Test OPTCD in SYSPRINT
             ...

References

  1. IBM System/360 Principles of Operation. IBM Corporation. A22-6821-0. http://bitsavers.org/pdf/ibm/360/princOps/A22-6821-0_360PrincOps.pdf. Retrieved Dec 6, 2018. 
  2. 2.0 2.1 "HLASM - List of all Opcodes, Extended Mnemonics and Function Codes, Sorted by Mnemonic". http://www.bixoft.nl/english/opl_bobm.htm. Retrieved January 14, 2013. 
  3. 3.0 3.1 IBM System/360 Basic Programming Support Basic Assembler Language. IBM Corporation. February 1965. C20-6503-0. http://bitsavers.org/pdf/ibm/360/bos_bps/C20-6503-0_BAL_Feb65.pdf. Retrieved April 5, 2022. 
  4. IBM 7090/7094 Support Package for IBM System/360. IBM Corporation. November 1964. C28-6501-2. http://bitsavers.org/pdf/ibm/7090/C28-6501-2_7090_SupportForSys360_Nov64.pdf. Retrieved April 5, 2022. 
  5. IBM System/360 Basic Operating System Language Specifications Assembler (16K Disk/Tape). IBM Corporation. December 1965. C24-3414-1. http://bitsavers.org/pdf/ibm/360/bos_bps/C24-3414-1_BOSasm_Dec65.pdf. Retrieved April 5, 2022. 
  6. IBM Corporation (1970). IBM System/360 Disk and Tape Operating Systems Assembler Language. http://bitsavers.trailing-edge.com/pdf/ibm/360/dos/GC24-3414-7_Disk_and_Tape_Operating_Systems_Assembler_Language_Aug70.pdf. 
  7. IBM Corporation (1966). IBM System/360 Operating System Assembler (32K) Program Logic Manual. http://bitsavers.trailing-edge.com/pdf/ibm/360/asm/Y26-3598-0_32k_asmPLM_1966.pdf. 
  8. IBM Corporation (1968). IBM System/360 Disk Operating System Assembler(F) Program Logic. http://bitsavers.trailing-edge.com/pdf/ibm/360/asm/Y26-3716-0_asm%28f%29_plm_Mar68.pdf. 
  9. IBM Corporation (1971). IBM System/360 Assembler(F) Program Logic. http://bitsavers.trailing-edge.com/pdf/ibm/360/asm/GY26-3700-2_asm%28f%29_plm_Jun71.pdf. 
  10. IBM Corporation (1974). IBM OS Assembler Language. http://www.textfiles.com/bitsavers/pdf/ibm/360/asm/GC28-6514-9_OS_Assembler_Rel21_Jan74.pdf. 
  11. IBM Corporation (1966). IBM System/360 Model 44 Programming System Assembler Language. p. 73. http://bitsavers.org/pdf/ibm/360/model44/C28-6811-1_Model_44_Programming_System_Assembler_Language_1966.pdf. Retrieved July 2, 2019. 
  12. Stanford Linear Accelerator Center. "GENERALIZED IBM SYSTEM 360 SOFTWARE MEASUREMENT (SLAC-PUB-715)". http://www.slac.stanford.edu/cgi-wrap/getdoc/slac-pub-0715.pdf. Retrieved October 8, 2012. 
  13. IBM Corporation (1984). MVS/Extended Architecture Conversion Notebook. http://bitsavers.trailing-edge.com/pdf/ibm/370/MVS_XA/GC28-1143-2_MVS_EA_Conversion_Notebook_May84.pdf. 
  14. IBM Corporation (20 December 1996). "5668-962 IBM Assembler H Version 2 Release 1.0". http://www-01.ibm.com/common/ssi/cgi-bin/ssialias?infotype=dd&subtype=sm&appname=ShopzSeries&htmlfid=897/ENUS5668-962. Retrieved October 8, 2012. 
  15. IBM Corporation (1973). OS/VS Assembler Programmer's Guide. http://bitsavers.trailing-edge.com/pdf/ibm/370/OS_VS/GC33-4021-1_OS_VS_Assembler_Programmers_Guide_May73.pdf. 
  16. IBM Corporation (2008). High Level Assembler for Linux on zSeries User's Guide. http://publibfp.dhe.ibm.com/epubs/pdf/asml1020.pdf. 
  17. "IBM HIGH LEVEL ASSEMBLER/MVS & VM & VSE". Announcement letters. IBM Corporation. May 5, 1992. http://www.ibm.com/common/ssi/cgi-bin/ssialias?infotype=an&subtype=ca&htmlfid=897/ENUS292-244&language=enus. Retrieved October 8, 2012. 
  18. IBM Corporation (1995). IBM High Level Assembler for MVS & VM & VSE Release 2 Presentation Guide. http://www.redbooks.ibm.com/redbooks/pdfs/sg243910.pdf. 
  19. 19.0 19.1 IBM Corporation (1966). IBM System/360 Model 44 Programming System Assembler Language. http://bitsavers.trailing-edge.com/pdf/ibm/360/model44/c28-6811-1_360_44_Asm.pdf. 
  20. IBM Corporation (1976). IBM Time Sharing System Assembler Programmer's Guide. http://bitsavers.informatik.uni-stuttgart.de/pdf/ibm/360/tss/GC28-2032-6_Time_Sharing_System_Assembler_Programmers_Guide_Apr76.pdf. 
  21. Alcock, David. "Dave's z/Architecture Assembler FAQ". Planet MVS. http://planetmvs.com/hlasm/s390faq.html#PCASM. Retrieved December 15, 2012. 
  22. Fujitsu ASSEMH manuals available from http://manuals.ts.fujitsu.com/index.php?id=1-2-2926-15435 (Retrieved 2016-02-27)
  23. Dignus, LLC. "Systems/ASM". http://www.dignus.com/dasm/. Retrieved December 15, 2012. 
  24. Tachyon Software LLC. "Tachyon Software". http://www.tachyonsoft.com/. Retrieved December 15, 2012. 
Additional references
  • Rudd, Anthony. An Illustrated Guide for z/Architecture Assembler Programmers. Create Space (2012).

External links