onsdag den 25. november 2015

Brave new world (2) - Strings

Strings

In this new brave world of Intel servers etc., System z and z/OS have to deal with strings. A string is a set of (ASCII) characters ended with a “String Terminator”, usually “Null” (binary zero). You have to count the characters if you wish to know the length of the string. That is a legacy from the paper tapes that contained ASCII strings terminated with null. Strings have continued to files, TCP/IP communication etc. Strings are build into programming languages like C, C++, and Java, hense we have to deal with them so two new instructions have been developed which I will describe below:
  • CLST - Compare Logical String
  • MVST - Move String

CLST - Compare Logical String

CLST compare two strings of bytes. Only if they have the same length and every byte are equal it satisfies a Branch Equal (BE). Otherwise the first operand is either lower or higher than the second operand. The terminating character can be any 8 bit byte, usually X’00’ but in the first example it is EBCDIC Space (X’40’). The string terminator is always the low order byte of register zero. Make sure that register 0 is zero except maybe for the low order byte.
        XR    0,0            
        ICM   0,B'0001',=C' '
        LA    R1,PARM_STRING
        LA    R2,PARM        
        CLST  R1,R2          
        BE    START_PROCESS
        B     WRONG_PARM
PARM_STRING DC C'STRING '
CLST - Compare String

MVST - Move String

The MVST copies a string from one position to another. It is the string terminator of the second operand that decides the length of the copied string. The example below copies a string to OUTREC and the rest of OUTREC is padded with ASCII space (X’20’)
        L     R2,RECADR
        XR    0,0
        LA    R1,OUTREC                 
        MVC   OUTPUT_LENGTH,=A(L'OUTREC)
        MVST  R1,R2                     
        LA    R2,OUTREC+L'OUTREC        
        SR    R2,R1                     
        MVI   0(R1),X'20'               
        S     R2,=A(2)                  
        EX    R2,MVC                    
        B     MVC+L'MVC                 
MVC      MVC   1(0,R1),0(R1)

MVST - Move String



Ingen kommentarer:

Send en kommentar