assembly 在z/OS汇编程序中将字节转换为位串?

e7arh2l6  于 2023-06-30  发布在  其他
关注(0)|答案(2)|浏览(111)

在z/OS Assembly中,将字节转换为它的位表示的最佳方法是什么?
例如,X '3A'变成CL 8 '00111010',类似于COBOL或Rexx'X2 B?
我在汇编中得到的是Map到两个表,每个表都是可能的,像这样:

...
         SR  R1,R1                                          
         IC  R1,BYTE                                        
         IC  R1,HEXTAB(R1)                                  
         LA  R1,BITTAB(R1)                                 
         MVC BITS,0(R1)          
...                         
*                                                           
BYTE     DC  X'3A'                                           
BITS     DS  CL8                                            
HEXTAB   DC  X'0001020903110A19042112290B311A39'            
         DC  X'05412245134D2A550C5D32651B6D3A75'            
         DC  X'06264262237D468514804E8D2B95569D'            
         DC  X'0D495EA533A966B11C886EB93BC176C9'            
         DC  X'071727374353637324837E9B47AF86C7'            
         DC  X'155181AD4FD18ED32C9096DB57D59EE3'            
         DC  X'0E2E4A6A5F92A6BE3498AAE067DDB2EB'            
         DC  X'1D5989B56FD7BAF33CA0C2EE77E5CAF7'            
         DC  X'FF0810182028303840444C545C646C74'            
         DC  X'25617C847F8C949C48A4A8B087B8C0C8'            
         DC  X'16365272829AAEC650ACD0D28FDAD4E2'            
         DC  X'2D6991BD97DFDCEA58B4D6F29FEDE4F6'            
         DC  X'FE0F1F2F3F4B5B6B607B8B93A3A7B7BF'            
         DC  X'357199C5ABCFD9E168BCDEE9B3F1ECF5'            
         DC  X'FD1E3E5A7A8AA2B670C4CED8BBE8F0F4'            
         DC  X'FC3D79A1C3CDE7EFFB78CCE6FACBF9F8'                                                                        
BITTAB   DC C'00000000100000011000001010000011'             
         DC C'10000100100001011000011010000111'             
         DC C'10001000100110001010100010111000'             
         DC C'11001000110110001110100011111001'             
         DC C'00101001001110010101100101101001'             
         DC C'01111001100110101001101110011101'             
         DC C'10011110100111111010101011101011'             
         DC C'01101011111011011110111011111111',C'0000000'

但这需要两个令人讨厌的大表的相应表示。
有没有更有效或更简洁的方法来做到这一点?

cngwdvgl

cngwdvgl1#

我使用UNPK将半字节隔离为一个字节,而不是使用一个包含所有可能位值的大表。这使我可以AND离开区域部分,然后使用剩余的半字节作为偏移量进入本地数组字符串,该字符串为4字节长,表示半字节的二进制值。这是第一次,但这是我的第一个想法。
如果我真的这样做,我可能会使用EX指令和TM来测试每个位,并简单地将'1'或'0'添加到字符位表示中。它将保存另一个字符数组。
为了使它更有用,可以优化它以接收3个参数,即源字符串,其长度和指向输出缓冲区的指针。使整个事情可重入,就不需要本地存储。
我认为这符合你的挑战。
测试字符串为C"123ABC",输出结果为

F    1    F    2    F    3    C    1    C    2    C    3
1111 0001 1111 0010 1111 0011 1100 0001 1100 0010 1100 0011
PRINT NOGEN                                                   
* ------------------------------------------------------------------- *
*                                                                     *
*  C2B                                                                *
*                                                                     *
*  @author Hogstrom                                                   *
*                                                                     *
*  Process a set of bytes and convert to a displayable '1' and '10'   *
*  to represent the binary value.                                     *
*                                                                     *
* ------------------------------------------------------------------- *
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                * Base Register                       
R13      EQU   13                                                      
R14      EQU   14                                                      
R15      EQU   15                                                      
*                                                                      
ASMSKEL  CSECT                                                         
         STM   R14,R12,12(R13)                                         
         LR    R12,R15                                                 
         USING ASMSKEL,R12                                             
*                                                                      
         ST    R13,SaveArea+4                                          
         LA    R0,SaveArea                                             
         ST    R0,8(R13)                                               
         LA    R13,SaveArea                                            
*                                                                      
         OPEN  (SYSOUT,(OUTPUT))                                       
*                                                                      
         LA    R2,L'TEST1        Length of bytes to convert to binary  
         LA    R3,TEST1          Source address of bytes to convert    
         LA    R4,LINE           Where to place the translated bits    
BYTELOOP DS   0H                                                       
         UNPK  NIBBLE,0(2,R3)    unpack two bytes, ignore the second   
         NC    NIBBLE,=X'0F0F'   Turn off zone as its not needed       
         SR    R5,R5             Clear Bit Offset Register             
         IC    R5,NIBBLE         Grab offset                           
         SLL   R5,2              and multiply by 4                     
         LA    R6,CHARBITS                                             
         AR    R6,R5             add offset to correct bits            
         MVC   0(4,R4),0(R6)     move them                             
*                                                                      
         LA    R4,5(R4)          Increment to the next section         
         SR    R5,R5             Clear Bit Offset Register             
         IC    R5,NIBBLE+1       Grab offset                           
         SLL   R5,2              and multiply by 4                     
         LA    R6,CHARBITS                                             
         AR    R6,R5             add offset to correct bits            
         MVC   0(4,R4),0(R6)     move them                             
         LA    R4,5(R4)          Increment to the next section         
         LA    R3,1(R3)          Move to next Byte                     
         BCT   R2,BYTELOOP                                             
*                                                                      
FINISH   DS   0H              
         PUT   SYSOUT,OUTREC                                            
         CLOSE SYSOUT                                                   
*                                                                       
         L     R13,SaveArea+4                                           
         LM    R14,R12,12(R13)                                          
         XR    R15,R15                                                  
         BR    R14                                                      
*                                                                       
SYSOUT   DCB   DSORG=PS,MACRF=(PM),DDNAME=SYSOUT,                      *
               RECFM=FBA,LRECL=133,BLKSIZE=0                            
*                                                                       
NIBBLE   DS    C'   '            Second byte is ignored                 
*                                                                       
TEST1    DC    C'123ABC'                                                
         DC    C' '              Filler Byte to accomodate UNPK         
*                                                                       
OUTREC         DC 0CL133                                                
ASA            DC  C' '                                                 
LINE           DC  CL132' '                                             
*                                                                       
SaveArea       DS  18F                                                  
                LTORG                                                   
CHARBITS  DS  0H        
          DC  C'0000'   
          DC  C'0001'   
          DC  C'0010'   
          DC  C'0011'   
          DC  C'0100'   
          DC  C'0101'   
          DC  C'0110'   
          DC  C'0111'   
          DC  C'1000'   
          DC  C'1001'   
          DC  C'1010'   
          DC  C'1011'   
          DC  C'1100'   
          DC  C'1101'   
          DC  C'1110'   
          DC  C'1111'   
          END
vhmi4jdf

vhmi4jdf2#

这也可以通过使用SLL将八位中的每一位移动到寄存器的高阶位来实现。LTR可用于检查寄存器是否为负(高位= 1)。

ASMX2B   CSECT ,                                                     
         USING ASMX2B,R15          TEMP BASE                         
         SAVE  (14,12)                                               
         LA    R14,SAVEAREA        A(MY SAVEAREA)                    
         ST    R14,8(R13)          FORWARD-CHAIN MINE FROM CALLER'S  
         ST    R13,4(R14)          BACK-CHAIN CALLER'S FROM MINE     
         LR    R13,R14             SET 13 FOR MY SUBROUTINE CALLS    
         DROP  R15                 FINISHED WITH TEMP BASE           
                                                                     
         LR    R12,R15             SET UP ACTUAL BASE REGISTER       
         USING ASMX2B,R12            AND TELL ASSEMBLER ABOUT IT     
                                                                     
         ICM   R1,B'1000',HEXVAL   HEX VALUE IN HIGH ORDER BYTE      
         LA    R2,BITVAL           POINT TO START OF BITVAL          
         LHI   R3,8                # BITS TO CHECK                   
LOOP     LTR   R1,R1               IS HIGH ORDER BIT ON ?            
         BM    *+8                 YES --->                          
         MVI   0(R2),C'0'          NO, SET BIT SETTING TO 0          
         SLL   R1,1                MOVE NEXT BIT TO HIGH ORDER BIT   
         LA    R2,1(,R2)           POINT TO NEXT VALUE IN BIT VAL    
         BCT   R3,LOOP                                               
                                                                     
         LHI   R15,0                                                 
         L     R13,4(R13)                                            
         RETURN (14,12),RC=(15)    RETURN                            
         YREGS ,                                                     
         LTORG ,                                                     
HEXVAL   DC    X'3A'                                                 
BITVAL   DC    CL8'11111111'                                         
SAVEAREA DS    18F      AREA FOR MY CALLEE TO SAVE & RESTORE MY REGS 
         END

相关问题