Page 1 of 1

what does this piece of code do ?

PostPosted: Tue Jul 01, 2008 2:20 pm
by Sunitha.P
ABRC#50  EQU         *                     
         IC          R03,0(,R10)           
         IC          R03,0(R03,R12)       
*                                                             
         STC         R03,0(,R11)           
*                                       
         LA          R10,1(,R10)           
         LA          R11,1(,R11)         
*                                 
         BCT         R09,ABRC#50         


Hi..
I wantd to knw meanin abt this piece of code ?
Can anyone plss explain each line ? I want to knw in detail as what is moved to what...like which parameter(1st,2nd..)in the register is moved to another register...

Re: what does this piece of code do ?

PostPosted: Mon Sep 08, 2008 10:40 pm
by MarkGoodrich
This is probably a translation loop.

Apparently, on entry to this piece of code,

R10 points to a list of one-byte offsets of fields within a table pointed at by R12
R11 points to an output list of one byte fields.
R12 points to a table, might be a translation table.

R9 contains the number of fields being processed.

R3 is used as a work register(assumed to be initially zero) to:

Load an offset from the location R10 points at.
Load the data byte from the table R12 points at that is at the offset.
Store the data byte in the output location pointed at by R11

The loop control then:

Increments the input pointer reg R10
Increments the output pointer reg R11

Loops, decrementing R9 until it goes non-positive.

This is probably the output of a compiler since it is much more efficient to use a MVCL instruction to copy the source to the destination, then use the EX instruction against a TR instruction to process up to 256 bytes at a time.

TR will replace the bytes in the destination string with those at their indicated offset in the table. Here R12 is the 256 byte table. If the length of the string is always going to be less than 256, an executed MVC from (R10) to (R11) followed by an executed TR from (R11) against (R12) will do it many times faster than the loop.