A Neat ALC Trick 
Author Message
 A Neat ALC Trick

At my late age I was just taught a neat trick for testing if a
field is blank.
        CLI     FIELD,C' '      If 1st byte not blank  
        BE      NOTBLANK        ..field cannot be blank
        CLC     FIELD+1(L'FIELD-1),FIELD        
        BNE     NOTBLANK
* fall thru if FIELD is blanks
        .      
        .
NOTBLANK DS     0H

Exercise: Prove that the code falls through iff FIELD is all
blanks, assuming of course that L'FIELD <= 256. (Hint: Use
mathematical induction).

I have to code ZAPs where space is tight, and I was impressed with
the elegance of this trick.



Mon, 06 Nov 2000 03:00:00 GMT  
 A Neat ALC Trick



Quote:

>writes:

>>        CLI     FIELD,C' '      If 1st byte not blank  
>>        BE      NOTBLANK        ..field cannot be blank
>>        CLC     FIELD+1(L'FIELD-1),FIELD        
>>        BNE     NOTBLANK
>>* fall thru if FIELD is blanks
>>        .      
>>        .
>>NOTBLANK DS     0H

>Shouldn't the first comparison be BNE NOTBLANK?  You really do not want to
>branch to NOTBLANK if the first character _is_ a space.

Jeeez!  What a picky bunch we are.

--
Rick Anderson
Seattle
anderson aatt pobox fullstop com



Tue, 07 Nov 2000 03:00:00 GMT  
 A Neat ALC Trick


Quote:
Anderson) writes:
>What a picky bunch we are.

If you think we are picky, just try computers--they are unforgivingly picky! 8)

Mark A. Young



Tue, 07 Nov 2000 03:00:00 GMT  
 A Neat ALC Trick

Quote:

> However, the beauty of CLC FIELD,BLANKS is that it WORKS!

         CLC   FIELD,BLANKS
         BNE   NOTBLANK
         ...
FIELD    DS    CL10
         ...
BLANKS   DC    CL8' '

Quote:
> and > 1.  The code breaks when L'FIELD = 1.

Just as your code breaks when you don't check that the constant is large
enough. However, in his case the assembler will catch the error.


Tue, 07 Nov 2000 03:00:00 GMT  
 A Neat ALC Trick

Quote:

>And this is one way to clear a register!

>       L    R1,=H'-1'
>       BCT  R1,*

To clear a register, I usually use a two-byte instruction that makes no memory
reference:

    XR  R1,R1

A lot of IBM code uses:

    SR  R1,R1

Mark A. Young



Tue, 07 Nov 2000 03:00:00 GMT  
 A Neat ALC Trick

Quote:


> >And this is one way to clear a register!

> >       L    R1,=H'-1'
> >       BCT  R1,*

This was a joke. Apparently, the joke wasn't obvious. The last time I
ran this (on a 370/168) I gave up after half an hour.

Quote:
> To clear a register, I usually use a two-byte instruction that makes no memory
> reference:

>     XR  R1,R1

> A lot of IBM code uses:

>     SR  R1,R1

The last time I looked up the instruction time for XR versus SR was on a
360/40. The time was identical except in the spacial case where the
register contained the maximum magnitude negative number (x'80000000').
In this special case SR required an additional cycle that XR did not
require. Since then, I have always used XR to clear a register instead
of SR.

--

Beyond Software, Inc.      http://www.beyond-software.com
"Transforming Legacy Applications"



Tue, 07 Nov 2000 03:00:00 GMT  
 A Neat ALC Trick



Quote:
> Since then, I have always used XR to clear a register instead of SR.

I generally use SLR to clear a register because, when I studied the JES2
code back in the mid 1970s, that's what was used most of the time for this
function so I figured there was a good reason for it.  Since then, I
noticed that the PL/S, PL/AS and PL/X translators also use SLR to clear a
register.  

There may not be any reason to use SLR instead of SR or XR on modern
hardware, but why change?




Tue, 07 Nov 2000 03:00:00 GMT  
 A Neat ALC Trick

I remember one machine were XR was much slower than SR or SLR.  Don't
ask me which one.  I'm in the SR camp, by the way.

Quote:
> The last time I looked up the instruction time for XR versus SR was on a
> 360/40. The time was identical except in the spacial case where the
> register contained the maximum magnitude negative number (x'80000000').
> In this special case SR required an additional cycle that XR did not
> require. Since then, I have always used XR to clear a register instead
> of SR.

-- Steve Myers

