Assembler Bit Processing
Bit Manipulation
  Table of Contents  v-16.01.01 - asmbit01.htm 
  Introduction
  EXPAND the bits of a one-byte field into bytes of an eight-byte field
  COMPRESS the bytes of an eight-byte field into bits of a one-byte field
  Call Interface
  The JCL Member
  COBOL Mainline Program
  Assembler Bit Processing Routine
  COBOL Copy File for Pass Area
  Summary
  Software Agreement and Disclaimer
  Downloads and Links
  Current Server or Internet Access
  Internet Access Required
  Glossary of Terms
  Comments or Feedback
  Company Overview
The SimoTime Home Page 

Table of Contents Previous Section Next Section Introduction

This is an example of how COBOL program can call an Assembler routine do bit-level manipulation. The three basic functions provided are as follows.

1 Determine the setting of a bit (0 or 1).
2 Set a bit to 0.
3 Set a bit to 1.
  The Three Basic Functions provided by the Bit Manipulation Routine

This example uses an approach of converting the bit information in a single byte to or from an eight-byte field of COBOL accessible zeroes and ones. This example contains one JCL member to execute the two programs. The main COBOL program (CBLBITC1.CBL) is used to demonstrate and test the bit manipulation functions. The bit manipulation functions are in a separate, callable Assembler program (ASM4BITS.MLC). The COBOL program was written and tested using the VS COBOL II dialect. Also, the COBOL program will work with COBOL for MVS and COBOL/370. A JCL member is provided to run the job as an MVS batch job on an IBM Mainframe System or a Windows System with Micro Focus Enterprise Developer.

In the world of programming there are many ways to solve a problem. This suite of programs is provided as a "COBOL calling Assembler" programming example of one of the possible solutions to the problem of determining and changing the bits within a byte. This example may serve as a tutorial for new programmers and as a reference for experienced programmers. Additional information (including a COBOL routine that does bit manipulation) is provided in the Downloads and Links to Similar Pages section of this document.

Note: Refer to the Download and Links to Similar Pages section of this document for links to additional documents that discuss this topic.


We have made a significant effort to ensure the documents and software technologies are correct and accurate. We reserve the right to make changes without notice at any time. The function delivered in this version is based upon the enhancement requests from a specific group of users. The intent is to provide changes as the need arises and in a timeframe that is dependent upon the availability of resources.

Copyright © 1987-2017
SimoTime Technologies
All Rights Reserved

Table of Contents Previous Section Next Section EXPAND the bits of a one-byte field into bytes of an eight-byte field

For each bit that is ON (1) in the BTS-PASS-BITS field the corresponding byte in the BTS-PASS-BYTES field is set to a value of one. For each bit that is OFF (0) in the BTS-PASS-BITS field the corresponding byte in the BTS-PASS-BYTES field is set to a value of zero.

 Input BTS-PASS-BITS, a one byte field (8-bits)
 Output BTS-PASS-BYTES, an eight byte field
 Example if BTS-PASS-BITS = x'55' then BTS-PASS-BYTES will be '01010101'
  Expand Function of the Bit manipulation Routine

Table of Contents Previous Section Next Section COMPRESS the bytes of an eight-byte field into bits of a one-byte field

For each byte that is a one in the BTS-PASS-BYTES field the corresponding bit in the BTS-PASS-BITS field is set to ON (1). For each byte that is zero in the BTS-PASS-BYTES field the corresponding bit in the BTS-PASS-BITS field is set to OFF (0).

 Input BTS-PASS-BYTES, an eight byte field
 Output BTS-PASS-BITS, a one byte field (8-bits)
 Example if BTS-PASS-BYTES = '01010101' then BTS-PASS-BITS will be set to x'55'
  Compress Function of the Bit manipulation Routine

Table of Contents Previous Section Next Section Call Interface

The callable interface requires a data structure to be defined. A copy file (PASSBITS.cpy) is provided with the following source code.

      *****************************************************************
      *                PASSBITS is a COBOL Copy File                  *
      *     Data Structure or Pass Area used for calling SIMOBITS.    *
      *         Copyright (C) 1987-2017 SimoTime Technologies         *
      *                     All Rights Reserved                       *
      *****************************************************************
      *              Provided by SimoTime Technologies                *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************
      *
      * When BTS-PASS-REQUEST is 'EXPAND  ' do analysis of
      *      BTS-PASS-BITS (a 1-btye field of 8-bits)
      *      and based on the bit settings a corresponding value of
      *      0 or 1 is set in the BTS-PASS-BYTES (an 8-byte field
      *      of zeroes and ones).
      *
      * When BTS-PASS-REQUEST is 'COMPRESS' do analysis of
      *      BTS-PASS-BYTES (an 8-byte field of zeroes and ones)
      *      and based on a value of 0 or 1 the corresponding
      *      bit in BTS-PASS-BITS (a 1-byte field of 8-bits) is
      *      switched ON or OFF.
      *
       01  BTS-PASS-AREA.
           05  BTS-PASS-REQUEST            PIC X(8).
           05  BTS-PASS-RESULT             PIC S9(9)   COMP.
           05  BTS-PASS-RECORD.
               10  BTS-PASS-BITS           PIC X.
               10  BTS-PASS-BYTES.
                   15  BTS-PASS-BYTE-01    PIC X.
                   15  BTS-PASS-BYTE-02    PIC X.
                   15  BTS-PASS-BYTE-03    PIC X.
                   15  BTS-PASS-BYTE-04    PIC X.
                   15  BTS-PASS-BYTE-05    PIC X.
                   15  BTS-PASS-BYTE-06    PIC X.
                   15  BTS-PASS-BYTE-07    PIC X.
                   15  BTS-PASS-BYTE-08    PIC X.
      *
      ***  PASSBITS - End-of-Copy File - - - - - - - - - - - PASSBITS *
      *****************************************************************
      *

