IBM Basic assembly language and successors: Difference between revisions

Content deleted Content added
Line 14:
 
==A small example==
The following fragment shows how the logic "ifIf SEX = 'M', add 1 to MALES; else, add 1 to FEMALES" would be performed in Assembler.
 
<pre>
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 LEQU * 7,FEMALES If not male, load FEMALES into registerA 7;label
LAL 7,1(,7)FEMALES If not male, load current value in addFEMALES 1;
STLA 7,FEMALES1(,7) add 1 (pre-XA max value and24 storebits)
ST 7,FEMALES and store
GO_ON EQU *
GO_ON EQU * - rest of program -
*
MALES DC F'0' defines 31 bit memory ___location (initially=0)
FEMALES DC F'0' "" ""
</pre>
 
The following is the ubiquitous [[Hello world]] program, and would, executing under suchan IBM Operating systems such as [[OS VS/1]] and [[MVS]], display the words 'Hello World' on the operator's console:
 
<pre>
HELLO CSECT The name of this program is 'HELLO'
* USING *,12 Register 15 points Tellhere assembleron whatentry registerfrom weOp/sys areor usingcaller.
SAVEUSING (14*,12) Save registers Tell assembler what register we are using for pgm. base
LR STM 14,12,15 4(13) Save registers 14,15,and Use0 Registerthru 12 forin thiscallers programSave area
LR 12,15 Set up base register with programs entry point address
WTO 'Hello World' Write To Operator
RETURNLA (14 R13,12)SAVE ReturnNow point to callingour own embedded save area party
* -end of housekeeping (similar for most programs) -
WTO 'Hello World' Write To Operator (Operating System macro)
*
LM 14,12,4(13) Restore registers as on entry
BR 14 Return to caller
GO_ON* EQU *
SAVE DS 18A Define 18 fullwords for calling
END HELLO This is the end of the program
</pre>
Note: "WTO" is an Assembler macro that generates an Operating System call
 
Note that becauseBecause of thesaving methodregisters ofand defininglater programs by saving registersrestoring and returning, this small program is usable either to be directly executed fromas a batch program calledinvoked fromdirectly by the operating system or[[Job cancontrol belanguage]] used(JCL) aslike athis subroutine from another program.
// EXEC PGM=HELLO
or, alternatively, it can be CALLed as a subroutine from such a program.
CALL HELLO
 
==Types of instructions==