# Master the Mainframe User Group - Group home

### MTM 2019 Part 3 Challenge 11 - Assembler Challenge

#### By William Downie posted Thu February 27, 2020 05:51 AM

Hello Mainframers!

My name is Will. I have been working on the Mainframe platform as an Assembler application programmer for many years now. I found out about the MTM Challenge at a "Mainframe Meetup" in London, and decided to take part to broaden my knowledge of the Mainframe, particularly Cobol programming, DB2 and to try and get an understanding of what Sys Progs do.

As many of you will probably be new IBM Assembler I thought I'd share some tips on how I went about Challenge 11.

The point of the challenge is to write out a third message. I'm guessing that many of you did something like this:

Of course, this works but I thought it could be improved upon.

First thing is to give the registers an equate, no-one refers to registers using just a number. Reference to registers in Assembler is done a lot !  In my code I am going to use two registers, I chose 2 and 3, so equated R2 and R3 to these. Doing this means I can now refer to R2 and R3 in the source code:

As the challenge is to print out three messages I thought this could be done in a loop, that iterates three times. To keep this simple I assumed each message will be 80 characters in length (rather than variable length). I constructed the following table that contains the three messages:
To keep the table neat, I have moved the DC (Define Constant) to column 2. This allows the longer third message to fit in a single line. If I didn't do this then the third message would need to be over two lines, which makes the table less easy to read.

In Assembler we always aim to avoid hard coding, trying to make all length's etc soft. So, I have defined the length of the message as an equate called MLQ and set this to 80. This can now be used in the field length, CL80 is replaced by CL(MLQ). And a second equate I have added is MSG#Q. This is the number of entries in the table, dividing the size of the table by the length of an entry.

The code to reference the table is as follows:

One thing the sample code provided missed was comments. It is good practice to put a meaningful comment next to each instruction.

I'll go through what each line is doing:

LHI   R3,MSG#Q
This is loading the number of messages into R3. MSG#Q is calculated at assembly time. In this case it is 3.

LA   R2,MSGTAB
This is pointing R2 to the start of the message table.

LOOP   PUT RECDD,0(R2)
LOOP is a label that we can branch to.
PUT is the IBM supplied macro that will write the record to the DDNAME referred to in the RECDD DCB. As R2 is pointing to the record I am telling the macro to PUT  the record that R2 is pointing to.

AHI   R2,MLQ
This adds the value equates to MLQ (80) to R2. R2, will now point 80 bytes on.

BCT   R3,LOOP
This is Branch on CounT. It subracts 1 from R3 and if the result is not zero, branches to LOOP.

I hope this shines a little light on IBM Assembler. If you have any questions about this challenge, or if you'd like to know why I chose to use R2 and R3 (rather than say R0 and R1)  or any Assembler questions in general please get in touch.