Blog Archives

Structured Assembler Macros: The IF statement

Back in the 70′s many thoughtful computer scientists weighed in on a now-dead issue of the GoTo statement in high-level languages.  The issue seems to be pretty much settled now, with many new languages avoiding GoTo altogether, and high-level programmers avoiding their use except in very specialized circumstances.   But assembler programmers depend on branch statements (conditional and unconditional) as a required part of any program logic. We can’t avoid coding Branch statements, so the goal is to use them in a reasonably straightforward way, avoiding spaghetti logic.  Good assembler programmers do this intuitively after a while, but IBM has included some high-level macros that make the job even easier now.  The macros are distributed in the HLASM Toolkit.  The macros are stored in a library called hlg.SASMMAC2 (where hlq is a high-level qualifier that varies from system to system).  If your system has the toolkit, include the macro library in your SYSLIB for the compile.  On my system, the JCL looks like this:

//                  DD   DSN=HLA.SASMMAC2,DISP=SHR

In the next few postings, we will look at the macros that are available.  In this first note, we look at three macros that support if-statements:  If, ELSE, and ENDIF.

   The IF statement comes in a variety of formats, but I especially like the format below:

        IF (CLC,X,LT,Y)                   
            MVC  SMALLER,X                 
            MVC  LARGER,Y                  
            MVC  SMALLER,Y                 
            MVC  LARGER,X                  

The predicate in the If statement has four parts:

1)  A compare instruction mnemonic (like CLC or CP)

2)  The operand 1 field

3)  A condition parameter (H – high, GT -greater than, L – low, LT – less than, E or EQ – equal)

4) The operand 2 field

Like if-statements in high-level languages, the true block occurs between the IF and the ELSE, and the false block occurs after the ELSE and before the ENDIF.

When the macros are assembled, the required branch statements and labels are inserted.  IF statements can be nested and used in conjuction with other structured macros, just as you would hope for. 

    Examine the generated code by coding PRINT ON,NODATA,GEN just before the if statement, and PRINT ON,NODATA, NOGEN just after the ENDIF.

   Give the IF statement a try – you’ll like it.

Leave a comment

February 12, 2013 · 12:44 am

Instruction of the Day: UNPK

Learn a new instruction today.  Here’s a link to a short video that covers UNPK, the mainframe instruction that converts packed fields to zoned decimal.  All the videos and tutorials are found here.

Leave a comment

October 21, 2012 · 8:38 pm

Instruction of the Day: PACK

I just posted the first of many short instructional videos that cover specific mainframe instructions here. The link to it is on my assembler resources page here. The first video covers the PACK instruction. I’ll try to post one video each day, five days a week, so join in and learn assembly language one instruction at a time. Each video will cover instruction semantics, examples of using the instruction, and demo executions of the instruction in VisibleZ. The notes for each instruction are included in a Powerpoint document. You can already find some introductory assembler videos on the resources page. If you have an instruction you would like to hear about soon, drop me a line and let me know. I’ll try to build a video for it as soon as possible.

Leave a comment

October 20, 2012 · 8:42 pm