2

I'm trying to add two numbers and subtract two numbers but when I compile my code it says 'invalid op-code' (I'm using assist (IBM))

MAIN               CSECT
                   USING MAIN,15
->invalid op-code  NUM1 DC F'67'
->invalid op-code  NUM2 DC F'203'
                   L    0,NUM1
                   L    1,NUM2
                   AR   0,1
                   L    2,NUM1
                   L    3,NUM2
                   SR   2,3
                   XDUMP
                   END MAIN
Hogstrom
  • 3,581
  • 2
  • 9
  • 25
  • @lurker, *none* of the `dc` examples in that link are preceded by `=`. – paxdiablo Jun 21 '19 at 01:19
  • What architecture is this? IBM POWER / PowerPC? Or S/390 or something? (If the latter, tag it with `[zos]`). If this assembles and faults at runtime with invalid opcode, that's probably from putting literal data where the CPU will execute it as code, inside your `main` function. – Peter Cordes Jun 21 '19 at 02:16
  • It only says z/OS – Andy Olivares Jun 21 '19 at 02:18
  • There are so few questions about IBM mainframe hardware and software that there's only one tag for the OS and hardware. The tag description says z/OS, but it's the tag that gets used on other S390 asm questions. (Fuz created a new tag for this question, but I tagged it zOS as well so people that follow that tag will see it.) – Peter Cordes Jun 21 '19 at 18:06
  • Oops, apparently the `[mainframe]` tag is best here, and refers to the hardware. Thanks Ross. – Peter Cordes Jun 21 '19 at 18:18
  • I'm guessing you have the names for the DC statements in the wrong column, but that could be because of how you inserted `->invalid op-code`. The first character of a name must be on the first column of a line. – Ross Ridge Jun 21 '19 at 18:29
  • 1
    Thanks you all. I’ve figured it out. NUM1 and NUM2 had to be declared after XDUMP. – Andy Olivares Jun 21 '19 at 18:32
  • 1
    @PeterCordes I don't really like how the `[mainframe]` tag is used, but it's what most assembly questions for IBM's S/360-derived computers use here. – Ross Ridge Jun 21 '19 at 18:33

2 Answers2

4

A few things. First, the placement of the data items is important as it will be incorporated in with the code list. Unlike higher level languages where declarations of data types are organized automatically.

Second, you are declaring the data items incorrectly. The name should start in column 1 with the data type DC next and then followed by the data. This will simply include the data inline with the other code which will cause your program to fail with an abend S0C1.

Here is an suggested way to declare the data

Columns    
0        1         2         3         4
1234567890123456789012345678901234567890

MAIN     CSECT  
         USING MAIN,15  
         L    0,NUM1
         L    1,NUM2
         AR   0,1
         L    2,NUM1
         L    3,NUM2
         SR   2,3
         XDUMP
NUM1     DC   F'67'
NUM2     DC   F'203'
         END  MAIN

Moving the data out of the code path and putting its name in the right column communicates that your data label is not an op-code.

Hogstrom
  • 3,581
  • 2
  • 9
  • 25
3

You have put your data where the assembler expects instructions to be. You need to find out how to specific a data or literal area and put your data there. Or rewrite your code to use immediate type data, where the values are in the itext.