Top Xread Card, 80 Read Rec
Total Page:16
File Type:pdf, Size:1020Kb
XDECO/XDECI
MAIN CSECT USING MAIN,R15 * TOP XREAD CARD, 80 READ REC BC B’0100',EXIT CHECK EOF XDECI R2,CARD GET FIRST NUM XDECI R3,0(R1) GET NEXT NUM AR R3,R2 ADD NUMBERS XDECO R3,SUM BACK TO CHARACTER XPRNT PLINE,33 PRINT PLINE B TOP GO TO TOP OF LOOP * EXIT BR R14 LEAVE PROGRAM ****************************************************** CARD DC 20CL4'CARD’ 80 BYTE CARD PLINE DC CL1' ‘ CARRIAGE CONTROL DC CL20'HERE IS MY SUM’ MESSAGE SUM DC CL12'HI’ MUST BE 12 BYTES! END /* //FT05F001 DD * 5 7 6 10 (these are in stream data records 2 3 you type in for data) /*
(this is the printed output you would see in your job output)
HERE IS MY SUM 12 HERE IS MY SUM 16 HERE IS MY SUM 5
DO WHILE CONSTRUCT
WE WANT TO DO A LOOP 5 TIMES
PSEUDOCODE:
SET UP COUNTERS DO WHILE (COUNT <> 5) DO WORK IN LOOP ENDDO
CODE:
SR R2,R2 SET R2 TO O L R5,FIVE SET R5 TO 5 * DO1 CR R2,R5 ARE THEY = BC B’1000’,ENDDO1 BRANCH ON CC OF 0 TO DONE BE ENDO1 ***MNEMONIC ALTERNATIVE
(DO WORK IN LOOP HERE)
A R2,ONE ADD 1 TO R2 B DO1 GO TO TOP UNCONDITIONALLY * ENDDO1 go on with other code
++++++++++++++++++++++++++++++++++++++++++++++++++++ FIVE DC F’5’ ONE DC F’1’ IF - THEN CONSTRUCT
IF (NUM1 > NUM2) THEN ANSWER = NUM1 + NUM2 END IF
REGISTER 2 - > NUM1 REGISTER 3 - > NUM2 REGISTER 4 - > ANSWER
IF CR R2,R3 BC B'1101',ENDIF OR BNH ENDIF (fall through if higher,skip if not higher) LR R4,R3 AR R4,R2 ENDIF DS 0H ______
IF - THEN - ELSE CONSTRUCT
IF (NUM1 > NUM2) THEN ANSWER = NUM1 + NUM2 ELSE ANSWER = NUM1 ENDIF
REGISTER 2 - > NUM1 REGISTER 3 - > NUM2 REGISTER 4 - > ANSWER
IF CR R2,R3 BC B'1101',ELSE OR BNH ELSE LR R4,R3 COPY NUM2 TO ANSWER AR R4,R2 ADD NUM1 TO ANSWER BC B'1111',ENDIF OR B ENDIF ELSE DS 0H LR R4,R2 SET ANSWER=NUM1 ENDIF DS 0H
note DS 0H is used as a dummy label so we have a label to branch to, this is a common coding technique BUILDING A TABLE
BUILD DS 0H BUILD STARTS HERE LA R5,TABLE POINT TO TABLE * TOP XREAD CARD, 80 READ REC BC B’0100',EXIT CHECK EOF XDECI R2,CARD GET FIRST NUM ST R2,0(R5) PUT ENTRY IN TABLE LA R5,4(R5) GO TO NEXT ENTRY B TOP GO TO TOP OF LOOP * EXIT ST R5,EOT SAVE EOT BR R9 GO BACK TO MAIN ***************************************************** CARD DC 20CL4'CARD’ 80 BYTE CARD TABLE DC 10F’-15’ TABLE EOT DC F’-5’ EOT SAVED HERE INTERNAL SUBROUTINES
MAIN: BAL R9, BUILD CALL INTERNAL SUB BUILD . . . BUILD DS 0H BUILD STARTS HERE LA R5,TABLE POINT TO TABLE * TOP XREAD CARD, 80 READ REC BC B’0100',EXIT CHECK EOF XDECI R2,CARD GET FIRST NUM ST R2,0(R5) PUT ENTRY IN TABLE LA R5,4(R5) GO TO NEXT ENTRY B TOP GO TO TOP OF LOOP * EXIT ST R5,EOT SAVE EOT BR R9 GO BACK TO MAIN ***************************************************** CARD DC 20CL4'CARD’ 80 BYTE CARD TABLE DC 10F’-15’ TABLE EOT DC F’-5’ EOT SAVED HERE MVC/CLC SS INSTRUCTIONS
MVC IMPLIED MVC F1,F2 MVC F1(4),F2 ALWAYS USE LENGTHS MVC F1(4),F3 MVC F1(4),=CL4’MIKE’
MVC EXPLICIT LA R1,F1 LA R2,F2 MVC 0(4,R1),0(R2) SAME AS LINE 1 up top
CLC CLC F2(4),F3 LOGICAL COMPARE CLC F4(4),F5 WHICH IS GREATER?
F1 DC CL4’bbbb’ F2 DC CL4’BILL’ F3 DC CL4’BIFF‘ F4 DC XL4’FFFFFFFF’ F5 DC XL4’00000001’ CLI/MVI SI INSTRUCTIONS
MVI PLINE,C’b’ MVI PLINE,C’1’
CLI BYTE,’A’ CLI BYTE,X’C2’ CLI PLINE,C’-’
BYTE DC CL1’b’ PLINE DC CL133‘THIS IS MY PLINE’
Clear a PLINE with blanks:
MVI PLINE,C’b’ MVC PLINE+1(122),PLINE
PLINE DC CL123’THIS IS MY PLINE’
EDIT used to convert from packed decimal to character for printing p 172 niu text are these examples
1. MVC PLINE+1(4),=XL4'40202020' Move pattern to pline ED PLINE+1(4),F2 —> 12 3C Edit packed num with pattern
40 20 20 20 40 F1 F2 F3 <---- Result after edit
Say F2 HAS 00 0C
40 40 40 40 <---- Result after edit
2. 40 20 21 20 21 in the pattern is significance starter
Edit 00 0C
40 40 40 FO IS RESULT AFTER EDIT
5. 40 20 6B 20 20 20 6B 20 20 21 4B 20 20 Edit 00 12 34 56 7C
40 40 40 40 F1 F2 6B F3 F4 F5 4B F6 F7 12,345.67 <-- after we print Edit 00 00 00 02 3C 40 40 40 40 40 40 40 40 40 40 4B F2 F3 .23 STANDARD LINKAGE
MAIN CSECT
LA R13,MSAVE POINT 13 AT MAIN SAVE (***This statement is for a teaching purposes)
LA R1,PLIST POINT R1 AT LIST OF ADDRESS. L R15,=V(BUILD) 15 POINTS TO SUBROUTINE BALR R14,R15 GO TO SUB, R14 IS RETURN
CARD DC CL80'CARD’ CARD TO READ INTO PLIST DC A(CARD,TABLE,EOT) LIST OF ADDRESSES TABLE DC 50F’-1' TABLE EOT DC F’-1' BUILD FILLS THIS IN MSAVE DC 18F’-1' MAIN SAVE AREA
______BUILD CSECT STM R14,R12,12(R13) SAVE CALLERS REGS LR R12,R15 POINT 12 AT START OF BUILD USING BUILD,R12 R12 IS BASE REG LA R14,BSAVE POINT AT BUILD SAVE AREA ST R14,8(R13) SET FORWARD POINTER ST R13,4(R14) SET BACK POINTER LR R13,R14 R13 IS NOW AT BUILD SAVE
LM R2,R4,0(R1) BRING IN PARMS, AT 0(R1) IS A LIST OF POINTERS XREAD 0(R2),80 WE READ CARD LIKE THIS
L R13,4(R13) GET OUT BACK POINTER LM R14,R12,12(R13) RESTORE REGS BR R14 GO BACK TO MAIN
BSAVE DC 18F’-1' BUILD SAVE PACKED DECIMAL
XREAD CARD,80 READ A CARD WITH 00032 IN CHAR ON IT
PACK NUM1(3),CARD(5) CONVERT FROM CHAR TO PACKED
AP NUM1(3),NUM2(2) ADD 5 TO NUM1 SP NUM1(3),NUM2(2) SUBTRACT 5 FROM NUM1 CP NUM1(3),=PL2'4' SEE IF NUM1 IS 4
ZAP BNUM(6),NUM1(3) MOVE TO BIGGER NUM MP BNUM(6),NUM3(2) NEED 2 BYTES LEADING ZEROS
DP NUM5(5),NUM4(2) ANSWER ON LEFT, REM ON RIGHT LENGTH OF REM. IS LENGTH 2 NUM5 NUM4 before 00 00 00 03 2C 00 3C after: ans rem 00 01 0C 00 2C
ZAP NUMOUT(5),NUM5(5) CAN YOU DO THIS? ______NUM1 DC PL3'1' NUM2 DC PL2'5' NUM3 DC PL2'3' BNUM DC PL6'0' NUM5 DC PL5'32' NUM4 DC PL2'3' NUMOUT DC PL5'0' SELECTION SORT ALGORITHM
BEGIN initially is a pointer to the first entry END is a pointer to the last entry I and LOW are also pointers 1 is the length of one entry
Do While (BEGIN < END) LOW = BEGIN I = BEGIN + 1 Do While (I not > END) If Key (LOW) > Key (I) LOW <- I Endif I = I + 1 Enddo Swap ENTRY (BEGIN) with ENTRY (LOW) BEGIN = BEGIN + 1 Enddo