The following will translate an eight character field of 0's and 1's to a one byte field with the bits set to match to 0's and 1's of the eight character field. Please note: the content of the BTS-PASS-REQUEST field must be upper case and contain 'COMPRESS'

      *****************************************************************
      * The coding required to do the call to the Byte-Bit Routine    *
      * (translate an 8-byte field to a 1-byte field).                *
      *****************************************************************
           MOVE '11111111'         to BTS-PASS-BYTES
           MOVE 'COMPRESS'         to BTS-PASS-REQUEST
           CALL 'ASM4BITS'      using BTS-PASS-AREA

In the preceding example the contents of BTS-PASS-BITS will be X'FF' or high-value upon return from the call to ASM4BITS.

The following will set the individual bytes of an eight character field to 0's or 1's based on the bit settings of a one byte field. Please note: the content of the BTS-PASS-REQUEST field must be upper case and contain 'EXPAND' followed by two spaces

      *****************************************************************
      * The coding required to do the call to the Byte-Bit Routine    *
      * (translate a 1-byte field to an 8-byte field).                *
      *****************************************************************
           MOVE X'55'              to BTS-PASS-BITS
           MOVE 'EXPAND  '         to BTS-PASS-REQUEST
           CALL 'ASM4BITS'      using BTS-PASS-AREA

In the preceding example the contents of BTS-PASS-BYTES will be '01010101' upon return from the call to ASM4BITS.

Table of Contents Previous Section Next Section The JCL Member

The following is the mainframe JCL member (ASMBITJ1.jcl) that is required to run as a job on the mainframe or as a Mainframe Express project on the PC.

//ASMBITJ1 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1
//* *******************************************************************
//*       ASMBITJ1.JCL - a JCL Member for Batch Job Processing        *
//*       This JCL Member is provided by SimoTime Technologies        *
//*           (C) Copyright 1987-2017 All Rights Reserved             *
//*             Web Site URL:   http://www.simotime.com               *
//*                   e-mail:   helpdesk@simotime.com                 *
//* *******************************************************************
//*
//* Text   - COBOL calls ASSEMBLER for Bit and Byte manipulation
//* Author - SimoTime Technologies
//* Date   - January 01, 1989
//*
//* This set of programs illustrate the use a COBOL program that calls
//* an Assembler routine to do bit manipulation.
//* This suite of programs will convert between a one-byte
//* (consisting of eight-bits) field and an eight-byte field
//* consisting of ZEROES and ONES.
//*
//* The DD statement for SYSOUT is required by this example. The
//* COBOL program may be compiled using the SYSOUT directive and
//* without the DD statement for SYSOUT an RTS173 or RTS227 may occur.
//*
//* This set of programs will run on a mainframe under MVS or on
//* a Personal Computer running Windows and Mainframe Express by
//* Micro Focus.
//*
//*   ************
//*   * CBLBITJ1 *
//*   ********jcl*
//*        *
//*        *
//*   ************     ************
//*   * ASMBITC1 *-----* DISPLAY  *
//*   ********cbl*     ************
//*        *   *
//*        *   *       ************
//*        *   *-CALL--* ASM4BITS *
//*        *           ********cbl*
//*        *
//*   ************
//*   *   EOJ    *
//*   ************
//*
//* *******************************************************************
//* Step 1 of 1, This is a single step job.
//*
//ASMBITS1 EXEC PGM=ASMBITC1
//STEPLIB  DD  DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR
//SYSOUT   DD  SYSOUT=*
//*

Table of Contents Previous Section Next Section COBOL Mainline Program

