IBM MTM: Part Three – Challenge #13

Assembler! No, it’s not a language that Ikea has come up with. Assembly, asm, scary numbers language thingy or assembler, it has many names. This is there part where I tell you I haven’t written any asm but state that I’ve written some language that looks like it. Ehh… not this time.

This challenge is about… surprise surprise! Assembler!

IBM Z Mainframe Assembler

IBM Master the Mainframe Part Three – Challenge #13

This challenge sure won’t make me a full fledged Assembler programmer but I’ll at least have some experience with asm. Asm is more difficult to learn than other languages. It requires you to learn Assembler mnemonics, machine instructions, Assembler directives, Assembler macros and you need to know a thing or two about hardware architecture.

Being able to understand Assembler gives one the ability to debug complex system problems by reading system dumps. Higher level languages such as C/C++, Java, Cobol etc. were created to make programming the computer easier by hiding the complexity of the underlying machine instructions, addressable memory and registers.

Compile assembler program

I have to admit that this challenge is a good filter. I suffer from great procrastination. Let’s go ahead and compile the assembler program. Let’s edit Z30163.SOURCE and make a new member name s asmpgm and copy ‘zos.mtm2018.public.source(asmpgm)’ and submit. I’ll jump straight to the output panel while I’m at it.
There’s a full review of what this code does available at mtm2018.mybluemix.net I doubt I’ll explain it better than IBM 🙂

Use TSO TEST facility to understand assembler program execution

Let’s test the code that we’ve compiled using test ‘z30163.load(asmpgm)’  this has to be done inside the TSO Ready prompt. I had to remove the LOGOFF command when logging in so I could =x and boot myself to the TSO screen.
Now I can run these commands. Excuse my laziness but please check mybluemix to know more about each command.

Note, I will have to enter go numerous times to proceed with the program execution. It should stop at +42.

This is an important part. We know register 2 holds the value 4. The loop continues until register 2 is zero. So it iterates a total of 4 times. We enter go 8 times because we execute 2 things inside the loop.

Well that sure was something! I did this process twice, help! Once for myself and the second time to get some screenshots. I can’t embarrass myself right?!

Modify and re-compile ASMPGM assembler program

Let’s do this boys, girls, bits and bytes!
  1. Use register 6 for all operations where register 2 was previously used
  2. Use register 7 for all operations where register 3 was previously used
  3. Initialize the register used to sum each add operation in the loop with a zero value
  4. Execute the loop 10 times adding 5 to the register being used to sum each add operation

Help! Can I pay someone to do this for me?

As for the registers 6 and 7, just change all occurrences where register 2 or 3 is used. In IBM’s explanation they state which register is being used at what line inside the code. So it’s a matter of understanding the code or just ctrl+f ‘register 2’ at mybluemix 😉

Initialise the register used to sum each add operation in the loop with a zero value is easy. Think how the two registeres are initialised now, they hold the value Begin. Then a bit further register 6 and 7 are ‘loaded‘ with value 4 and 1. I’ve only edited the one register where we add something. I didn’t touch the other register where we subtract from.

We can find the storage address of label LOOP at +3A, when we’ve entered go it adds 1 to register 3 until register 2 is zero as it subtracts one every loop. So in the end register 3 was 5 and register 2 held the value zero. How many times did we need to enter go in order to get register 2 to 0?

Think fast! IBM now wants us to execute the loop 10 times and add 5 every iteration to the register where we add a number.

I think I’ve got it right, now is a good time to debug again and tso submit ‘zos.public.jcl(p3ch13)’ to copy my code to P3.OUTPUT. Let’s debug first! Don’t make the same mistake I did, we’re debugging new registers now 🙂 not register 2 or 3. But 6 or 7.

Looks like it iterated 10 times all the way down to where register 6 equals zero and register 7 equals 0x32 (hex).

Should be it!

Share this:

