
Basic Data Operation

This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:


Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses




Task

Write a routine to perform a bitwise AND, OR, and XOR on two integers, a bitwise NOT on the first integer, a left shift, right shift, right arithmetic shift, left rotate, and right rotate.

All shifts and rotates should be done on the first integer with a shift/rotate amount of the second integer.

If any operation is not available in your language, note it.




*        Bitwise operations        15/02/2017
BITWISE  CSECT
         USING  BITWISE,R13
         B      72(R15)
         DC     17F'0'
         STM    R14,R12,12(R13)
         ST     R13,4(R15)
         ST     R15,8(R13)
         LR     R13,R15
         L      R1,A
         XDECO  R1,PG
         MVC    OP,=CL7'A='
         XPRNT  OP,L'OP+L'PG
         L      R1,B
         XDECO  R1,PG
         MVC    OP,=CL7'B='
         XPRNT  OP,L'OP+L'PG
*                                  And
         L      R1,A
         N      R1,B
         XDECO  R1,PG
         MVC    OP,=C'A AND B'
         XPRNT  OP,L'OP+L'PG
*                                  Or
         L      R1,A
         O      R1,B
         XDECO  R1,PG
         MVC    OP,=C'A OR  B'
         XPRNT  OP,L'OP+L'PG
*                                  Xor
         L      R1,A
         X      R1,B
         XDECO  R1,PG
         MVC    OP,=C'A XOR B'
         XPRNT  OP,L'OP+L'PG
*                                  Not
         L      R1,A
         X      R1,=X'FFFFFFFF'    not (by xor -1)
         XDECO  R1,PG
         MVC    OP,=CL7'NOT A'
         XPRNT  OP,L'OP+L'PG
*
         MVC    A,=X'80000008'     a=-2147483640 (-2^31+8)
         L      R1,A
         XDECO  R1,PG
         MVC    OP,=CL7'A='
         XPRNT  OP,L'OP+L'PG
*                                  shift right arithmetic (on 31 bits)
         L      R1,A
         SRA    R1,3
         XDECO  R1,PG
         MVC    OP,=C'A SRA 3'
         XPRNT  OP,L'OP+L'PG
*                                  shift left arithmetic (on 31 bits)
         L      R1,A
         SLA    R1,3
         XDECO  R1,PG
         MVC    OP,=C'A SLA 3'
         XPRNT  OP,L'OP+L'PG
*                                  shift right logical (on 32 bits)
         L      R1,A
         SRL    R1,3
         XDECO  R1,PG
         MVC    OP,=C'A SRL 3'
         XPRNT  OP,L'OP+L'PG
*                                  shift left logical (on 32 bits)
         L      R1,A
         SLL    R1,3
         XDECO  R1,PG
         MVC    OP,=C'A SLL 3'
         XPRNT  OP,L'OP+L'PG
*
RETURN   L      R13,4(0,R13)
         LM     R14,R12,12(R13)
         XR     R15,R15
         BR     R14
A        DC     F'21'
B        DC     F'3'
OP       DS     CL7
PG       DS     CL12
         YREGS
         END    BITWISE