This program (ASMBITC1.cbl) was written to test the callable Assembler program (ASM4BITS.mlc) that does the conversion between a 1-byte field of 8-bits and a field of 8-bytes.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    ASMBITC1.
       AUTHOR.        SIMOTIME TECHNOLOGIES.
      *****************************************************************
      * Copyright (C) 1987-2017 SimoTime Technologies.                *
      *                                                               *
      * All rights reserved.  Unpublished, all rights reserved under  *
      * copyright law and international treaty.  Use of a copyright   *
      * notice is precautionary only and does not imply publication   *
      * or disclosure.                                                *
      *                                                               *
      * Permission to use, copy, modify and distribute this software  *
      * for any non-commercial purpose and without fee is hereby      *
      * granted, provided the SimoTime copyright notice appear on all *
      * copies of the software. The SimoTime name or Logo may not be  *
      * used in any advertising or publicity pertaining to the use    *
      * of the software without the written permission of SimoTime    *
      * Technologies.                                                 *
      *                                                               *
      * Permission to use, copy, modify and distribute this software  *
      * for any commercial purpose requires a fee to be paid to       *
      * SimoTime Technologies. Once the fee is received by SimoTime   *
      * the latest version of the software will be delivered and a    *
      * license will be granted for use within an enterprise,         *
      * provided the SimoTime copyright notice appear on all copies   *
      * of the software. The SimoTime name or Logo may not be used    *
      * in any advertising or publicity pertaining to the use of the  *
      * software without the written permission of SimoTime           *
      * Technologies.                                                 *
      *                                                               *
      * SimoTime Technologies makes no warranty or representations    *
      * about the suitability of the software for any purpose. It is  *
      * provided "AS IS" without any expressed or implied warranty,   *
      * including the implied warranties of merchantability, fitness  *
      * for a particular purpose and non-infringement. SimoTime       *
      * Technologies shall not be liable for any direct, indirect,    *
      * special or consequential damages resulting from the loss of   *
      * use, data or projects, whether in an action of contract or    *
      * tort, arising out of or in connection with the use or         *
      * performance of this software                                  *
      *                                                               *
      * SimoTime Technologies                                         *
      * 15 Carnoustie Drive                                           *
      * Novato, CA 94949-5849                                         *
      * 415.883.6565                                                  *
      *                                                               *
      * RESTRICTED RIGHTS LEGEND                                      *
      * Use, duplication, or disclosure by the Government is subject  *
      * to restrictions as set forth in subparagraph (c)(1)(ii) of    *
      * the Rights in Technical Data and Computer Software clause at  *
      * DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of          *
      * Commercial  Computer Software - Restricted Rights  at 48      *
      * CFR 52.227-19, as applicable.  Contact SimoTime Technologies, *
      * 15 Carnoustie Drive, Novato, CA 94949-5849.                   *
      *                                                               *
      *****************************************************************
      *      This program is provided by SimoTime Technologies        *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************
      *
      *****************************************************************
      * Source Member: ASMBITC1.CBL
      * Copy Files:    PASSBITS.CPY
      * Calls to:      ASM4BITS
      *****************************************************************
      *
      * ASMBITC1 - Call ASM4BITS to convert between bits and bytes.
      *
      * CALLING PROTOCOL
      * ----------------
      * Use standard procedure to RUN or ANIMATE.
      *
      * DESCRIPTION
      * -----------
      * This program will call a COBOL routine to access a
      * routine to convert between bits and bytes..
      *
      *          ************
      *          * CBLBITJ1 *
      *          ********jcl*
      *               *
      *               *
      *          ************     ************
      *          * ASMBITC1 *-----* CONSOLE  *
      *          ********cbl*     ******dsply*
      *               *
      *               *
      *          ************
      *          * ASM4BITS *
      *          ********cbl*
      *
      * This program calls ASM4BITS to perform two functions:
      *
      * EXPAND   - translate the bits of a one-byte field to bytes
      *            in an eight-byte field.
      * COMPRESS - translate the bytes of an eight-byte field into
      *            bits in a one-byte field.
      *
      *****************************************************************
      * The EXPAND function will do the following:
      *
      * Input:  BTS-PASS-BITS, a one byte field (8-bits)
      * OUTPUT: BTS-PASS-BYTES, an eight byte field
      *
      * For each bit that is on in the BTS-PASS-BITS field set the
      * corresponding byte in the BTS-PASS-BYTES field to a value
      * of one.
      *
      * For each bit that is off in the BTS-PASS-BITS field set the
      * corresponding byte in the BTS-PASS-
      * BYTES field to a value of zero.
      *
      * Example: if   BTS-PASS-BITS = x'55'
      *          then BTS-PASS-BYTES will be '01010101'
      *
      *****************************************************************
      * The COMPRESS function will do the following:
      *
      * Input:  BTS-PASS-BYTES, an eight byte field
      * Output: BTS-PASS-BITS, a one byte field (8-bits)
      *
      * For each byte that is a one in the BTS-PASS-BYTES field the
      * corresponding bit in the BTS-PASS-BITS field is set to ON (1)
      *
      * For each byte that is zero in the BTS-PASS-BYTES field the
      * corresponding bit in the BTS-PASS-BITS field is set to OFF (0).
      *
      * Example: if   BTS-PASS-BYTES = '01010101'
      *          then BTS-PASS-BITS set to x'55'
      *
      *****************************************************************
      *
      * MAINTENANCE
      * -----------
      * 1989/02/27 Simmons, Created program.
      * 1997/03/17 Simmons, Updated for call to ASM4BITS.
      *
      *****************************************************************
      *
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
      *****************************************************************
      *    Data-structure for Title and Copyright...
      *    ------------------------------------------------------------
       01  SIM-TITLE.
           05  T1 pic X(11) value '* ASMBITC1 '.
           05  T2 pic X(34) value 'Convert between Bits and Bytes    '.
           05  T3 pic X(10) value ' v08.06.05'.
           05  T4 pic X(24) value ' http://www.simotime.com'.
       01  SIM-COPYRIGHT.
           05  C1 pic X(11) value '* ASMBITC1 '.
           05  C2 pic X(20) value 'Copyright 1987-2017 '.
           05  C3 pic X(28) value '   SimoTime Technologies    '.
           05  C4 pic X(20) value ' All Rights Reserved'.

       01  SIM-THANKS-01.
           05  C1 pic X(11) value '* ASMBITC1 '.
           05  C2 pic X(32) value 'Thank you for using this program'.
           05  C3 pic X(32) value ' provided from SimoTime Technolo'.
           05  C4 pic X(04) value 'gies'.

       01  SIM-THANKS-02.
           05  C1 pic X(11) value '* ASMBITC1 '.
           05  C2 pic X(32) value 'Please send all inquires or sugg'.
           05  C3 pic X(32) value 'estions to the helpdesk@simotime'.
           05  C4 pic X(04) value '.com'.

       COPY PASSBITS.

      *****************************************************************
      *    BTS-PASS-REQUEST values when calling ASM4BITS.
      *    ------------------------------------------------------------
       01  REQUEST-4-EXPAND        pic X(8)    value 'EXPAND  '.
       01  REQUEST-4-COMPRESS      pic X(8)    value 'COMPRESS'.

      *****************************************************************
      *    Buffer used for posting messages to the console.
      *    ------------------------------------------------------------
       01  MESSAGE-BUFFER.
           05  MESSAGE-HEADER      pic X(11)   value '* ASMBITC1 '.
           05  MESSAGE-TEXT        pic X(68).

      *****************************************************************
      *    Work fields used for testing call to ASM4BITS.
      *    ------------------------------------------------------------
       01  HEX-00                  pic X       value x'00'.
       01  HEX-55                  pic X       value x'55'.
       01  HEX-AA                  pic X       value x'AA'.
       01  HEX-FF                  pic X       value x'FF'.

       01  BYTES-00                pic X(8).
       01  BYTES-55                pic X(8).
       01  BYTES-AA                pic X(8).
       01  BYTES-FF                pic X(8).

       01  ZERO-VALUE              pic 9       value 0.
       01  MINUS-ONE               pic S9      value -1.
       01  MINUS-ONE-X             redefines   MINUS-ONE
                                   pic X.
       01  POSITIVE-BIT-VALUE      pic X(8)    value '00000000'.
       01  NEGATIVE-BIT-VALUE      pic X(8)    value '00000000'.

       01  THREE-BYTES.
           05  PACK-03             pic S9(5)   comp-3  value 0.
       01  TWO-BYTES               pic X(2)    value '00'.
       01  EIGHT-BYTES             pic X(8)    value LOW-VALUES.

       01  THE-EASY-WAY.
           05  FILLER              pic X(9)    value 'Efficient'.
           05  FILLER              pic X(10)   value ', PACK-03 '.
           05  PACK-03-E1L         pic X(4)    value SPACES.
           05  FILLER              pic X       value '-'.
           05  PACK-03-E1R         pic X(4)    value SPACES.
           05  FILLER              pic X       value SPACE.
           05  PACK-03-E2L         pic X(4)    value SPACES.
           05  FILLER              pic X       value '-'.
           05  PACK-03-E2R         pic X(4)    value SPACES.
           05  FILLER              pic X       value SPACE.
           05  PACK-03-E3L         pic X(4)    value SPACES.
           05  FILLER              pic X       value '-'.
           05  PACK-03-E3R         pic X(4)    value SPACES.
           05  FILLER              pic X(13)   value ', UNPACKED-5='.
           05  UNPACKED-5          pic 9(5)    value 0.

       01  THE-HARD-WAY.
           05  FILLER              pic X(9)    value 'Difficult'.
           05  FILLER              pic X(10)   value ', PACK-03 '.
           05  PACK-03-H1L         pic X(4)    value SPACES.
           05  FILLER              pic X       value '-'.
           05  PACK-03-H1R         pic X(4)    value SPACES.
           05  FILLER              pic X       value SPACE.
           05  PACK-03-H2L         pic X(4)    value SPACES.
           05  FILLER              pic X       value '-'.
           05  PACK-03-H2R         pic X(4)    value SPACES.
           05  FILLER              pic X       value SPACE.
           05  PACK-03-H3L         pic X(4)    value SPACES.
           05  FILLER              pic X       value '-'.
           05  PACK-03-H3R         pic X(4)    value SPACES.
           05  FILLER              pic X(13)   value ', FIVE-BYTES='.
           05  FIVE-BYTES          pic X(5)    value '00000'.

       01  ALPHABET-UPPER pic X(26) value 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

       01  IX-1           pic 9(3) value 0.
       01  IX-2           pic 9(3) value 0.
       01  IX-3           pic 9(3) value 0.

      *****************************************************************
       PROCEDURE DIVISION.

           perform Z-POST-COPYRIGHT

           perform BYTES-TO-BITS-COMPRESS.

           perform BITS-TO-BYTES-EXPAND.

           perform ALPHABET-DUMP.

           perform COBOL-UNPACK.

           perform Z-THANK-YOU.

           move ZERO to RETURN-CODE

           GOBACK.

      *****************************************************************
       ALPHABET-DUMP.
           move 'Starting ALPHABET-DUMP Routine...' to MESSAGE-TEXT
           perform Z-POST-MESSAGE

           add 1 to ZERO giving IX-1
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           perform 26 times
               move ALPHABET-UPPER(IX-1:1) to BTS-PASS-BITS
               call 'ASM4BITS' using BTS-PASS-AREA
               move 'Position nnn is x, the binary value is xxxx-xxxx'
                 to MESSAGE-TEXT
               move IX-1                to MESSAGE-TEXT(10:03)
               move BTS-PASS-BITS       to MESSAGE-TEXT(17:1)
               move BTS-PASS-BYTES(1:4) to MESSAGE-TEXT(40:4)
               move BTS-PASS-BYTES(5:4) to MESSAGE-TEXT(45:4)
               perform Z-POST-MESSAGE
               add 1 to IX-1
           end-perform
           exit.

      *****************************************************************
       BITS-TO-BYTES-EXPAND.
           move 'Starting BITS-TO-BYTES-EXPAND Routine...'
             to MESSAGE-TEXT
           perform Z-POST-MESSAGE

           move HEX-00 to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'ASM4BITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES to BYTES-00
           perform DISPLAY-BYTES

           move HEX-FF to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'ASM4BITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES to BYTES-FF
           perform DISPLAY-BYTES

           move HEX-55 to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'ASM4BITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES to BYTES-55
           perform DISPLAY-BYTES

           move HEX-AA to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'ASM4BITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES to BYTES-AA
           perform DISPLAY-BYTES

           exit.

      *****************************************************************
       BYTES-TO-BITS-COMPRESS.
           move 'Starting BYTES-TO-BITS-COMPRESS Routine...'
             to MESSAGE-TEXT
           perform Z-POST-MESSAGE

           move '00000000' to BTS-PASS-BYTES
           move REQUEST-4-COMPRESS to BTS-PASS-REQUEST
           call 'ASM4BITS'      using BTS-PASS-AREA
           move BTS-PASS-BITS to HEX-00
           perform DISPLAY-BYTES

           move '11111111' to BTS-PASS-BYTES
           move REQUEST-4-COMPRESS to BTS-PASS-REQUEST
           call 'ASM4BITS'      using BTS-PASS-AREA
           move BTS-PASS-BITS to HEX-FF
           perform DISPLAY-BYTES

           move '01010101' to BTS-PASS-BYTES
           move REQUEST-4-COMPRESS to BTS-PASS-REQUEST
           call 'ASM4BITS'      using BTS-PASS-AREA
           move BTS-PASS-BITS to HEX-55
           perform DISPLAY-BYTES

           move '10101010' to BTS-PASS-BYTES
           move REQUEST-4-COMPRESS to BTS-PASS-REQUEST
           call 'ASM4BITS'      using BTS-PASS-AREA
           move BTS-PASS-BITS to HEX-AA
           perform DISPLAY-BYTES

           exit.

      *****************************************************************
      * If you thought the UnPack was reserved for the mainframe      *
      * assembler programmers then take a look at the following       *
      * routine. The is a bit of an esoteric use of bit mainipulation *
      * but it does unpack a data string into a new data string.      *
      *                                                               *
      * A quicker and better way to unpack a field is as follows:     *
      *    ADD PACKED-FIELD TO ZERO GIVING UNPACKED-FIELD.            *
      *****************************************************************
       COBOL-UNPACK.
           move 'Starting the COBOL-UNPACK Routine...'
             to MESSAGE-TEXT
           perform Z-POST-MESSAGE

           add 615 to ZERO giving PACK-03

      *    Do the UNPACK the easy way...
           add PACK-03 to ZERO giving UNPACKED-5

      *    First, determine the bit configuration for zero to be
      *    used to set the left-nibble of the unpacked bytes.
      *    Then determine the negative sign bit configuration.
      *    This section of code is used so the program will run
      *    properly in both an EBCDIC and ASCII environment.
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           move ZERO-VALUE       to BTS-PASS-BITS
           call 'ASM4BITS'       using BTS-PASS-AREA
           move BTS-PASS-BYTES   to POSITIVE-BIT-VALUE

           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           move MINUS-ONE-X      to BTS-PASS-BITS
           call 'ASM4BITS'       using BTS-PASS-AREA
           move BTS-PASS-BYTES   to NEGATIVE-BIT-VALUE
           move '0000'           to NEGATIVE-BIT-VALUE(5:4)
      *    Do the UNPACK the esoteric way...
           move all '0' to FIVE-BYTES
           add 1 to ZERO giving IX-1
           add 1 to ZERO giving IX-2
           add 3 to ZERO giving IX-3
           perform until IX-3 = 1
               move REQUEST-4-EXPAND    to BTS-PASS-REQUEST
               move THREE-BYTES(IX-1:1) to BTS-PASS-BITS
               call 'ASM4BITS'       using BTS-PASS-AREA
               move BTS-PASS-BYTES      to EIGHT-BYTES

               move REQUEST-4-COMPRESS  to BTS-PASS-REQUEST
               move POSITIVE-BIT-VALUE      to BTS-PASS-BYTES

               move EIGHT-BYTES(1:4)    to BTS-PASS-BYTES(5:4)
               call 'ASM4BITS'       using BTS-PASS-AREA
               move BTS-PASS-BITS       to FIVE-BYTES(IX-2:1)
               add 1 to IX-2
               move EIGHT-BYTES(5:4)    to BTS-PASS-BYTES(5:4)
               call 'ASM4BITS'       using BTS-PASS-AREA
               move BTS-PASS-BITS       to FIVE-BYTES(IX-2:1)
               subtract 1 from IX-3
               add 1 to IX-2
               add 1 to IX-1
           end-perform
           perform COBOL-UNPACK-UNITS.

      *    Display the results...
           perform COBOL-UNPACK-POST-EFFICIENT
           perform COBOL-UNPACK-POST-DIFFICULT

           move 'Finished the COBOL-UNPACK Routine...'
             to MESSAGE-TEXT
           perform Z-POST-MESSAGE

           exit.
      *---------------------------------------------------------------*
       COBOL-UNPACK-POST-DIFFICULT.
           move THREE-BYTES(1:1) to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'ASM4BITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES(1:4) to PACK-03-H1L
           move BTS-PASS-BYTES(5:4) to PACK-03-H1R

           move THREE-BYTES(2:1) to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'ASM4BITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES(1:4) to PACK-03-H2L
           move BTS-PASS-BYTES(5:4) to PACK-03-H2R

           move THREE-BYTES(3:1) to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'ASM4BITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES(1:4) to PACK-03-H3L
           move BTS-PASS-BYTES(5:4) to PACK-03-H3R

           move THE-HARD-WAY to MESSAGE-TEXT
           perform Z-POST-MESSAGE
           exit.

      *---------------------------------------------------------------*
       COBOL-UNPACK-POST-EFFICIENT.
           move THREE-BYTES(1:1) to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'ASM4BITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES(1:4) to PACK-03-E1L
           move BTS-PASS-BYTES(5:4) to PACK-03-E1R

           move THREE-BYTES(2:1) to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'ASM4BITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES(1:4) to PACK-03-E2L
           move BTS-PASS-BYTES(5:4) to PACK-03-E2R

           move THREE-BYTES(3:1) to BTS-PASS-BITS
           move REQUEST-4-EXPAND to BTS-PASS-REQUEST
           call 'ASM4BITS'    using BTS-PASS-AREA
           move BTS-PASS-BYTES(1:4) to PACK-03-E3L
           move BTS-PASS-BYTES(5:4) to PACK-03-E3R

           move THE-EASY-WAY to MESSAGE-TEXT
           perform Z-POST-MESSAGE
           exit.

      *---------------------------------------------------------------*
       COBOL-UNPACK-UNITS.
           move REQUEST-4-EXPAND    to BTS-PASS-REQUEST
           move THREE-BYTES(IX-1:1) to BTS-PASS-BITS
           call 'ASM4BITS'       using BTS-PASS-AREA
           move BTS-PASS-BYTES      to EIGHT-BYTES

           move REQUEST-4-COMPRESS  to BTS-PASS-REQUEST
           if  PACK-03 < 0
               move NEGATIVE-BIT-VALUE      to BTS-PASS-BYTES
           else
               move POSITIVE-BIT-VALUE      to BTS-PASS-BYTES
           end-if
           move EIGHT-BYTES(1:4)    to BTS-PASS-BYTES(5:4)
      *    move EIGHT-BYTES(5:4)    to BTS-PASS-BYTES(1:4)
           call 'ASM4BITS'       using BTS-PASS-AREA
           move BTS-PASS-BITS       to FIVE-BYTES(IX-2:1)
           exit.

      *****************************************************************
       DISPLAY-BYTES.
           move 'Binary value is '     to MESSAGE-TEXT(1:16)
           move BTS-PASS-BYTES(1:4)    to MESSAGE-TEXT(17:4)
           move '-'                    to MESSAGE-TEXT(21:1)
           move BTS-PASS-BYTES(5:4)    to MESSAGE-TEXT(22:4)
           perform Z-POST-MESSAGE
           exit.

      *****************************************************************
      * The following Z-Routines perform administrative tasks         *
      * for this program.                                             *
      *****************************************************************

      *****************************************************************
       Z-POST-COPYRIGHT.
           display SIM-TITLE
           display SIM-COPYRIGHT
           exit.

      *****************************************************************
       Z-POST-MESSAGE.
           display MESSAGE-BUFFER
           move SPACES to MESSAGE-TEXT
           exit.

      *****************************************************************
       Z-THANK-YOU.
           display SIM-THANKS-01
           display SIM-THANKS-02
           exit.
      *****************************************************************
      *      This example is provided by SimoTime Technologies        *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************

