›› Moving data

Index



Move Immediate (MVI) instruction

The MVI instruction is a SI type instruction. It moves one byte from the instruction the a storage area.

Instruction format


   +--------+-------+-------+---+---+
   | op-code|   I2  | B1| D1| D1| D1|  4 bytes long x'92'
   +--------+-------+-------+---+---+
   0        8       16      24      31
   
        Format:
        MVI   D1(B1),I2

          MVI    AREA,C'A'             /* Move 'A' into AREA        */ 
          MVI    NAME+6,C'B'           /* Move 'A' into name + 6    */ 		  
          MVI    BINARY,X'00'          /* Move x'00' to BINARY      */ 		  		  


Move (MVC) instruction (x'D2')

The MVC instruction is a storage to storage instruction. It is used to copy up to 256 bytes from one place in storage to another. The data in the destination area will be replaced with new new data.

The amount of bytes to be copied is determined by the length of the receiving field. You need to either explicitly define the length or the assembler will determine the destination length at assembly time.

You need to specify the actual amount of data to be moved start to count at 1. Internally the instruction will store this with a value -1. You are moving 256 bytes and they are numbered internally from 0 to 255.


MVC instruction (x'D2')

The MVC character instruction operates by coping the first byte from the sending field to the first byte of the receiving field. This is done left to right.

Instead of having the instruction copy the first byte to the first field in the receiving field you can tell it to copy the first byte to the corresponding byte in the receiving field to the next byte in the receiving field.
This is a easy way to use MVC to clear a field or load it with all the same data.
This diagram will illustrate this process:

These are the instructions used to achieve this task:

          MVI    TEMP(8),SOURCE      /* make a copy of the data      */
          MVC    SOURCE+1(8),TEMP    /* move then one byte down in   */
                                     /* the area                     */

Here is an example to move data up in the data area

This will move one 'A' into the left most position. We then move the next 6 bytes with the 'A' character.

Using the basis on how the MVC instruction functions you can now alter the starting positions to move data forward or backward in a string. Pay special attention because this is destructive and when you are not careful you might overly your data.


Here is an example to move data up in the data area

          MVI    TEMP(8),SOURCE      /* make a copy of the data      */
          MVC    SOURCE+1(8),TEMP    /* move then one byte down in   */ 
                                     /* the area                     */


This example will move data down in the data area. It would move 4 bytes into the data area and start move data from this area for 6 bytes to the the destination.

          MVC    SOURCE(6),SOURCE+4      /* make a copy of the data  */

This diagram demonstrate the data movement.



Move Long (MVCL) instruction (x'0E')

Unlike the MVC instruction the MVCL instruction is a register-to-register instruction. This instruction will use 4 registers in two even-odd register pairs.

The even registers gets loaded with the addresses of the sending and receiving fields. The first operand will contain the receiving address and the second even register will contain the sending field address.

The odd registers contain length values in the the right 3 bytes of the register.

In the sending field pair odd register you can place a fill character in the 4th byte. If the receiving field is longer then the sending field this character will be used to pad the field on the right.

The instruction will add 1 to the address to copy the next byte too and subtract 1 from the length value after every successful copy.

As in the MVC instruction the copy is done from left to right. Overlap is not allowed in the MVCL instruction. If this happens the condition code will be set to 3 and no movement will happen.

The maximum amount of data that can be copied with this instruction is 16 megabytes as the length indicator is the right 3 bytes of the odd register values.

In addition to copying the data this instruction will also set a condition code as shown in below.


Instruction format


   +--------+---+---+                   
   | op-code| R2| R4|                4 bytes long x	'0E'
   +--------+---+---+                
   0        8       15                 
   
        Format:
        MVCL  R2,R4
			

Condition codes is set as follows:

  • equal field lengths CC=0
  • Receiving field smaller CC=1
  • Receiving field larger CC=2
  • Overlap field larger CC=3



Here is an example:

MVCLEX1  EQU   *
RECEIVE  DC    CL'SOMEDATA'            /* Assume the register        */
SEND     DC    CL'A LONGER FIELD'      /* contain the following:     */
                                       /* R6 = 4000                  */
         LA    R6,RECEIVE              /* R8 = 8000                  */
         LH    R7,=H'8'                /*                            */		 		 
         LA    R8,SEND                 /*                            */
         LH    R9,='14'                /*                            */		 
         MVCL  R6,R8                   /*                            */		 		 

After this is done the field would look like this:
REVEICE  DC    C'A LONGER'            /*                            */
SEND     DC    C'A LONGER FIELD'      /*                            */

And the register would contain:
R6 = 4009   (start + length of data moved + 1)
R7 = 0                   
R8 = 8008   (start  + lenth of data moved + 1)
R9 = 8 (14 - 6)

