Help with COMP-1 and IBM-370



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Help with COMP-1 and IBM-370

Postby Nitele » Thu Jul 26, 2018 6:07 am

Hello!
So, I've been trying to understand this code:

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. NUMBERS.
000300 AUTHOR. TEEBEE.
000400****************************************************************
000500*    Simply transfer the present program to your favorite      *
000600*    mainframe computer, compile it, link it and submit some   *
000700*    appropriate JCL to run it. Its output tells the answer.   *
000800****************************************************************
000900 ENVIRONMENT DIVISION.
001000 CONFIGURATION SECTION.
001100 OBJECT-COMPUTER. IBM-370.
001200 SOURCE-COMPUTER. IBM-370.
001300 DATA DIVISION.
001400 WORKING-STORAGE SECTION.
001500 01 THE-NUMBERS.
001600      10 FILLER USAGE IS COMP-1 VALUE -.24093455E+04.
001700      10 FILLER USAGE IS COMP-1 VALUE -.55439209E-47.
001800      10 FILLER USAGE IS COMP-1 VALUE  .44591240E+13.
001900      10 FILLER USAGE IS COMP-1 VALUE -.22818252E-71.
002000      10 FILLER USAGE IS COMP-1 VALUE -.48936378E-36.
002100      10 FILLER USAGE IS COMP-1 VALUE  .53763199E+00.
002200      10 FILLER USAGE IS COMP-1 VALUE  .23808258E+74.
002300      10 FILLER USAGE IS COMP-1 VALUE -.13901026E-68.
002400      10 FILLER USAGE IS COMP-1 VALUE -.54452280E-53.
002500      10 FILLER USAGE IS COMP-1 VALUE -.33187504E+05.
002600      10 FILLER USAGE IS COMP-1 VALUE  .84218729E+00.
002700      10 FILLER USAGE IS COMP-1 VALUE -.18465549E-73.
002800      10 FILLER USAGE IS COMP-1 VALUE -.16025044E-50.
002900  01 THE-ANSWER REDEFINES THE-NUMBERS PIC X(52).
003000  PROCEDURE DIVISION.
003100      DISPLAY THE-ANSWER
003200      GOBACK.
003300  END PROGRAM NUMBERS.


I've tried several Cobol compilers, and I didn't get any sentence that made sense, so, since I'm a newb in the area, I'm certainly doing something wrong.
Could someone walkthrough how to get what it prints out? Do I need a different machine to run the code?
Thanks in advance!
Nitele
 
Posts: 4
Joined: Thu Jul 26, 2018 6:00 am
Has thanked: 2 times
Been thanked: 0 time

Re: Help with COMP-1 and IBM-370

Postby NicC » Thu Jul 26, 2018 2:31 pm

if you have tried several COBOL compilers then you are probably not running on a mainframe and that is what you need to do, compile and execute. On a mainframe the character set is coded differently from PC data. The source says IBM 370 so you have to run on an IBM mainframe.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Help with COMP-1 and IBM-370

Postby Nitele » Fri Jul 27, 2018 8:04 am

Well, I do not have access to an IBM mainframe. Is it easier to try to emulate it, in this case, instead of understanding the code?
I'll try that!
Thank you.
Nitele
 
Posts: 4
Joined: Thu Jul 26, 2018 6:00 am
Has thanked: 2 times
Been thanked: 0 time

Re: Help with COMP-1 and IBM-370

Postby NicC » Fri Jul 27, 2018 1:36 pm

What do you mean by 'emulate'? Run on mvs 3.4 on a Hercules emulator? That would do it as it uses the EBCDIC encoding and not ASCII.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic

These users thanked the author NicC for the post:
Nitele (Mon Jul 30, 2018 6:43 am)
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Help with COMP-1 and IBM-370

Postby phunsoft » Fri Jul 27, 2018 6:08 pm

I think the code is there to help you understand: A byte is a byte is a byte. With most architectures, a byte consists of 8 bits. So a byte can hold 256 different combinations of the 8 bits. What any of those combinations means depends on how you look at the byte. Is it a single character? If so, what code page? Is it a one byte binary number? If so, signed or unsigned? And so on.

This code defines 13 single precision floating point variables (COMP-1), each one needs 4 bytes to store a floting point number. Each variable is initialized. The compile needs to transform the haman readable number to the internal format. E.g. the first number -.24093455E+04 is transformed to the four bytes x'C3', x'96', x'95', and x'87', or x'C3969587'.

The code then tells the compiler that you want interpret the 13 * 4 bytes in a different way, i.e. as a character string. So the 4 bytes above are lokked at as the first 4 bytes of a 52 byte character string. But what code page is to be used? Since this is about mainframe, the code page can be expected to be an EBCDIC code page (which one exactly is unknown). This is what the DISPLAY statement does, it looks at the bytes as characters and simply writes them out.

If you want to run this program on a ASCII platform, and still get a meaningful text being displayed, you need to initialize the float variables with values that correspond to the text in ASCII. Another option is to run the program as given, save the output in a file, and then use the editor of choice to display the content as EBCDIC data.

HTH
Peter

These users thanked the author phunsoft for the post:
Nitele (Mon Jul 30, 2018 6:43 am)
phunsoft
 
Posts: 14
Joined: Thu Jul 26, 2018 10:35 am
Has thanked: 0 time
Been thanked: 2 times

Re: Help with COMP-1 and IBM-370

Postby Nitele » Fri Jul 27, 2018 10:03 pm

I tried using Hercules yesterday all night. It seems I'm too much of a newb in the subject to make anything work, but I bet it is suposed to be the easier solution, indeed. hahahahaha
I tried to follow your tips today, phunsoft. I got some results, based on another similar problem in this forum!

Thanks for the help, guys.
Nitele
 
Posts: 4
Joined: Thu Jul 26, 2018 6:00 am
Has thanked: 2 times
Been thanked: 0 time

Re: Help with COMP-1 and IBM-370

Postby phunsoft » Sat Jul 28, 2018 12:39 am

What is the result you got?
Peter
phunsoft
 
Posts: 14
Joined: Thu Jul 26, 2018 10:35 am
Has thanked: 0 time
Been thanked: 2 times

Re: Help with COMP-1 and IBM-370

Postby Nitele » Mon Jul 30, 2018 6:41 am

Since it's a challenge at hacker.org, I'd be spoiling it for anyone who searched it if I posted the text!
But I got something similar to "Congratulations, the answer is blablabla". Hahah
Nitele
 
Posts: 4
Joined: Thu Jul 26, 2018 6:00 am
Has thanked: 2 times
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post