I generally go for the code that
     Is easy to read
     Uses the least storage
     Does not require a literal or named constant

MVHHI is six bytes and clear; the alternatives obscure the intent and none is 
shorter.

-- 
Shmuel (Seymour J.) Metz
http://mason.gmu.edu/~smetz3
עַם יִשְׂרָאֵל חַי
נֵ֣צַח יִשְׂרָאֵ֔ל לֹ֥א יְשַׁקֵּ֖ר




________________________________________
From: IBM Mainframe Assembler List <[email protected]> on behalf 
of Charles Mills <[email protected]>
Sent: Monday, February 9, 2026 1:54 PM
To: [email protected] <[email protected]>
Subject: Re: Half-word Counter in Storage -- Best Practice


External Message: Use Caution


The differences in CPU time are so minute as to be insignificant.

The big hit is bringing the counter in and out of cache, which is the
same any way you do it.

I like the last, because it is the clearest code -- the instructions
correspond to what you are doing logically: setting a counter to a
numeric zero.

/Charles/

On 2/9/2026 10:48 AM, David Clark wrote:
> If a half-word counter has to be in storage (to save on registers) and must
> start at zero, which is better or which would you prefer to do as a best
> practice?
>
> ...simply clear storage?
>
> XC    STRGLEN,STRGLEN    FOR USED STRING LENGTH COUNTER
>
> ...or clear a register and save to storage?
>
> XR    R5,R5              STARTING AT ZERO
> STH   R5,STRGLEN          SET USED STRING LENGTH COUNTER
>
> ...or use an immediate value and save to storage?
>
> LHI   R5,0               STARTING AT ZERO
> STH   R5,STRGLEN          SET USED STRING LENGTH COUNTER
>
> Sincerely,
>
> Dave Clark
> --
> int.ext: 91078
> direct: (937) 531-6378
> home: (937) 751-3300
>
> Winsupply Group Services
> 3110 Kettering Boulevard
> Dayton, Ohio  45439  USA
> (937) 294-5331
--
/Charles/
+1-707-291-0908


Reply via email to