Table of Contents Previous Section Next Section Assembler Bit Processing Routine

This program (ASM4BITS.mlc) was originally written to be used as a teaching and learning aid. Application programs that are being migrated to a Windows, UNIX or Linux System a callable COBOL program is used to replace this callable 370 assembler routine. Today, the callable COBOL program is used in a number of mainframe shops and it is the program of choice used by SimoTime. Also, the program has been tested and deployed on a Windows System with Enterprise Developer from Micro Focus.

ASM4BITS CSECT
***********************************************************************
*             ASM4BITS.MLC - This is an HLASM Program                 *
*                 Provided by SimoTime Technologies                   *
*           (C) Copyright 1987-2017 All Rights Reserved               *
*             Web Site URL:   http://www.simotime.com                 *
*                   e-mail:   helpdesk@simotime.com                   *
***********************************************************************
*                                                                     *
* Created: 1974/06/01, Simmons                                        *
* Changed: 1974/06/01, Simmons, no changes to date...                 *
*                                                                     *
***********************************************************************
*                                                                     *
* This program will run on an IBM Mainframe using MVS or a PC using   *
* Micro Focus Mainframe Express, version 2.5 or later (MFE) with      *
* the Assembler Option.                                               *
*                                                                     *
* This program provides an example of an assembler sub-routine that   *
* provides an eight-byte string of zeroes or ones to coincide with    *
* the bits in a single byte.                                          *
*                                                                     *
* Using the Micro Focus Animation You can immediately see the results *
* of each instruction execution. This is a very effective way to      *
* become familiar with how these techniques work.                     *
*                                                                     *
***********************************************************************
*
* This program is a callable routine that performs two functions:
*
* EXPAND   - translate the bits of a one-byte field to bytes
*            in an eight-byte field.
* COMPRESS - translate the bytes of an eight-byte field into
*            bits in a one-byte field.
*
* ------------------------------------------------------------------- *
* The EXPAND function will do the following.
*
* The call interface is as follows.
*    move 'EXPAND  ' to BTS-PASS-REQUEST
*    call 'ASM4BITS' using BTS-PASS-AREA
*
* Input:  BTS-PASS-BITS, a one byte field (8-bits)
* OUTPUT: BTS-PASS-BYTES, an eight byte field
*
* For each bit that is on in the BTS-PASS-BITS field set the
* corresponding byte in the BTS-PASS-BYTES field to a value
* of one.
*
* For each bit that is off in the BTS-PASS-BITS field set the
* corresponding byte in the BTS-PASS-
* BYTES field to a value of zero.
*
* Example: if   BTS-PASS-BITS = x'55'
*          then BTS-PASS-BYTES will be '01010101'
*
* ------------------------------------------------------------------- *
* The COMPRESS function will do the following:
*
* The call interface is as follows.
*    move 'COMPRESS' to BTS-PASS-REQUEST
*    call 'ASM4BITS' using BTS-PASS-AREA
*
* Input:  BTS-PASS-BYTES, an eight byte field
* Output: BTS-PASS-BITS, a one byte field (8-bits)
*
* For each byte that is a one in the BTS-PASS-BYTES field the
* corresponding bit in the BTS-PASS-BITS field is set to ON (1)
*
* For each byte that is zero in the BTS-PASS-BYTES field the
* corresponding bit in the BTS-PASS-BITS field is set to OFF (0).
*
* Example: if   BTS-PASS-BYTES = '01010101'
*          then BTS-PASS-BITS set to x'55'
*
***********************************************************************
* ASM4BITS, Expand or compress between bits and bytes.                *
***********************************************************************
*
R0       EQU   0
R1       EQU   1
R2       EQU   2
R3       EQU   3
R4       EQU   4
R5       EQU   5
R6       EQU   6
R7       EQU   7
R8       EQU   8
R9       EQU   9
R10      EQU   10
R11      EQU   11
R12      EQU   12
R13      EQU   13
R14      EQU   14
R15      EQU   15
*
* ------------------------------------------------------------------- *
         SAVE (14,12)
         BALR  12,0
         USING *,12
