terça-feira, 10 de abril de 2018

Learning Assembler: Where Do You Start?

So you want to learn to program in assembler. Congratulations, and welcome to the select few. Most programmers are terrified of assembler language, and stick to more comfortable high-level languages like Java, C and COBOL. But in the mainframe world, there are times when a problem needs assembler. And by learning to program in assembler, you’re going to gain other benefits: the basics of dump analysis, a better understanding of how programs work, and even hints on improving program efficiency.
The problem is that for the beginner, learning assembler is hard. Hard, but not impossible. Twenty-odd years ago I did it with less resources than are available today. And I’m not alone. So if I were starting over again, how would I learn assembler today?

Step 1: Get the Tools

First of all, you need somewhere where you can create, assemble and run your programs. The best place is a test z/OS system. However if this isn’t an option, all is not lost. You can use the excellent and free z390 Assembler Emulator from www.z390.org.
The rest of your tools are books:
  • IBM Principles of Operation – I call it POPs. This is a scary looking book describing the internal workings of the System z processors. But don’t be afraid. It lists all the assembler instructions, and what they do. Once you get used to the format, this is the best assembler instruction reference. You can find it on the front page of the z/OS Infocenter.
  • Bill Quall’s Mainframe Assembler Programming. Originally written by Bill in 1998, and now available as a free download. This is a great introduction to assembler programming. Bill refers to the PC/370 emulator in this book – this is now the z390 emulator mentioned above.
  • HLASM Programmers Guide – you will use this together with POPs above. POPs details instructions to the mainframe processor. This book explains about assembler language, and how to use the High Level Assembler. Also available from the HLASM section in the z/OS Infocenter.
  • MVS Programming: Assembler Services Guide and the two MVS Programming: Assembler Service References . These are three books that describe the z/OS system services you can call from assembler. Again, found in the MVS section in the z/OS Infocenter.
  • DFSMS Macro Instructions for Data Sets – this describes the assembler macros essential for access VSAM and non-VSAM datasets. Found in the DFSMS section in the z/OS Infocenter.

Step 2a: If You Can, Do a Course

Here’s where the problems start. Ideally, a great first step in learning assembler would be to do a course. In the past a few vendors offered a 5 day course to introduce assembler programming, and get you started. Today, most of these have dried up, though The Trainers Friend and Verhoef still advertise classroom-based assembler courses.
If you’re lucky enough to get to a Share conference, then attend their Assembler Bootcamp: a series of five sessions introducing assembler run every conference.
All the above options assume you have a travel budget. For most of us, this isn’t possible. Interskill offer a great range of online assembler courses you can do anywhere, from introductory level up to advanced concepts such as cross-memory and 64 bit programming. If you have access, these are a great place to start. zNextGen members are eligible for free courses, and Interskill will offer an assembler course in September. Marist College’s IDCPalso hold assembler training classes that can be studied remotely.
Another alternative is to find someone who knows assembler, and is willing to be your mentor. Longpela Expertise offers a similar service through our Systems Programming Mentoring training.

Step 2b: Read