MVCLEX2  EQU   *
SEND     DC    CL'SOMEDATA'            /* Assume the register        */
RECEIVE  DC    CL'A LONGER FIELD'      /* contain the following:     */
                                       /* R6 = 4000                  */
         LA    R6,SEND                 /* R8 = 8000                  */
         LH    R7,=H'8'                /*                            */		 		 
         LA    R8,RECEIVE              /*                            */
         LH    R9,='14'                /*                            */		 
         ICM   R9,8,=C''               /* Load high order byte or    */		 		 
                                       /* R9 with blank              */		 		 		 
         MVCL  R6,R8                   /*                            */		 		 

After this is done the field would look like this:
SEND     DC    C'SOMEDATA'             /*                            */
RECEIVE  DC    C'SOMEDATA      '       /*                            */

And the register would contain:
R6 = 400D   (start + length of data moved + 1)
R7 = 0                   
R8 = 800D   (start  + lenth of data moved + 1)
R9 = X'40000000' fill character and zeros.

* Example to set large area to zeros
MVCLEX3  EQU   *
         LA    R4,TOZEROS              /*                            */
         LH    R5,=H'4000'             /*                            */
         LA    R6,0                    /* Not really going to use    */
                                       /* this data as we are setting*/		 
         SR    R7,R7                   /* R7 to zero here.           */		 		 		 
         MVCL  R4,R6                   /*                            */		 		 



Store (ST) instruction (x'50')

The ST instruction will store the content from a register into a fullword storage area.

Instruction format


   +--------+---+---+-------+---+---+
   | op-code| R1| X2| B2| D2| D2| D2|  4 bytes long x'50'
   +--------+---+---+-------+---+---+
   0        8       16      24      31
   
        Format:
        ST  R1,D2(X2,B2)

          ST    R1,STGAREA             /* Copy content from R1       */
          DS    STGAREA    F           /* into STGAREA               */



Store Halfword (STH) instruction

The STH instruction will store the right most 2 bytes or a register into a storage area.

Instruction format

   +--------+---+---+-------+---+---+
   | op-code| R1| X2| B2| D2| D2| D2|  4 bytes long x'40'
   +--------+---+---+-------+---+---+
   0        8       16      24      31
   
        Format:
        ST  R1,D2(X2,B2)

          STH   R1,STGAREA             /* Copy rightmost 2 bytes from*/ 		  		  
		  DS    STGAREA    H           /* R1 into STGAREA            */



Store Multiple (STM) instruction

STM will store multiple consecutive registers into multiple consecutive storage areas. If you specify the starting register to be higher then the ending register this instruction would wrap.

Instruction format

   +--------+---+---+---+---+---+---+
   | op-code| R1| R3| B2|     D2    |  4 bytes long x'90'
   +--------+---+---+---+---+---+---+
   0        8       16      24      31
   
        Format:
        STM R1,R3,D2(B2)

EXMP1     STM   R1,R3,REG1             /* Copy R1, R2 AND R3 into    */
REG1      DS    F                      /* the 3 storage areas start  */
REG2      DS    F                      /* at REG1                    */
REG3      DS    F                      /*                            */


EXMP2     STM   R14,R12,SAVEAREA       /* Copy R14, R15, R0, R1...R12*/ 		  		  
          DS    SAVEAREA 15F           /* into SAVEAREA              */



Load Address (LA) instruction

The next two instructions LOAD address and LOAD is worth spending some time on. Make sure you understand the difference 100%.

Both instructions calculate the effective address from the second part of the instruction. LA then loaded this address into the register. Remember from the introduction the displacement can not be larger then 4095. Instruction format

   +--------+---+---+---+---+---+---+
   | op-code| R1| X2| B2|     D2    |  4 bytes long x'41'
   +--------+---+---+---+---+---+---+
   0        8       16      24      31
   
        Format:
        LA    R1,D2(X2,B2)

R1 before '00000000'
R1 after  '00000080'

LAEX1     LA   R1,5                    /* Load the number 5 into R1  */
LAEX1     LA   R1,5                    /* No base or index used.     */

LAEX2     LA   R1,DATA                 /* Loads the effective address*/
                                       /* of DATA into R2            */
									   
LAEX3     LA   R1,5(R1)                /* Add 5 to R1                */



Load (L) instruction

The effective address is calculated and the fullword at this address is loaded into the register.

Instruction format

   +--------+---+---+---+---+---+---+
   | op-code| R1| X2| B2|     D2    |  4 bytes long x'58'
   +--------+---+---+---+---+---+---+
   0        8       16      24      31
   
        Format:
        L    R1,D2(X2,B2)

R1 before '00000000'
R1 after  '00000080'

LEX1      L    R1,REG1                 /*Copy fullword from effective*/
REG1      DC   F'80'                   /* into R1                    */


Load Halfword (LH) instruction

Load loads the content of a halfword into a register. The storage address must be on a fullword boundary.

Instruction format

   +--------+---+---+---+---+---+---+
   | op-code| R1| X2| B2|     D2    |  4 bytes long x'48'
   +--------+---+---+---+---+---+---+
   0        8       16      24      31

        Format:
        LH   R1,D2(X2,B2)   