*
         ST    R1,SAVER1             * Save Register 1
         L     R8,0(,R1)             * Get address of PASS AREA
         L     R6,0(,R1)
         LA    R6,12(,R6)            * Get address of Single Byte
         L     R7,0(,R1)
         LA    R7,13(,R7)            * Get address of eight bytes
*
         CLC   0(8,R8),REQEXP        * Is this an EXPAND request...
         BE    EXPAND
*
         CLC   0(8,R8),REQCOM        * Is this a COMPRESS request...
         BE    COMPRESS
*
         B     EORNOK
*
* ------------------------------------------------------------------- *
* Based on the bit within a one-byte field being set to "OFF" or "ON"
* move a "0" or "1" value to the corresponding byte within an
* eight-byte string.
*
EXPAND   EQU   *
         MVC   WRK04+3(1),0(R6)     * Save the one-byte
         MVC   0(8,R7),ZEROES       * Init eight-byte string to zeroes
         LA    R5,128
         LA    R3,8                 * Load 8 into REG-3 for loop count
BCTLOOP1 EQU   *
         L     R4,WRK04
         NR    R4,R5                * Logical and of bit position
         BZ    *+8
         MVI   0(,R7),C'1'          * Move one if bit on
         LA    R7,1(,R7)            * Incr to Next Byte String Address
         SRL   R5,X'01'             * Shift right 1-bit position
         BCT   R3,BCTLOOP1          * Loop until REG-3 goes to ZERO
         B     RETURN
