In many cases, the data we need to work with is not simply binary integers but names, phrases, passwords and other items which are stored as character variables of some length.
We have instructions for working with character variables.
Move Character (MVC)
MVC is used to copy character values from one location to another. The syntax for using it is like this:
MVC D1(L,B1),D2(B2)
where
Here L is in the range 1 to 256.
MVC will copy bytes, one at a time, left to right, from the source to the destination.
It is possible that the source and destination fields may overlap.
This is a type SS instruction. The length L is encoded in the machine code as 1 byte, stored as 1 less than its actual value. Thus the value we write down for L is 1 to 256, but the encoded value is 0 to 255 (and thus will fit into 1 byte).
Example: Suppose we have defined two character variables:
INNAME DS CL15 OUTNAME DS CL15
At some point we have data in INNAME and we want a copy of it in OUTNAME. We can do the following:
MVC OUTNAME(15),INNAME
If we omitted the length, as in
MVC OUTNAME,INNAME
the assembler would look up the length associated with OUTNAME and use that value. This is usually what we want, but some programmers prefer to code the length explicitly every time.
Move Character Immediate (MVI)
MVI is used to se the value of a single byte in memory to a specified value. The syntax for using it is like this:
MVI D(B),I
where
Here I is what is called an immediate byte, a constant which is encoded into the machine instruction itself. We can specify the value of I in several ways such as C'A' or X'C1' or B'11000001'.
This is a type SI instruction. The immediate byte I is encoded in the machine instruction as the second byte.
Example: Suppose we have defined a character variable:
FLAG DS C
At some point, we want it to contain the value C'Z'. We can do the following:
MVI FLAG,C'Z'
Another way to do the same thing would be:
MVC FLAG(1),=C'Z'
but that uses more memory than the MVI, 7 bytes instead of 4.
Compare Logical (CLC)
CLC is used to compare two character values. The syntax for using it is like this:
CLC D1(L,B1),D1(B2)
where
CLC will compare bytes from the two variables, one at a time, left to right, until it either finds a difference or finishes looking at L characters.
It is possible that the two variables may overlap.
This is a type SS instruction. The length L is encoded in the machine code as 1 byte, stored as 1 less than its actual value. Thus the value we write down for L is 1 to 256, but the encoded value is 0 to 255 (and thus will fit into 1 byte).
CLC will set the condition code:
It is useful to remember that CLC is comparing bytes by their numerical values (0 to 255 apiece). In assembly language, we are using the EBCDIC encoding sequence, in which lower-case letters 'a' to 'z' come before upper-case letters 'A' to 'Z' which come before digits 0-9.
This is not the same as in the widely-used ASCII encoding sequence.
Example: Suppose we have the variable INNAME as defined above. We want to know if it contains the value 'JONES'. We can do the following:
CLC INNAME(15),=CL15'JONES'
Compare Logical Immediate (CLI)
CLI is used to compare the value of a single byte in memory to a specified value. The syntax for using it looks like this:
CLI D(B),I
where
This is a type SI instruction. The immediate byte I is encoded in the machine instruction as the second byte.
CLI will set the condition code:
Example: Suppose we have the variable FLAG as defined above. We want to know if FLAG contains the value C'M'. We can do the following:
CLI FLAG,C'M'
Destructive Overlap
Sometimes we have a character variable and we want to fill it with some particular value. For instance, we might have a line we are using to print data and we want to fill it with blanks. This can be done using a technique called destructive overlap.
Example: Suppose we have defined the following:
PLINE DC 121C' '
At some point in our program, we have moved various data into PLINE and printed it, and now we want it to be as it was before. We can do the following:
MVI PLINE,C' ' MVC PLINE+1(120),PLINE
The effect is that the blank in the first byte is copied to the second byte, which is then copied to the third byte, and so on.
Example: Suppose we instead would like to fill up PLINE with a repeating pattern such as '*.*.*.*.*.' and so on. We can do the following:
MVC PLINE(2),=CL2'*.' MVC PLINE+2(119),PLINE