11 thoughts on “IBM MTM: Part Three – Challenge #13

  1. more hints for Initialise the register used to sum each add operation in the loop with a zero value please!!! I am not able to load values into record 6, it keeps showing 6r fffffffffff.

    many thanks in advance!

    1. Hi Ronald, is it possible to paste some of your code? You should only change some things, not insert lines. I’ll make a small checklist for you.

      1. Determine which register we use to add a number. Is it register 6 or 7?
      2. This register is already initialised, just change the initialised value to 0.
      3. Be sure to change the debug register commands to 6 or 7. ‘at +3A (l 2r:3r)‘ becomes ‘at +3A (l 6r:7r)‘.

      Re-read this part 🙂

      Think how the two registeres are initialised now, they hold the value Begin. Then a bit further register 6 and 7 are ‘loaded‘ with value 4 and 1.

      1. * program body
        *—————————
        L 6,=C’Begin’
        LA 6,=C’Begin’
        LOOPINIT DS 0H
        SR 6,6 <—- subtract register 6 from itself
        L 6,=F'50' <– load '50' for subtraction of 5 /loop for 10 loops
        L 7,=F'1' <–load '1' as starting value
        *—————————
        LOOP DS 0H
        A 7,=F'5' <– addition of 5 every loop
        BCT 6,LOOP <— decrement register 6 by 5
        *—————————
        STOP1 LH 7,HALFCON
        STOP2 A 7,FULLCON
        STOP3 ST 7,HEXCON

        I made changes to the program body section only. I am using register 7 for addition(if that's the right thing to do haha).

        I see that Stmt 34 is where register 6 will be loaded with 'Begin', but which line shows register 7 being loaded with 'Begin'?

        When you mention the register is already initialize, is the step performing initialization the step below?
        stmt 37 SR 2,2
        Does this in turn mean that i am heading in the right direction by using register 6 for addition?

        Thanks for your response Kevin and your kind help!!

        1. at +2c (l 6r)
          TEST
          go
          AT +2C
          6R FFFFFFFF
          TEST
          at +2c (l 6r)
          TEST
          go
          AT +2C
          6R FFFFFFFF
          TEST
          at +30 (l 6r;l 11f8. length(5) c)
          TEST
          go
          AT +30
          6R FFFFFFFF
          INVALID ADDRESS 11F8. +
          REENTER THIS OPERAND –

          not sure if i am entering the debugging line accurately either, so here are some lines!

          1. L 6,=F’50’ < – load '50' for subtraction of 5 /loop for 10 loops L 7,=F'1' <–load '1' as starting value Why do you load 50 as a starting value? We just need to loop 10 times. We don't subtract 5 from register 6 anywhere in the code. The code only adds 5 to register 7 in the code and thats it. See this part in my blog:

            This is an important part. We know register 2 holds the value 4. The loop continues until register 2 is zero. So it iterates a total of 4 times. We enter go 8 times because we execute 2 things inside the loop

            Even IBM states:

            Stmt 42, op code beginning with x’5A’, is mnemonic A, add 1 to register 3
            Stmt 43, op code beginning with x’46’, is mnemonic BCT, decrement register 2 by 1 and branch to the label loop until register 2 is zero

            These two statements inside the loop are in no way connected to eachother.

            Also read this:

            Initialize the register used to sum each add operation in the loop with a zero value

            Why do you load a different number in it? 🙂

            My apologies for being a little bit cryptic, IBM asked me to not post the solutions.

        1. Welcome back Walter, 0x32 or 000032 shown on the screen is in Hexadecimal format. 0x32 to the decimal format equals to 50. We add 5 to the needed register and we loop 10 times, so eventually 10 times 5 equals 50.

  2. Please dont be sorry, I totally understand and dont want to put you in a spot either. Anyway, I got it already, very much thanks to your help!! Onward to ch15!!
    Cheers! 🙂

Leave a Reply

Your email address will not be published.