LEX1      LH   R1,REG1                 /* Copy data from storage     */
REG1      DC   H'80'                   /* area  REG1 to register 1   */



Load Multiple (LM) instruction

Load Multiple does the reverse from STM. It starts at a storage area and start loading these fullword areas into registers.

Instruction format

   +--------+---+---+---+---+---+---+
   | op-code| R1| R3| B2|     D2    |  4 bytes long x'98'
   +--------+---+---+---+---+---+---+
   0        8       16      24      31

        Format:
        LH   R1,R3,D2(B2)   

LMEX1     LM   R1,R3,REG1              /* Copy data from storages    */
REG1      DS    F                      /* areas REG1, REG2, REG 3    */
REG2      DS    F                      /* into register 1, 2 and 3.  */
REG3      DS    F                      /*                            */


LMEX2     LM    R14,R12,SAVEAREA       /* Copy data from SAVEAREA    */ 		  		  
          DS    SAVEAREA 15F           /* into R14, R15, R0...R12    */



Insert Character (IC) instruction

Instruction format

   +--------+---+---+---+---+---+---+                
   | op-code| R1| X1| B1|     D1    |       4 bytes long x'43'
   +--------+---+---+---+---+---+---+                      
   0        8       16  20         31                   

        Format:
        IC   R1,D2(X2,B2)  

                                       /*                            */



Insert Character under mask (ICM) instruction

Instruction format

   +--------+---+---+---+---+---+---+                
   | op-code| R1| M1| B1|     D1    |       4 bytes long x'BF'
   +--------+---+---+---+---+---+---+                      
   0        8       16  20         31                   

        Format:
        ICM  R1,M3,D2(B2)  

                                       /*                            */



Convert to Binary (CVB) instruction

Instruction format

   +--------+---+---+---+---+---+---+                 
   | op-code| R1| X1| B2|     D2    |    4 bytes long x'4F'
   +--------+---+---+---+---+---+---+                
   0        8       16  20         31                 

        Format:
        CVB   R1,D2(X2,B2)   

                                       /*                            */



Convert to Decimal (CVD) instruction

Instruction format

   +--------+---+---+---+---+---+---+                 
   | op-code| R1| X1| B2|     D2    |    4 bytes long x'4E'
   +--------+---+---+---+---+---+---+                
   0        8       16  20         31                 

        Format:
        CVD   R1,D2(X2,B2)   

CVDEX1   ZAP                           /*                            */



Zero and ADD (ZAP) instruction

Instruction format

   +--------+---+---+---+---+---+---+---+---+---+---+
   | op-code| L1| L3| B1|     D1    | B2|     D2    |  6 bytes long x'F8'
   +--------+---+---+---+---+---+---+---+---+---+---+
   0        8       16  20          32  36          47

        Format:
        ZAP   D1(L1,B1),D2(L2,B2)   

ZAPEX1   ZAP                           /*                            */

PACK (PACK) instruction

Instruction format

   +--------+---+---+---+---+---+---+---+---+---+---+
   | op-code| L1| L3| B1|     D1    | B2|     D2    |  6 bytes long x'F2'
   +--------+---+---+---+---+---+---+---+---+---+---+
   0        8       16  20          32  36          47

        Format:
        PACK   D1(L1,B1),D2(L2,B2)   

PACKEX1  PACK                          /*                            */



Unpack (UNPK) instruction

Instruction format

   +--------+---+---+---+---+---+---+---+---+---+---+
   | op-code| L1| L3| B1|     D1    | B2|     D2    |  6 bytes long x'F3'
   +--------+---+---+---+---+---+---+---+---+---+---+
   0        8       16  20          32  36          47

        Format:
        PACK   D1(L1,B1),D2(L2,B2)   

UNPKEX1  UNPK                          /*                            */



Edit (ED) instruction

Instruction format

   +--------+---+---+---+---+---+---+---+---+---+---+
   | op-code|     L | B1|     D1    | B2|     D2    |  6 bytes long x'DE'
   +--------+---+---+---+---+---+---+---+---+---+---+
   0        8       16  20          32  36          47

        Format:
        ED   D1(L,B1),D2(B2)  

EDEX1                                  /*                            */



Data Movement Summary

The next table can be used as a quick reference when you have to move data and need to determine what instructions to use when moving to different data tipes.

Assembler data movement instructions

Sending field Receiving fields
BIN in storage BIN in register Packed-decimal Numeric Character Edited Character
  Binary
  in storage
  COMP
MVC L, LH, LM L+CVD L+CVD+UNPK L+CVD+ED
  Binary 
  in register
  COMP
ST, STH, STM LR CVD CVD+UNPK CVD+ED
  Packed
  COMP-3
CVB+ST CVB ZAP UNPK ED
  Numeric
  Character  
PACK+CVB+ST PACK+CVB PACK MVC PACK+ED
 

Links