*
* ------------------------------------------------------------------- *
* Based on a "0" or "1" value of an individual byte within an
* eight-byte string set the corresponding bit within a one-byte field
* to "OFF" or "ON".
*
COMPRESS EQU   *
         MVI   0(,R6),X'00'         * Init the one-byte to low-value
         LA    R5,128
         LA    R3,8                 * Load 8 into REG-3 for loop count
         SR    R4,R4
BCTLOOP2 EQU   *
         CLI   0(,R7),C'1'          * Is eight-byte position a one
         BNE   *+6
         OR    R4,R5                * Set bit if value is one
         LA    R7,1(,R7)            * Incr to Next Byte String Address
         SRL   R5,X'01'             * Shift right 1-bit position
         BCT   R3,BCTLOOP2          * Loop until REG-3 goes to ZERO
         ST    R4,WRK04             * Store the one-byte value
         MVC   0(1,R6),WRK04+3      * Move one-byte to PASS AREA
         B     RETURN
*
* ------------------------------------------------------------------- *
* Success, return to the calling program with a ZERO Return Code.
*
RETURN   EQU   *
         SR    15,15                 * Set return code to ZERO
         RETURN (14,12),RC=(15)
*
* ------------------------------------------------------------------- *
* ABENDing, return to the calling program with a non-ZERO Return Code.
*
EORNOK   EQU   *
         LA    R15,16                * Set return code to 16 or x'10'
         RETURN (14,12),RC=(15)
