      TITLE   MOVEnm
      MODULE  MOVEnm
      AREADEF PROG,[CODE,PIC,READ],DOUBLE
      EXPORTC MOVE12,MOVE21,MOVE14,MOVE41,MOVE24,MOVE42
;
      AREA    PROG
MOVE14 ; (IN,OUT,N) : move byte array to integer*4 (positive integers 0-255)
      BSR     init
      ADDR    R1[R2:D],R1     ;end of OUT
      ADDD    R0,R2           ;end of IN
      ALIGN   WORD,#XA2
l14   ADDQD   -4,R1
      ADDQD   -1,R2
      MOVZBD  0(R2),0(R1)     ;move with no sign extension
      CMPD    R0,R2
      BLT     l14             ;loop
      RXP     4
MOVE41 ; (IN,OUT,N) : move integer*4 array to byte (positive integers 0-255)
      BSR     init
      ADDD    R1,R2           ;end of OUT
      ALIGN   WORD,#XA2
l41   MOVB    0(R0),0(R1)     ;move with truncation if necessary
      ADDQD   1,R1
      ADDQD   4,R0
      CMPD    R1,R2
      BLT     l41             ;loop
      RXP     4
MOVE42 ; (IN,OUT,N) : move integer*4 array to integer*2
                    ; (positive integers 0-65535)
      BSR     init
      ADDR    R1[R2:W],R2     ;end of OUT
      ALIGN   WORD,#XA2
l42   MOVW    0(R0),0(R1)     ;move with truncation if necessary
      ADDQD   2,R1
      ADDQD   4,R0
      CMPD    R1,R2
      BLT     l42             ;loop
      RXP     4
;
init  MOVD    12(SP),R2
      MOVD    0(R2),R0        ;address of IN
      MOVD    4(R2),R1        ;address of OUT
      MOVD    8(R2),R2        ;address of N
      MOVD    0(R2),R2        ;N
      RET     0
;
MOVE12 ; (IN,OUT,N) : move byte array to integer*2 (positive integers 0-255)
      BSR     init
      ADDR    R1[R2:W],R1     ;end of OUT
      ADDD    R0,R2           ;end of IN
      ALIGN   WORD,#XA2
l12   ADDQD   -2,R1
      ADDQD   -1,R2
      MOVZBW  0(R2),0(R1)     ;move with no sign extension
      CMPD    R0,R2
      BLT     l12             ;loop
      RXP     4
MOVE21 ; (IN,OUT,N) : move integer*2 array to byte (positive integers 0-255)
      BSR     init
      ADDD    R1,R2           ;end of OUT
      ALIGN   WORD,#XA2
l21   MOVB    0(R0),0(R1)     ;move with truncation if necessary
      ADDQD   1,R1
      ADDQD   2,R0
      CMPD    R1,R2
      BLT     l21             ;loop
      RXP     4
MOVE24 ; (IN,OUT,N) : move integer*2 array to integer*4
                    ; (positive integers 0-65535)
      BSR     init
      ADDR    R1[R2:D],R1     ;end of OUT
      ADDR    R0[R2:W],R2     ;end of IN
      ALIGN   WORD,#XA2
l24   ADDQD   -4,R1
      ADDQD   -2,R2
      MOVZWD  0(R2),0(R1)     ;move with no sign extension
      CMPD    R0,R2
      BLT     l24             ;loop
      RXP     4
      END
