steve-myers wrote:Now I know you won't reply, but at least think about these questions.
- Are the *+12 and *-10 correct? I think they are, but I've been known to goof. How did I calculate the *+12 and *-10 addresses?
- Where does the *-10 branch to? Why do I want to branch there?
- Where does the *+12 branch to? Why do I want to branch there?
- What is the purpose of the LA following the BCT instruction? Hint: think FIELD is CL8' '
- What are the instructions following the EX instruction doing?
- Why is OUTPUT+1 used in the LA after the EX instruction?
I will answer one more possible query. Why do I use a Y type address constant in RDW DC Y(..? I use Y because it aligns to a halfword boundary; AL2 does not align to anything.
Challenge accepted!
Let me try this quiz:
- Are the *+12 and *-10 correct? I think they are, but I've been known to goof. How did I calculate the *+12 and *-10 addresses?
+12 and -10 are correct.
+12 = L'BCT + 2*L'LA = 12. Both BCT and LA are RX-type 4-bytes instruction.
-10 = L'BC + L'CLI + L'BCTR = 4 + 4 + 2 = 10. BC is RX-type, CLI is SI-type, they are 4-bytes and BCTR is RR-type which is 2-bytes. - Where does the *-10 branch to? Why do I want to branch there?
-10 branches to "BCTR 15,0", which is the beginning of the loop. That instruction moves the pointer register R15 back 1 char. - Where does the *+12 branch to? Why do I want to branch there?
+12 branches to "LA 14,FIELD". It is 1 instruction after the end of the loop. It loads the start of the FILED to R14. Since R15 points to the last non-whitespace char, R15-R14 gets the length of the content in FIELD (length-1, actually). - What is the purpose of the LA following the BCT instruction? Hint: think FIELD is CL8' '
Sorry, I really have no idea. R15 is supposed to be always pointing to a valid position inside FIELD provided it is not CL0. Even if FIELD is all whitespace and the loop stops by the BCT, R15 should still point to the first char in FIELD. - What are the instructions following the EX instruction doing?
LA-LA-SR calculates the VBREC's length which include the content of FIELD plus the 2 bytes record header.
STH puts the length in the record header. - Why is OUTPUT+1 used in the LA after the EX instruction?
After the EX, R15 holds the (length-1) of the content in FIELD. If we do "@OUTPUT + R15 - @RDW", we get the (record length-1), so we must plus 1 there. By the way, R15 must hold (length-1) due to MVC.
Regarding question 4... if FIELD has only 1 non-whitespace char, such as CL8'A', R15 will point to the 'A' after the loop, which will make R15 hold 0 as the length of content. However, if FIELD is CL8'', R15 will still point to the beginning of FIELD. This is a very small error and I don't even think it will bring any trouble. And neither do I think the "LA 15,FIELD" would make a difference, or, would it?...
Thanks, Steve, the quiz took that beginner (me) around an hour to do, and almost turned him on