View previous topic :: View next topic
|
Author |
Message |
kalaignar_S Warnings : 1 New User
Joined: 06 Jan 2006 Posts: 21
|
|
|
|
Which one is the efficient COBOL coding, has been mentioned below??
Why??
MOVE A TO B.
COMPUTE B = A.
If anybodies know this let me know the reason..
Thanks
Kalaignar |
|
Back to top |
|
|
ralph_v
New User
Joined: 07 Jul 2005 Posts: 27
|
|
|
|
COMPUTE B = A is efficient coding because you can check for truncation using ONSIZE ERROR clause. |
|
Back to top |
|
|
parikshit123
Active User
Joined: 01 Jul 2005 Posts: 269 Location: India
|
|
|
|
Well,
When you say 'efficient coding', offcourse COMPUTE should be a better choice. You can do more with that. for example you can check for size or even overflow....
But, when it comes to "efficient code", if you ignore exceptions, MOVE is efficient. as it maps to less number of instructions.
I hope the difference between "efficient coding" and "efficient code" is clear. |
|
Back to top |
|
|
parikshit123
Active User
Joined: 01 Jul 2005 Posts: 269 Location: India
|
|
|
|
Also,
I would suggest you to choose a good title for the topic.
I feel that "Efficient Coding" is too general for this topic.
However, it was really a nice question.
Thanks,
Parikshit |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
Kalaignar,
It's interesting that in the specific example you give, the compiler generates the exact same code for move and compute.
Code: |
WORKING-STORAGE SECTION.
01 A PIC S9(5) VALUE 123.
01 B PIC S9(5) VALUE 345.
PROCEDURE DIVISION.
.000028 MOVE A TO B.
. 000234 F224 D0E8 8000 PACK 232(3,13),0(5,8) TS2=0
. 00023A F822 D0E8 D0E8 ZAP 232(3,13),232(3,13) TS2=0
. 000240 F342 8008 D0E8 UNPK 8(5,8),232(3,13) B
.000029 COMPUTE B = A.
. 000246 F224 D0E8 8000 PACK 232(3,13),0(5,8) TS2=0
. 00024C F822 D0E8 D0E8 ZAP 232(3,13),232(3,13) TS2=0
. 000252 F342 8008 D0E8 UNPK 8(5,8),232(3,13) B
.000031 GOBACK |
|
|
Back to top |
|
|
parikshit123
Active User
Joined: 01 Jul 2005 Posts: 269 Location: India
|
|
|
|
Hi David,
Thats correct!
the specific example generates the same code.
Now, suppose if you are using ONSIZE ERROR clause then compiler will definitely generate more number of instructions. isn't it?
So, only an assignment is your need, offcourse simple move is a better choice.
Any further ideas.. seems to be a nice topic isn't it?
Thanks,
Parikshit. |
|
Back to top |
|
|
|