Basic assembly language
Encyclopedia
BAL is a low-level language used on IBM
IBM
International Business Machines Corporation or IBM is an American multinational technology and consulting corporation headquartered in Armonk, New York, United States. IBM manufactures and sells computer hardware and software, and it offers infrastructure, hosting and consulting services in areas...

 mainframes
Mainframe computer
Mainframes are powerful computers used primarily by corporate and governmental organizations for critical applications, bulk data processing such as census, industry and consumer statistics, enterprise resource planning, and financial transaction processing.The term originally referred to the...

 from the earliest 360 series, through systems 370, 390 and z/Series, as well as the Univac 90/60
UNIVAC 90/60
The Univac 90/60 series computer was a mainframe class computer manufactured by Sperry Corporation as a competitor to the IBM System 360 series of mainframe computers...

, 90/70 and 90/80 mainframes made by Sperry Corporation
Sperry Corporation
Sperry Corporation was a major American equipment and electronics company whose existence spanned more than seven decades of the twentieth century...

. The earliest version was provided with the System/360
System/360
The IBM System/360 was a mainframe computer system family first announced by IBM on April 7, 1964, and sold between 1964 and 1978. It was the first family of computers designed to cover the complete range of applications, from small to large, both commercial and scientific...

 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".

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
Input/output
In computing, input/output, or I/O, refers to the communication between an information processing system , and the outside world, possibly a human, or another information processing system. Inputs are the signals or data received by the system, and outputs are the signals or data sent from it...

: 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.

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
Z/Architecture
z/Architecture, initially and briefly called ESA Modal Extensions , refers to IBM's 64-bit computing architecture for IBM mainframe computers. IBM introduced its first z/Architecture-based system, the zSeries Model 900, in late 2000. Later z/Architecture systems include the IBM z800, z990, z890,...

. Each of these architectures has retained compatibility
Computer compatibility
A family of computer models is said to be compatible if certain software that runs on one of the models can also be run on all other models of the family. The computer models may differ in performance, reliability or some other characteristic...

 with most of the features of its predecessor. BAL uses the native instruction set
Instruction set
An instruction set, or instruction set architecture , is the part of the computer architecture related to programming, including the native data types, instructions, registers, addressing modes, memory architecture, interrupt and exception handling, and external I/O...

 of these machines. It is thus closer to the hardware than third-generation languages such as COBOL
COBOL
COBOL is one of the oldest programming languages. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments....

.

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
COBOL
COBOL is one of the oldest programming languages. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments....

 or Fortran
Fortran
Fortran is a general-purpose, procedural, imperative programming language that is especially suited to numeric computation and scientific computing...

. 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
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

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.

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 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 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
MVS
Multiple Virtual Storage, more commonly called MVS, was the most commonly used operating system on the System/370 and System/390 IBM mainframe computers...

, 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
Job Control Language
Job Control Language is a scripting language used on IBM mainframe operating systems to instruct the system on how to run a batch job or start a subsystem....

 (JCL) like this
// EXEC PGM=HELLO
or, alternatively, it can be CALLed as a subroutine from such a program.
CALL HELLO

Types of instructions

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

Machine instructions (Mnemonic
Mnemonic
A mnemonic , or mnemonic device, is any learning technique that aids memory. To improve long term memory, mnemonic systems are used to make memorization easier. Commonly encountered mnemonics are often verbal, such as a very short poem or a special word used to help a person remember something,...

)

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
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 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

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.

Macros and conditional assembly

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 macro's 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
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

, and the OS provides standard macros for requesting those services. These are analogous to Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 system call
System call
In computing, a system call is how a program requests a service from an operating system's kernel. This may include hardware related services , creating and executing new processes, and communicating with integral kernel services...

s. For instance, in MVS
MVS
Multiple Virtual Storage, more commonly called MVS, was the most commonly used operating system on the System/370 and System/390 IBM mainframe computers...

(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.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK