COBOL CHAR関数とORD関数
CHAR関数とORD関数を使えば、
COMP系つかわなくても、
COBOL85からBIT操作しようと思えばできたみたい。
汎用機世界では、COBOL関数が封印されているのと、
アセンブラで可能なので、こういうことはしないのです。
<CHARORD.COB>
000010
000020 IDENTIFICATION DIVISION.
000030 PROGRAM-ID. CNT001.
000040*
000050 ENVIRONMENT DIVISION.
000060 CONFIGURATION SECTION.
000070 SOURCE-COMPUTER. COBOL85.
000080 OBJECT-COMPUTER. COBOL85.
000090*
000100 INPUT-OUTPUT SECTION.
000110 FILE-CONTROL.
000120 SELECT OUT01 ASSIGN TO "D:\work\OUT_CHAR.dat".
000130 SELECT IN01 ASSIGN TO "D:\work\OUT_CHAR.dat".
000140 SELECT OUT02 ASSIGN TO "D:\work\OUT_ORD.dat".
000150*
000160 DATA DIVISION.
000170 FILE SECTION.
000180 FD OUT01.
000190* BLOCK CONTAINS 0 RECORD <=INVALID WORD BLOCK
000200* LABEL RECORD IS STANDARD.<=INVALID WORD LABEL
000210 01 OUT01-AREA.
000220 05 OUT01-DATA PIC X(01).
000230 FD IN01.
000240 01 IN01-AREA.
000250 05 IN01-DATA PIC X(01).
000260 FD OUT02.
000270* BLOCK CONTAINS 0 RECORD <=INVALID WORD BLOCK
000280* LABEL RECORD IS STANDARD.<=INVALID WORD LABEL
000290 01 OUT02-AREA.
000300 05 ORD-DATA PIC 9(03).
000310 05 OUT02-CRLF PIC X(02).
000320
000330
000340 WORKING-STORAGE SECTION.
000350 01 IX PIC 9(003).
000360******************************************************************
000370 PROCEDURE DIVISION.
000380*
000390 OPEN OUTPUT OUT01.
000400*
000410 MOVE 1 TO IX.
000420 PERFORM 256 TIMES
000430 MOVE FUNCTION CHAR(IX) TO OUT01-DATA
000440 WRITE OUT01-AREA
000450 ADD 1 TO IX
000460 END-PERFORM.
000470 CLOSE OUT01.
000480
000490*
000500 OPEN INPUT IN01.
000510 OPEN OUTPUT OUT02.
000520 PERFORM 256 TIMES
000530 READ IN01
000540 COMPUTE ORD-DATA = FUNCTION ORD(IN01-DATA)
000550 MOVE X'0D0A' TO OUT02-CRLF
000560 WRITE OUT02-AREA
000570 END-PERFORM.
000580*
000590 CLOSE IN01.
000600 CLOSE OUT02.
000610 GOBACK.