HLASM Toolkit Structured Assembler macros
One of the biggest impediments to being productive with assembler is how you code complex selection logic tests. For example in Cobol say, you might code something like this:
IF condition1 OR condition2 OR condition3 THEN…
Pretty simple and easy to understand and in fact in assembler it’s not that much harder:
test for condition1
branch if true to LABEL1
test for condition2
branch if true to LABEL1
test for condition3
branch if NOT true to LABEL2
Code here is any of the above is true
Exit point for code, also if none of the above conditions are true, thus bypassing the above code.
Pretty easy to follow, but,what about something like:
IF (condition1 AND condition2) OR condition3 THEN…
Get the assembler branch logic wrong and you could end up implementing this instead quite easily:
IF condition1 AND (condition2 OR condition3) THEN…
Not only that, but unless you document within your code exactly what selection logic you are trying to implement in the code then it can be hard for someone later on (maybe trying to fix a bug in your code or modify it to do something else) to understand exactly what you intended and why. Of course if that person then makes changes to your code and does not also document what the new logic in supposed to be doing then you are just as screwed but that’s another story!
Part of the problem comes from having to create unique label names for all those intermediate branches and make sure that you are going to the correct label for any given condition. Some people might argue that that is part of being an assembler programmer but when you are getting paid for this stuff, and when a client is waiting for a working, tested, fault free piece of code to be delivered, I don’t think you can afford the luxury of insisting that you do the ‘proper’ way.
There is however a solution to this predicament in the form of the HLASM (High Level Assembler) Toolkit Structured Assembler macros. Unfortunately these do NOT come by default with the assembler which means that they cost extra! but if your site has them them then they can improve both your productivity, and the readability and maintainability of your code.
With the structured assembler macros you could now write this for example:
Y0ur raw assembler code here
Whilst not exactly like higher level languages like C and Cobol, it’s pretty close and you have to admit that it’s a LOT easier to see the intended logic and to understand it. The nice thing about these macros is that they generate all the intermediate labels for the branching themselves so that your source code is a lot easier to read and understand since it’s not cluttered up with labels and code that have nothing to do with the logic of the business problem being solved, but are there simply to implement your solution to specific coding situations.
You can even nest the macros so that you can code something like this:
IF complex condition
do something else
Again, much easier to understand the intended logic and much easier to read in source code form.
Why would you NOT want to do this.
The toolkit macros also give you the ability to implement DO loops, including DO WHILE and DO UNTIL, as well as CASE and SELECT statements. Remember, you can do all of this in raw assembler code and as an educational opportunity, there is nothing wrong with doing so but if you have these macros available you will find that your productivity will increase by leaps and bounds, not only because you don’t have to spend as much time “writing logic just to implement logic”, but because you will be sure (as far as you can) that the code your write does actually implement your intended logic. That means fewer mistakes, less testing time, more reliable software and better productivity.