*
* ------------------------------------------------------------------- *
* Data buffers used within the routine.
*
REQEXP   DC    CL8'EXPAND  '
REQCOM   DC    CL8'COMPRESS'
SAVER1   DC    4XL1'00'
WRK04    DC    4XL1'00'
ZEROES   EQU   *
ZERO     DC    CL1'0'
         DC    7CL1'0'
         END

Table of Contents Previous Section Next Section COBOL Copy File for Pass Area

This copy file (PASSBITS.cpy) provides a convenient method for defining the data areas (or fields) that are used to pass information between the demo program and the bit and byte conversion routine.

      *****************************************************************
      *                PASSBITS is a COBOL Copy File                  *
      *     Data Structure or Pass Area used for calling SIMOBITS.    *
      *         Copyright (C) 1987-2017 SimoTime Technologies         *
      *                     All Rights Reserved                       *
      *****************************************************************
      *              Provided by SimoTime Technologies                *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************
      *
      * When BTS-PASS-REQUEST is 'EXPAND  ' do analysis of
      *      BTS-PASS-BITS (a 1-btye field of 8-bits)
      *      and based on the bit settings a corresponding value of
      *      0 or 1 is set in the BTS-PASS-BYTES (an 8-byte field
      *      of zeroes and ones).
      *
      * When BTS-PASS-REQUEST is 'COMPRESS' do analysis of
      *      BTS-PASS-BYTES (an 8-byte field of zeroes and ones)
      *      and based on a value of 0 or 1 the corresponding
      *      bit in BTS-PASS-BITS (a 1-byte field of 8-bits) is
      *      switched ON or OFF.
      *
       01  BTS-PASS-AREA.
           05  BTS-PASS-REQUEST            PIC X(8).
           05  BTS-PASS-RESULT             PIC S9(9)   COMP.
           05  BTS-PASS-RECORD.
               10  BTS-PASS-BITS           PIC X.
               10  BTS-PASS-BYTES.
                   15  BTS-PASS-BYTE-01    PIC X.
                   15  BTS-PASS-BYTE-02    PIC X.
                   15  BTS-PASS-BYTE-03    PIC X.
                   15  BTS-PASS-BYTE-04    PIC X.
                   15  BTS-PASS-BYTE-05    PIC X.
                   15  BTS-PASS-BYTE-06    PIC X.
                   15  BTS-PASS-BYTE-07    PIC X.
                   15  BTS-PASS-BYTE-08    PIC X.
      *
      ***  PASSBITS - End-of-Copy File - - - - - - - - - - - PASSBITS *
      *****************************************************************
      *