If Step 2a doesn’t work for you, it’s not all over. Here’s how you start.
  1. Work through the five Enterprise Server Intro to Programming – Assembler PowerPoint presentations from IBM. This provides an easy-to-digest introduction to assembler.
  2. Read the first five chapters of the High Level Assembler Language Reference. This builds on what you’ve already seen in the PowerPoint presentations in step 1.
    I know, there’s a lot of reading here. But before you can program in assembler, you need to know some of the basics about memory, registers, hexadecimal and other concepts. Once you have these, you’re ready to get into it:
  3. Assemble your first program. You may think that your first program will be a ‘Hello World’ program called from TSO, but this isn’t as simple as you’d think. And few assembler programs run in TSO. So a better platform to start with is batch. Modify the following JCL to suit your site, and run it:
    //JOB1 JOB  (ACCT),'ASSEMBLE',CLASS=A,MSGCLASS=X
    //* Assemble         
    //C        EXEC PGM=ASMA90
    //SYSLIB   DD  DSN=SYS1.MACLIB,DISP=SHR
    //SYSUT1   DD  DSN=&&SYSUT1,SPACE=(4096,(12,12),,,ROUND),
    //             UNIT=SYSDA,DCB=BUFNO=1
    //SYSPRINT DD  SYSOUT=*
    //SYSLIN   DD  DSN=&&OBJ,SPACE=(3040,(40,4),,,ROUND),
    //             UNIT=SYSDA,DISP=(MOD,PASS),
    //             DCB=(BLKSIZE=3040,LRECL=80,RECFM=FB,BUFNO=1)
    //SYSIN    DD   DATA,DLM=QQ
    *=====================================
    * ASSEMBLER PROGRAM
    *=====================================
    TST1  AMODE 31
    TST1  RMODE ANY
    TST1  CSECT
          BAKR  R14,0                  SAVE CALLERS ENVIRONMENT
          LR    R12,R15                LOAD OUR ADDRESS IN R12
          USING TST1,R12               USE R12 AS BASE REG
          LA    R15,53                 LOAD 53 AS RETCODE
          PR                           RETURN TO CALLER
          END                          END OF PROGRAM
    QQ
    //*
    //* Link-Edit
    //L        EXEC PGM=HEWL,PARM='MAP,LET,LIST,NCAL',COND=(8,LT,C)
    //SYSLIN   DD  DSN=&&OBJ,DISP=(OLD,DELETE)
    //         DD  DDNAME=SYSIN
    //SYSUT1   DD  DSN=&&SYSUT1,SPACE=(1024,(120,120),,,ROUND),
    //             UNIT=SYSALLDA,DCB=BUFNO=1
    //SYSPRINT DD  SYSOUT=*
    //SYSLMOD DD   DSN=MY.LOAD.DATASET(TST1),DISP=SHR
    //* Execute
    //R        EXEC PGM=TST1,COND=(8,LT,L)
    //STEPLIB  DD   DISP=SHR,DSN=MY.LOAD.DATASET
    Don’t forget to change the load library (MY.LOAD.DATASET) to your own load library. This job assembles, binds and executes a simple assembler program that returns the number 53. It’s a great first step.
  4. By now you’ve assembled and run your first program. You’re away. Go to Bill Quall’s book and start reading. Tweak the program in step 3 as you work through.

Step 3: Code

The only way to really learn assembler is to write assembler. So write assembler programs. You could write programs as you work through Bill Quall’s book. Or you could write the following programs in order, building on the simple program in Step 2b.
  1. Return the number (10+15-45)*2 to introduce mathematical options.
  2. Return a number entered as a parameter (EXEC PGM=TST1,PARM=’22’ in the jobs in Step 2a) to introduce parameter handling.
  3. Return the number of letters of a string input to introduce strings and loops.
  4. Output a parameter entered to OPERLOG/SYSLOG to introduce z/OS service routines, and in particular, WTO.
  5. Write a string into a sequential dataset to introduce datasets and allocation.
  6. Write some information into a VSAM dataset to introduce VSAM.
  7. Abend the program using the ABEND macro to introduce errors and error handling.
  8. Insert the following code into your program:
    XR  R1,R1
    BR R1
    Try to explain what this does, and why. This will introduce you to addresses, and memory management.
  9. Output the current day and time to introduce data handling, and some more system routines.
  10. Output the name of the job executing – see our Control Blocks for Beginners article for some sample code. This introduces control blocks, mapping DSECTs, and internal z/OS structure.
If you successfully managed to create these 10 programs, you’re well on your way.

Step 4: Research

Once you get confidence, start reading and researching how better to program in assembler. Here are some good places to start:
Also look for other assembler programs, and see how they work. IBM provides many in sys1.samplib. One of my favourite sources for assembler is the brilliant CBT website.

Step 5: Keep Programming

Many people do a quick assembler course, and let it lapse. Fast forward five years and they’ve forgotten almost everything. So keep on using assembler. Program, debug, and explore.
Twenty-odd years ago I taught myself assembler in a similar way to what I’ve outlined here. And I found it hard work. But it was definitely worth it, and today I love assembler. Anyone working with me will recognise when I’ve seen a chance to use assembler by the large grin on my face. I hope you enjoy it as much as I do. Good luck in your assembler adventure.

http://www.longpelaexpertise.com.au/ezine/LearnAssembler.php

Nenhum comentário:

Postar um comentário