Debugging Practice Exercise
This exercise is intended to help you understand debugging.
It is not a homework assignment and will not be graded.
You will need to run a program. Copy this code into a file and run it:
//KC_____A JOB ,'Your Name Here',MSGCLASS=H
//STEP1 EXEC PGM=ASSIST
//STEPLIB DD DSN=KC02293.ASSIST.LOADLIB,DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
********************************************
* PRACTICE DEBUGGING PROGRAM
********************************************
MAIN CSECT
USING MAIN,15
XPRNT HEAD,30
L 7,NUM1
LTR 7,7
BNZ AHEAD
XPRNT OOPS,19
AHEAD M 6,=F'1'
D 6,NUM2
S 7,=F'3'
L 9,NUM3
M 8,=F'1'
DR 8,7
SR 8,8
XDECO 9,VALUE
XPRNT RESULT,29
XPRNT TAIL,21
BR 14
HEAD DC CL30' WE ARE DOING SOME ARITHMETIC.'
OOPS DC CL19' ERROR: NUM1 is 0.'
RESULT DC CL17' THE QUOTIENT IS:'
VALUE DS 12C
TAIL DC CL21' WE ARE DONE FOR NOW.'
NUM1 DC F'18'
NUM2 DC F'5'
NUM3 DC F'62'
END MAIN
/*
//
You will need to fill your KC number and your own name.
When you run the program, it will ABEND.
Questions
- What is the interruption code?
- What is the address of the instruction that would have been executed next if the
ABEND had not occurred?
- What is the instruction length code? What is its name?
- What is the condition code?
- What is the address of the instruction that caused the ABEND?
- What instruction set the value of the condition code?
- What is the object code for the ABENDing instruction?
- What do we find when we decode the object code for the ABENDing instruction?
- What actually caused this ABEND?
Answers
- The interruption code is found in the PSW in hex digits 5 through
9. In this case, the value is "0009". This is a "fixed-point
divide" exception.
- The address of the next instruction is found in the PSW in hex
digits 11 through 16. In this case, the value is X00002C'.
Notice that addresses are written in hexadecimal.
- The instruction length code is found in the PSW in the first 2
bits of the 9th hex digit. In this case, the 9th hex digit is
X'4', or B'0100'. The two bits of the instruction length code
are B'01', or 1 (decimal). That is 1 halfword or 2 bytes.
- The condition code is found in the PSW in the last 2 bits of
the 9th hex digit. In this case, the 9th hex digit is X'4' or
B'0100'. The two bits of the condition code are B'00', or 0
in decimal.
- The instruction that caused the ABEND is the instruction
immediately before the next instruction, so its address is:
address of next instrution - number of bytes in the ABENDing instruction
which is X'00002C' - X'2' = X'00002A'.
- The condition code was set by the most recent instruction that
affects it. Work backwards through the code from the ABENDing
instruction to find it. It is presumably the Subtract instruction
at location X'00001E'.
- To find the object code for the ABENDing instruction, look in
the dump at location X'00002A'. The object code is X'1D87'.
You may be able to find this also in the listing at location
X'00002A', but the value there is what was assembled. It is
possible for some event to change the object code later. (If
that occurs, it usually bad.) We want to know what was stored
at X'00002A' at the time of the ABEND.
- When we decode X'1D87', we find "DR 8,7".
- The ABEND occurred because the program tries to divide by 0.
Notice that Subtract set the condition code to 0 indicating the
result of the operation was 0.