Encoding and Decoding Practice Exercise

This exercise is intended to help you understand encoding and decoding.

It is not a homework assignment and will not be graded.


Here is part of the listing of a short program.

We want to fill in the blanks on the assembly listing below, using implicit addresses where possible:

 LOCATION COUNTER   MACHINE                 SOURCE
 VALUE (HEX)        LANGUAGE (HEX)          LANGUAGE

           000000                           PRAC     CSECT
           000000                                    USING PRAC,15
           000000   _______________                  L     2,F33 

         ________   _______________                  LA    3,3

         ________   _______________                  MR    2,2

         ________   5020 F034                        _______________

         ________   _______________                  AR    3,3      

         ________   5D20 F02C                        _______________

         ________   47A0 E000                        _______________

         ________   _______________                  BR    14

         ________   _______________         F129     DC    F'129'

           000020   _______________         F33      DC    F'33'

         ________   _______________         AB       DC    2CL3'AB'

         ________   _______________         BC       DC    F'-15'

         ________   _______________         CD       DC    3C'$'

         ________   _______________         TOTAL    DS    F'33'

                                            END      PRAC

Where do we start with this task? The assembler begins its work by computing locations. For each line of code, we have either the object code (such as "5020 F034") or the ordinary human-readable instructions (such as "AR 3,3"). In either case, we can decide on the length of the instruction in bytes.

For instance, with "5020 F034", we can look up the operation code 50 in the Reference Summary and learn that this is a ST instruction and is of type RX. An RX instruction is 4 bytes long.

Once we know how long each instruction is, we can add it to the location counter for the previous instruction and fill in the values, one at a time.

What about the DS and DC statements? Each of these also has a length depending on the type of data, the multiplier and the length declared. Thus "2CL3" takes up 2 * 3 = 6 bytes (as each character is stored as 1 byyte) and "F" (a fullword) takes up 4 bytes.

One detail to notice here is that a fullword must be on a fullword boundary, that is, an address which is a multiple of 4. Sometimes this makes it necessary to skip over 1, 2 or 3 bytes to reach the next fullword boundary. What happens to those bytes? They are simply wasted space, not used. (These are sometimes called "slack bytes".)

Once we have all the location counter values, we can do the encoding and decoding. In particular, we cannot encode or decode anything involving an implicit address until we know the location counter values that correspond to the labels.

For instance, if we needed to encode "ST 7,BC", we would need to know the address of BC as a D(X,B) expression, and the value D = the location counter value for the variable BC.