Loading...
Select Version
&pagelevel(4)&pagelevel
The following function is to be implemented in Assembler and C:
XSUBSTRING[2/3](STRING = <string_expression>
,START = <arithm_expression>
,LENGTH = <arithm_expression> / *REST-LENGTH
)
Assembler interface
Title of the function: |
|
Entry: |
|
Input data: |
|
Output data: |
|
First step: syntax specification.
BIFDESC NAME='XSUBSTRING2', -
ENTRYN=(*CSECT,XSUBDEF2), -
PARLIST= -
((STRING,*STRING), -
(START,*INTEGER,1), -
(LENGTH,*INTEGER,*REST-LENGTH, -
(*REST-LENGTH)) -
), -
PARFORM=BY-VALUE,
VALTYPE=*STRING
END
Second step: execution program
XSUBEX2 CSECT
XSUBEX2 AMODE ANY
XSUBEX2 RMODE ANY
STM 14,12,12(13) Save the caller’s registers
BASR 10,0 R10: base register
USING *,10
USING DSMDL1,4
USING DSMDL2,5
*
L 1,0(0,1) R1 ->a(p1) => R1=a(p1)
*
LA 5,48(1) R5 -> fifth element of the
operand list (e.g. RC)
L 5,4(5) R5 -> RC
MVC 0(9,5),OKRC Set RC = OK
*
LA 4,0(1) operand list starts at R4
L 6,BIF1VLG R6: length of the STRING operand
L 7,BIF1VPT R7: addr. of the STRING operand
LTR 6,6 Is the length of STRING=0?
BE MSGNULL Send a message NULL_STRING
*
LA 4,12(1) Second element of the operand
list follows at R4 (e.g. START)
LA 2,1(0,0) R2 = 1
L 8,BIF1VPT R8: address of the START value
L 8,0(8) R8: value of START
CR 8,2 If START < 1
BL MSGBOUN Send message OUT_OF_BOUNDS
CR 8,6 If START > length of STRING
BH MSGBOUN Send message OUT_OF_BOUNDS
*
LA 4,24(1) Third element of the operand
list follows at R4 (e.g. LENGTH)
* R3 = len. of STRING - START + 1
LA 3,1(0,0) R3 = 1
AR 3,6 R3 = R3 + length of STRING
SR 3,8 R3 = R3 - START
CLI BIF1VTY,BIF1INT
BE LENINT
LENKEYW DS OH
* *Look for REST-LENGTH
LR 9,3
B @0001
LENINT DS OH
* LENGTH = *INTEGER
L 9,BIFTVPT R9: address of the LENGTH value
L 9,0(9) R9: value of LENGTH
CR 9,2 If LENGTH < 1
BL MSGBOUN Send message OUT_OF_BOUNDS
CR 9,3 If LENGTH < REST-LENGTH
BNH @0001 Then ok
LR 9,3 LENGTH is truncated
MVC 0(9,5),TRUNCRC Set RC = TRUNCATED
@0001 DS OH
Calculate the function value
LA 4,36(1) Fourth element of the operand
list (e.g. FUNCTION_VALUE)
follows at R4
L 6,BIF1VPT R6 : address of function value
AR 8,7 R8 = address of STRING + START
SR 8,2 R8 = R8-1
LR 7,9 R7 = length of function value
ST 7,BIF1VLG
MVCL 6,8 Copy into function value
* B RETURN
MSGNULL
MSG7X MF=E,PARAM=NULLPL
MVC 0(9,5),NULLRC Set RC = NULL_STRING
* B RETURN
MSGBOUN
MSG7X MF=E,PARAM=BOUNDPL Set RC = OUT OF BOUNDS
* MVC 0(9,5),BOUNDRC
RETURN
LM 14,12,12(13) Write back caller’s registers
OKRC BR 14 Return to the caller
DC XL1'00'
DC XL1'00'
TRUNCRC DC CL7'CMD0001'
DC XL1'02'
DC XL1'00'
BOUNDRC DC CL7'SDP0414'
DC XL1'00'
DC XL1'01'
NULLRC DC CL7'SDP0412'
DC XL1'00'
DC XL1'01'
DC CL7'SDP0411'
DS OF
NULLPL MSG7X MF=L,ID=SDP0411
BOUNDPL MSG7X MF=L,ID=SDP0412
DS OF
DSMDL1 BIFMDL1 MF=D
DS OF
DSMDL2 BIFMDL2 MF=D
END
Third step: update BIFTAB
BIFTAB CSECT
.....
XSUBSTR2 BIFDEF MF=L,NAME=XSUBSTRING2,SYNTAX=XSUBDEF2,CODE=XSUBEX2
.....
END