Documente Academic
Documente Profesional
Documente Cultură
Caveat: The code samples below are intended as a starting point for your own use, it is your responsibility to ensure they works correctly in your situation. For instance, the code below assumes that 0 through 15 have been equated to R0 through R15, whereas sometimes equates are set-up so that 0 through 15 become R0 through R9, RA through RF.
LOOP * * NEXT
The m ore pe rform ance m inde d m ight use TRT (translate and te st) , but this has ce rtain disadvantage s: it ne e ds a 256 byte table with a non-ze ro value in e ach byte e x ce pt the one at offse t X40, it use s R 1 and R 2 im plicitly which m ight be inconve nie nt in the conte x t of a re al program and its awk ward if the input are a is m ore than 256 byte s long be cause you have to re pe at it for e ach 256-byte chunk .
The following alte rnative m e thod of the TRT m e thod ove r the CLI loop m e thod, but without the disadvantage s. LA R14,AREA R14 --> Start of input area LA R15,LAREA R15 = Length of input area L R5,=AL1(C' ',0,0,0) R4 = Blank pad char + zero length LOOP CLCL R14,R4 Search for a non-blank character BE ALLBLANK Exit if none found * (take appropriate action - R14 points to a non-blank character) NEXT LA R14,1(,R14) Dont find same non blank again BCT R15,LOOP Continue unless that was last byte This look s pre tty sim ilar to the CLI loop, but the CLCL instruction can bypass large num be rs of blank s with e ach e x e cution. If the e ntire input are a is blank , you can only e x e cute it once anyway. The re are two points to note about the way CLCL work s in this e x am ple : 1. Be cause the se cond ope rand le ngth (in the thre e byte s of R5) is ze ro, the se cond ope rand addre ss is ignore d - R 4 doe snt e ve n have to contain a valid addre ss. (Howe ve r, be ware the high byte of R 4 will be change d anyway, e ithe r to the whole byte cle are d to binary ze ro if in 24 bit addre ssing m ode , or just the top bit if in 31 bit addre ssing m ode ! ) The instruction use s an im plie d se cond ope rand, which is the sam e le ngth as the first ope rand and consists e ntire ly of the pad characte r supplie d in the high byte of R5, in this case a blank . So the com parison stops whe n a non-blank byte is found in the first ope rand. 2. CLCL (lik e MVCL) incre m e nts the addre ss re giste rs and de cre m e nts the le ngth re giste rs as it goe s; so you can continue whe re you le ft off with only a m inor adjustm e nt to avoid finding the sam e non-blank characte r ove r and ove r again. Incide ntally, the condition code se t by CLCL is the sam e as for CLI, so if the Tak e appropriate action code use s the condition code to distinguish be twe e n value s le ss than X40 and those gre ate r than X40, it will still work .
WORK PDVAL
R2,R2 Clear TRT result register WORK(L*2+1),FIELD(L+1) Put each nibble into a separate byte WORK(L*2),PDVAL-C'0' Look for a sign BADSIGN Error if no sign found at all BADDIGIT Error if sign found before end R2,NEGATIVE Branch if negative sign found at end POSITIVE Must be positive sign at end. CL(L*2+1) 10X'00',AL1(2,1,2,1,2,2)
The above e x am ple is valid for fie lds up to 7 byte s long. For longe r fie lds, the basic te chnique is still valid but you ne e d m ore UNPK instructions at the be ginning. For e x am ple , if L is be twe e n 8 and 14, the following will do:
UNPK UNPK
WORK(15),FIELD(8) WORD+14(L*2-13),FIELD+7(L-6)
Nice and sim ple and avoids anothe r of those boring CLI loops. O f course it will not catch invalid characte rs in the range XFA-XFF which are nt lik e ly from a vanilla 3270, but if you have the possibility of APL k e yboards the n you will ne e d to che ck the appropriate IBM m anual to se e what the y can se nd back .
+4 etc bad code +0 ok code drop through to normal processing if R15 is zero
The above two instructions can be rationalise d to just the following one , but the re is no such thing as a fre e lunch so the downside is that this will only work with odd value re giste rs, and that the value in the re giste r is alte re d so it can't be re lie d on to have the original value in subse que nt proce ssing. Howe ve r it doe s save 4 byte s e ach tim e it is use d, so it is not worth doing for just one te st, but m ay be worth it if the re are a lot of te sts. Do m ak e sure you code and te st care fully, a typo of R 1 inste ad of R 15 could waste a lot of tim e . BXH R15,R15,ERRRTN
* CSECT EQU 1 EQU 2 EQU 1 EQUTEST EQUTEST EQUTEST EQUTEST EQUTEST EQUTEST
this should cause an assembly error and this will be another another error
DC * *
H'0'
Fail 1st time Fail 2nd time through Fail 3nd time through Becomes XI *,X'97' 2nd time through
You m ight say this is a waste of tim e be cause I can ste p through m y code with a de bugge r, we ll that is true in your own te st/de ve lopm e nt e nvironm e nt, but is not m uch use in a production e nvironm e nt or whe n shipping code to run on anothe r m ainfram e .
Lack of addressability
O ne of the classic proble m s of an asse m ble r program that grows and grows ove r the ye ars is that of addre ssability. A program with a single base re giste r can addre ss from 0 to +4095 byte s, and for e ve ry additional base re giste r anothe r 4096 byte s can be addre sse d. Howe ve r in a m ainte nance situation putting in som e e x tra code can blow the lim it and the re m ay not be a spare conve nie nt re giste r to use to addre ss anothe r 4096 byte s of program . The following te chnique s m ay be found use ful in a de spe rate situation with short tim e scale s, but whe re tim e pe rm its a total code re -structure to re m ove the addre ssability issue is always the be st solution as the following trick s only put off the day of re ck oning and le ave an e ve n bigge r he adache for the ne x t pe rson doing m ainte nance . W he re tim e pe rm its and the code is going to be in use for som e tim e to com e , the n the pre fe rre d solution is always to re structure the program by bre ak ing it down into se ve ral m odule s.
sam e code inline in se ve ral place s. If so the n it worth se e ing if the com m on re pe ate d can be conve rte d to be a subroutine calle d by a BAL instruction.
Generates a 132 byte literal achieve the same effect with 128 less bytes
Now you've re ad the quick and e asy hints and tips try the se ction on writing m aintainable code , or de lve a little into the world of m acros.
Privacy Information