Lots of Code On One Base Register

Do your assembler programs look like they were written in 1970?  Are you still using the instruction set your dad learned back in college?  There are lots of new instructions you can master with minimal effort.  Consider branching.  The old-fashioned BC and all the related extended mnemonics (BL,BH, …) all use base/displacement addresses to satisfy your desire to change locations.  But there is a host of newer, relative-branch instructions that determine the target location by adding a signed binary integer to the beginning instruction address instead.  What’s the difference?  The old BC-based instructions require that you have a base register covering up the target address, so if you have lots of executable code, you’ll need more base registers.  The new relative branch instructions don’t need a base register at all – they jump forward and backward from the current instruction’s address.

So … if you put all the static storage fields together and keep them separate from your executable code, one base register might be sufficient.

I’ve put together a sample program at http://csc.columbusstate.edu/woolbright/relative/relative.txt  that demonstrates how this can happen.  There’s also a new video in the video course that walks you through it at  http://csc.columbusstate.edu/woolbright/relative/relative.html .  The program uses a newer linkage technique but its not a requirement for this idea to work for you.

It’s time to show your daddy a thing or two…

1 Comment

Filed under IBM Mainframe Assembler

One response to “Lots of Code On One Base Register

  1. Joe Developer

    It is possible to write large programs without more than one code base register and without using the relative and immediate facility instructions. Basically it is a natural process of writing your mainline and calling subroutines to process logical sections of code much like you do in high level languages.

    Each subroutine saves the caller’s registers as usual and then reestablishes addressability to itself using the same base register as the caller (and indeed the entire program). Clearly there is no magic here, you can’t have a subroutine larger than 4k and you can’t have a mainline larger than 4K. It is a managment technique and it can help you manage large projects so that things don’t get out of hand.

    If you break up your code into functional or logical sections of appropriate size then this works well. In practice I have not found it limiting and have seen it used on single source decks up to around 20+ thousand lines of code- these are in systems up to a few million lines of code.

    I wanted to point out that writing significant code in the real world neither requires multiple code base registers nor the relative and immediate facilty.
    It’s been a long time since IBM machines didn’t have the relative and immediate facility but we had to support ones that didn’t before it came out and then when it came out we still had to support old boxes and we didn’t see a need to change.

    If you start out coding today as a newcomer then relative and immediate is probably a good way to go. But if you are in the vendor software business you are probably not going to see much of that and if you code it yourself you’re going to get a lot of funny looks for a while!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s