IBM Basic Assembly Language - Examples

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,'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 callers Save area LR 12,15 Set up base register with programs entry point address USING *,12 Tell assembler what 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 LM 14,12,12(13) Restore registers as on entry 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'

Read more about this topic:  IBM Basic Assembly Language

Famous quotes containing the word examples:

    No rules exist, and examples are simply life-savers answering the appeals of rules making vain attempts to exist.
    André Breton (1896–1966)

    In the examples that I here bring in of what I have [read], heard, done or said, I have refrained from daring to alter even the smallest and most indifferent circumstances. My conscience falsifies not an iota; for my knowledge I cannot answer.
    Michel de Montaigne (1533–1592)

    Histories are more full of examples of the fidelity of dogs than of friends.
    Alexander Pope (1688–1744)