Table of Contents Previous Section Next Section Summary

This suite of programs is provided as a COBOL program that calls an Assembler routine. It is an example of one of the possible solutions to the problem of determining and changing the bits within a byte. This example uses an approach of converting the bit information in a single byte to or from an eight-byte field of COBOL accessible zeroes and ones. This document may be used to assist as a tutorial for new programmers or as a quick reference for experienced programmers.

In the world of programming there are many ways to solve a problem. This document and the links to other documents are intended to provide a greater awareness of the Data Management and Application Processing alternatives.

The documentation and software were developed and tested on systems that are configured for a SimoTime environment based on the hardware, operating systems, user requirements and security requirements. Therefore, adjustments may be needed to execute the jobs and programs when transferred to a system of a different architecture or configuration.

SimoTime Services has experience in moving or sharing data or application processing across a variety of systems. For additional information about SimoTime Services or Technologies please send an e-mail to: helpdesk@simotime.com or call 415 883-6565. We appreciate hearing from you.

Table of Contents Previous Section Next Section Software Agreement and Disclaimer

Permission to use, copy, modify and distribute this software, documentation or training material for any purpose requires a fee to be paid to SimoTime Technologies. Once the fee is received by SimoTime the latest version of the software, documentation or training material will be delivered and a license will be granted for use within an enterprise, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Technologies.

SimoTime Technologies makes no warranty or representations about the suitability of the software, documentation or learning material for any purpose. It is provided "AS IS" without any expressed or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Technologies shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software, documentation or training material.

Table of Contents Previous Section Next Section Downloads and Links

This section includes links to documents with additional information that are beyond the scope and purpose of this document. The first group of documents may be available from a local system or via an internet connection, the second group of documents will require an internet connection.

Note: A SimoTime License is required for the items to be made available on a local system or server.

Table of Contents Previous Section Next Section Current Server or Internet Access

The following links may be to the current server or to the Internet.

Link to Internet   Link to Server   Explore Bit Manipulation using a COBOL program calling COBOL to do the accessing of individuals bits within a byte.

Link to Internet   Link to Server   Explore the COBOL Connection for more examples of COBOL programming techniques and sample code.

Link to Internet   Link to Server   Explore The ASCII and EBCDIC Translation Tables. These tables are provided for individuals that need to better understand the bit structures and differences of the encoding formats.

Link to Internet   Link to Server   Explore The File Status Return Codes to interpret the results of accessing VSAM data sets and/or QSAM files.

Table of Contents Previous Section Next Section Internet Access Required

The following links will require an internet connect.

This suite of programs and documentation is available for download. Link to an Evaluation zPAK Option that includes the program members, documentation and control files.

A good place to start is The SimoTime Home Page for access to white papers, program examples and product information. This link requires an Internet Connection

Explore The Micro Focus Web Site for more information about products and services available from Micro Focus. This link requires an Internet Connection.

Table of Contents Previous Section Next Section Glossary of Terms

Link to Internet   Link to Server   Explore the Glossary of Terms for a list of terms and definitions used in this suite of documents and white papers.

Table of Contents Previous Section Next Section Comments or Feedback

This document was created and is copyrighted and maintained by SimoTime Technologies.

If you have any questions, suggestions, comments or feedback please call or send an e-mail to: helpdesk@simotime.com

We appreciate hearing from you.

Table of Contents Previous Section Next Section Company Overview

SimoTime Technologies was founded in 1987 and is a privately owned company. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. Our customers include small businesses using Internet technologies to corporations using very large mainframe systems.

Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems. We specialize in preparing applications and the associated data that are currently residing on a single platform to be distributed across a variety of platforms.

Preparing the application programs will require the transfer of source members that will be compiled and deployed on the target platform. The data will need to be transferred between the systems and may need to be converted and validated at various stages within the process. SimoTime has the technology, services and experience to assist in the application and data management tasks involved with doing business in a multi-system environment.

Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com


Return-to-Top
Assembler Bit Processing, Bit Manipulation
Copyright © 1987-2017
SimoTime Technologies and Services
All Rights Reserved
When technology complements business
http://www.simotime.com