The E-mail addresses in this message are private property.  Any use of them
to  send  unsolicited  E-mail  messages  of  a  commerical  nature  will be
considered trespassing,  and the originator of the message will be  sued in
small claims court in Camden County,  New Jersey,  for the  maximum penalty
allowed by law.



Tue, 07 Nov 2000 03:00:00 GMT  
 A Neat ALC Trick

Quote:

>I remember one machine were XR was much slower than SR or SLR.  Don't
>ask me which one.  I'm in the SR camp, by the way.

>> The last time I looked up the instruction time for XR versus SR was on a
>> 360/40. The time was identical except in the spacial case where the
>> register contained the maximum magnitude negative number (x'80000000').
>> In this special case SR required an additional cycle that XR did not
>> require. Since then, I have always used XR to clear a register instead
>> of SR.

I have here the instruction timing chart for the 370/145.

It gives the following times (microseconds)

XR     1.935
SR     1.575
SLR   1.373

Andy Wood



Tue, 07 Nov 2000 03:00:00 GMT  
 A Neat ALC Trick

Interesting.
Years ago, I found a comment in a nucleus listing that stated
          LA   R1,0
was the fastest way to set a register to zero.  The explanation was that XR,
SR,
SLR, et. al. were essentially iterative bit-wise, but that the LA operated
at the full
bandwidth all at once, and that, in this particular case, there was no extra
fetch.

Just to satisfy my curiosity, what does your timing chart give for LA used
this way?

Jim Ritzert

Quote:


>>I remember one machine were XR was much slower than SR or SLR.  Don't
>>ask me which one.  I'm in the SR camp, by the way.

>>> The last time I looked up the instruction time for XR versus SR was on a
>>> 360/40. The time was identical except in the spacial case where the
>>> register contained the maximum magnitude negative number (x'80000000').
>>> In this special case SR required an additional cycle that XR did not
>>> require. Since then, I have always used XR to clear a register instead
>>> of SR.

>I have here the instruction timing chart for the 370/145.

>It gives the following times (microseconds)

>XR     1.935
>SR     1.575
>SLR   1.373

>Andy Wood




Tue, 07 Nov 2000 03:00:00 GMT  
 A Neat ALC Trick


        >At my late age I was just taught a neat trick for testing if a
        >field is blank.

It's a neat trick iff it's coded correctly.

However, the beauty of CLC FIELD,BLANKS is that it WORKS!

But if you're short of space, what's wrong with CLCL?

        >    CLI     FIELD,C' '      If 1st byte not blank  
        >    BE      NOTBLANK        ..field cannot be blank

BNE NOTBLANK

        >    CLC     FIELD+1(L'FIELD-1),FIELD        
        >    BNE     NOTBLANK
        >* fall thru if FIELD is blanks
        >    .      
        >    .
        >NOTBLANK DS 0H

        >Exercise: Prove that the code falls through iff FIELD is all
        >blanks, assuming of course that L'FIELD <= 256.

and > 1.  The code breaks when L'FIELD = 1.

        >(Hint: Use mathematical induction).

        >I have to code ZAPs where space is tight, and I was impressed with
        >the elegance of this trick.



Wed, 08 Nov 2000 03:00:00 GMT  
 A Neat ALC Trick

. . .

Quote:
>Just to satisfy my curiosity, what does your timing chart give for LA used
>this way?

LA     1.452

That is for when index index resister is 0, which it is in that case.
Add extra 0.248 for non-zero index register.

One of the interesting things was that shift instructions were quite
slow. With this information, I was able to significantly speed up a
particular program by replacing a SLL with an ALR.

Probably not much residual value in those facts now.

Andy Wood



Wed, 08 Nov 2000 03:00:00 GMT  
 A Neat ALC Trick

Quote:

>Only if the assembler happens to assemble FFFF after that =H'-1'.

No, it will still work. That is, provided you don't get a protection
exception if it happens to be at a page boundary.

.
Andy Wood



Wed, 08 Nov 2000 03:00:00 GMT  
 
 [ 58 post ]  Go to page: [1] [2] [3] [4]

 Relevant Pages 

1. More pet ALC tricks...

2. Neat Net Tricks

3. YANVT: yet another neat vi trick

4. Programming BIOS Flash Roms -- Neat trick!

5. Neat Fortran/Numerical tricks

6. Neat scripting trick...

7. Neat trick: `n' listboxes scrolled with one scrollbar

8. ALC TRIVIA

9. Just One More ALC Trivia

10. More ALC trivia

11. Yet another ALC trivia

12. Still more ALC Trivia

 

 
Powered by phpBB® Forum Software