Task

Create and display the sequence of binary digits for a given   non-negative integer.

   The decimal value      5   should produce an output of               101
   The decimal value     50   should produce an output of            110010
   The decimal value   9000   should produce an output of    10001100101000

The results can be achieved using built-in radix functions within the language   (if these are available),   or alternatively a user defined function can be used.

The output produced should consist just of the binary digits of each number followed by a   newline.

There should be no other whitespace, radix or sign markers in the produced output, and leading zeros should not appear in the results.




*        Binary digits             27/08/2015
BINARY   CSECT
         USING  BINARY,R12
         LR     R12,R15            set base register
BEGIN    LA     R10,4
         LA     R9,N
LOOPN    MVC    W,0(R9)
         MVI    FLAG,X'00'
         LA     R8,32
         LA     R2,CBIN
LOOP     TM     W,B'10000000'      test fist bit
         BZ     ZERO               zero
         MVI    FLAG,X'01'         one written
         MVI    0(R2),C'1'         write 1
         B      CONT
ZERO     CLI    FLAG,X'01'         is one written ?
         BNE    BLANK
         MVI    0(R2),C'0'         write 0
         B      CONT
BLANK    BCTR   R2,0               backspace
CONT     L      R3,W
         SLL    R3,1               shilf left
         ST     R3,W
         LA     R2,1(R2)           next bit
         BCT    R8,LOOP            loop on bits
PRINT    CLI    FLAG,X'00'         is '0'
         BNE    NOTZERO
         MVI    0(R2),C'0'         then write 0
NOTZERO  L      R1,0(R9)
         XDECO  R1,CDEC
         XPRNT  CDEC,45
         LA     R9,4(R9)
         BCT    R10,LOOPN          loop on numbers
RETURN   XR     R15,R15            set return code
         BR     R14                return to caller
N        DC     F'0',F'5',F'50',F'9000'
W        DS     F                  work
FLAG     DS     X                  flag for trailing blanks
CDEC     DS     CL12               decimal value
         DC     C' '            
CBIN     DC     CL32' '            binary value
         YREGS  
         END    BINARY