Understanding the location counter
The primary task for the assembler is to convert your symbolic machine instruction to the actual machine instruction. for instance000AC D20F A08A B0C0 0008A 000E0 101 MVC PGM2_EXEC,PGM2_LIST
The MVC coresponds to the D2 and that will be all for now. At the very left of the line you will see the position of the instruction according to the other instructions in your program. We could call it the offset to the beginning of the program. Here it is in hexadecimal and the offset is called the Location Counter. It is increased by the length of the present instruction so there is space for the next instruction. Not complicated, - but very important!!
First of all you have to keep in mind that this is on the time of assembling your program. An asterisks (*) refers to the current position of your location counter.
Here comes an example. The first line A(*+8) means current position (look left) which is X' E0' plus 8 equals X'E8'. That is the location counter of the third line. That will later be resolved into the address of the program name, but that is another story.
0000E0 000000E8 130+PGM2_LIST DC A(*+8)
0000E4 00000000 131+ DC A(0)
0000E8 D7C7D4F240404040 132+ DC CL8'PGM2'
00010 133 PGM2_LGD EQU *-PGM2_LIST
The last line will calculate the length of the three instructions above. This is a pure assembler instruction and will NOT increase the location counter, - i.e. it will never end up as an machine instruction. That is why there is no location counter on the left. The assembler variable PGM2_LGD is calculated to the right of the EQU-instruction (EQUal).
* is the current value of the location counter and subtract it by the location counter for PGM_LIST. That equals to decimal 16 (X'10'). That is what the left most integer tells you.
It is always better to have the length in an variable, because you might put another field into the DSECT and your length of that DSECT will still be correct.
Length used explicit
You do not need to calculate the length every time. You can use the length as part of your instruction in order to manipulate the assembler to use another lenght. You can always put L' (quote) in front of your field. It will then be an assembler variable containing the length of that field.
000090 D20F A000 B17C 00000 001A0 91 MVC WSEC,=CL(L'WSEC)'PGM2-WS'
I wish to move the constant into the field WSEC but I don't know the length of WSEC. It doesn't matter because I will just set the length of the constant to the same as WSEC. The result is that the constant is padded with space to right, - exactly what I want. Take a look at the machine instruction. From the second byte of the instruction you can derive that the length is actually 16, (X'F' + 1).
Take a look at these four instructions and tell me what the second one does,
0000A0 4430 B084 000A8 99 EX R3,MVC
0000A4 47F0 B08A 000AE 100 B MVC+L'MVC
0000A8 D200 A016 2002 00016 00002 101 MVC MVC WTOTEXT(0),2(R2)
0000AE 4130 A014 00014 102 LA R3,WTOLGD
Yes, - it branches over the MVC-instruction to the last instruction. The Branch needs an offset and calculates it by taking the location counter of MVC, the label contains both the location counter and length. Both are added together (MVC+l'MVC) and the result 000AE is showen. Look at the last line location counter and you will see it is correct.
Ingen kommentarer:
Send en kommentar