Referencing the location counter value
The value of the location counter is referenced by using the asterisk (*)
When used in an instruction, the value of the asterisk resolves to the address of the instruction.
Loc Cntr Value Assembler Code 000100 B PASTLOAD 000104 L R1,0(,R2) 000108 PASTLOAD M R4,=F'9' 000100 B *+8 000104 L R1,0(,R2) 000108 M R4,=F'9' *+8 is interpreted as the value of the location counter before generation of the instruction plus 8 PRO: avoid cluttering up a program with a bunch of labels CON: must be updated if instructions are added/deleted
Altering the location counter value
The value of the location counter can be altered by using the ORG instruction.
Format 1: ORG address comment - sets the location counter value to the specified address Format 2: ORG , comment - sets the location counter value to the next available unused location in the program Similar to COBOL's REDEFINES clause Example 1: Suppose that the routine BUILD has to start at address 000450. It can be positioned at the address using ORG Loc Cntr Value Assembler Code ORG X'000450' 000450 BUILD DS 0H 000450 STM R0,R15,BSAVE 000454 LM R3,R5,0(R1) 000458 ... Example 2: Suppose that an input record can have 2 formats. The format of the record depends on the first character. ORG can be used to define storage so NAMED areas of storage can be referenced in the code, rather than using displacements. Name: 1 Code N Address: 1 Code A 2 - 16 First Name 2 - 41 Address 17 - 31 Last Name 42 - 61 City 32 - 80 Unused 62 - 63 State 64 - 80 Unused ASSEMBLER code before ORG: Loc Cntr Value Assembler Code 000080 BUFFER DS CL80 Input buffer 0000D0 PLINE DC CL1'-' Print line for records 0000D1 DC CL131' ' In the code: XREAD BUFFER,80 Read a record CLI BUFFER,C'N' Check for name record BNE ADDR Goto next check if not N MVC PLINE+10(15),BUFFER+1 Move first name to print line MVC PLINE+30(15),BUFFER+16 Move last name to print line B PRINT Print the line * ADDR CLI BUFFER,C'A' Check for address record BNE ERROR Goto error routine if not A MVC PLINE+12(40),BUFFER+1 Move address to print line MVC PLINE+60(20),BUFFER+41 Move the city to print line MVC PLINE+85(2),BUFFER+61 Move the state to print line B PRINT Print the line * ERROR MVC PLINE+1,=C'*** Error: invalid record ***' PRINT XPRNT PLINE,132 Print the line ASSEMBLER code after ORG: Loc Cntr Value Assembler Code 000080 BUFFER DS CL80 ORG BUFFER change LCV to 000080 000080 CODE DS CL1 000081 RESTREC DS CL79 ORG RESTREC change LCV to 000081 000081 FIRST DS CL15 000090 LAST DS CL15 ORG RESTREC change LCV to 000081 000081 ADDRESS DS CL40 0000A9 CITY DS CL20 0000BD STATE DS CL2 ORG , change LCV to 0000D0 0000D0 PLINE DC CL1'-' In the code: XREAD BUFFER,80 Read a record CLI CODE,C'N' Check for name record BNE ADDR Goto next check if not N MVC PLINE+10(15),FIRST Move first name to print line MVC PLINE+30(15),LAST Move last name to print line B PRINT Print the line * ADDR CLI CODE,C'A' Check for address record BNE ERROR Goto error routine if not A MVC PLINE+12(40),ADDRESS Move address to print line MVC PLINE+60(20),CITY Move the city to print line MVC PLINE+85(2),STATE Move the state to print line B PRINT Print the line * ERROR MVC PLINE+1,=C'*** Error: invalid record ***' PRINT XPRNT PLINE,132 Print the line