0% found this document useful (0 votes)
45 views

2001PM

This document describes testing of a program that calculates the day of the week for a given date. The program returns either the day of the week or an error code. Test data is shown along with expected results. Questions are asked about the type of testing being done, the test data, and conclusions that can be drawn from the test results.

Uploaded by

camanhvn
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

2001PM

This document describes testing of a program that calculates the day of the week for a given date. The program returns either the day of the week or an error code. Test data is shown along with expected results. Questions are asked about the type of testing being done, the test data, and conclusions that can be drawn from the test results.

Uploaded by

camanhvn
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 35

Q5.

Read the following description concerning program design and then answer sub-questions
1 through 4.

A subprogram that calculates the day of the week for a given date has been created and is
being tested.

[Description of Subprogram]
This subprogram calculates the day of the week for a date (given according to the western
calendar). If there is an error in the date that is entered, the program returns a
corresponding error code.
(1) The date is given in the format “yyyy, mm, dd” (yyyy: four digits for the year (in the
western calendar); mm: two digits for the month; dd: two digits for the day of the
month).
(2) If the date information is valid, the program returns the corresponding day of the
week (SUN, MON, TUE, WED, THU, FRI, SAT).
(3) If the date information is invalid, the program returns, as a return code, an error code
that corresponds to one of the three types of errors described in Table 1.

Table 1 Date Checks and Error Codes


Error code Description of check
The input values are checked to make sure that they are within the allowable
E1
ranges: 1900 to 2299 for the year, 01 to 12 for the month, and 01 to 31 for the day.
If the day is 31, the month is checked to make sure that it is not February, April,
E2 June, September, or November. If the day is 30, the month is checked to make sure
that it is not February.
If the date given is February 29, the year is checked to make sure that it is a leap
E3
year.

2
[Testing the Subprogram]
Based on the description of the subprogram, the test items were set and test data was
created with due consideration given to the boundary values. Table 2 shows the test data
and the expected correct results.

Table 2 Test Data and Expected Correct Results


Test items Test data and results [in the format “(test data; result)”]
Year value (1899,12,31; E1), (1900,01,01; MON), (2299,12,31; SUN), (2300,01,01; E1)
Month value (2001,00,01; E1), , (2001,12,01; WED) , (2001,13,01; E1)
Date value (2001,01,0 ; E1) , (2001,01,01; MON), (2001,01,31; THU), (2001,01,32 ; E1)
Combinations (2001,02,28; WED), (2001,02,30; E2), (2001,02,31; E2), (2001,03,31; SAT),
of months and (2001,04,30; MON), (2001,04,31; E2), (2001,05,31; THU), (2001,06,30; SAT),
days in non-
leap years (2001,06,31; E2), (2001,07,31; TUE), (2001,08,31; FRI), (2001,09,30; SUN),
(2001,09,31; E2), (2001,10,31; WED), (2001,11,30; FRI), (2001,11,31; E2),
(2001,12,31; MON)
February 29 (1996,02,29; THU), (2000,02,29; TUE), (2001,02,29; E3), (2100,02,29; E3)

Note: 1996 and 2000 are leap years, 2001 and 2100 are not leap years.

Sub-question 1
From the answer group below, select the term which describes the type of test that is being
conducted with the test data shown in Table 2.

Answer group:
a) Integration test b) Performance test
c) Endurance test d) Black-box test
e) White-box test

Sub-question 2
From the answer group below, select the correct answer to be inserted in the box
in Table 2.

Answer group:
a) (2001,01,01; MON) b) (2001,01,33; E1) c) (2001,06,01; FRI)
d) (2001,00,99; E1) e) (2002,02,29; E3) f) (2010,13,14; E1)

3
Sub-question 3
When the subprogram was executed using the test data shown in Table 2, the response for
the year 2100 test data in the “February 29” test item was “2100, 02, 29; MON” instead of
the expected correct result indicated by the underlined data in the table. From the answer
group below, select the correct conclusion that we can draw from these results.

Answer group:
a) Because February 29 only comes once every four years, the impact from this problem
is small. Considering the effort that would be required to correct this error in the
program and the possibility that the correction could give rise to new problems, it is
not appropriate to attempt to correct this error.
b) Because the correct response is generated for non-leap years, it is best to change the
underlined test data to a non-leap year so that all of the test results will be correct
without reducing the amount of test data.
c) It is likely that there is an error in the leap year calculation processing. Therefore, to
correct the subprogram, the first step is to check the portion of the code that handles
leap-year processing.
d) Although the number of days varies from month to month, the range of values for the
month is always “1” to “12,” so there was no need to conduct a range test on the
month value.
e) Because the year 2100 is 100 years ahead in the future, there is no need to correct the
sub-program.

4
Sub-question 4
The figure below is a flowchart for calculating the date of the second Monday in October
in a given year (assume the year is 2000 or later) using the debugged subprogram.
From the answer group below, select the correct answers to insert in the boxes .

Fig. Flowchart for Obtaining the Date of the Second Monday in October

Answer group:
a) Day  31?
b) Day ≦ 31?
c) Is the return value an error code?
d) Is the return value “MON”?
e) Is the return value “SUN”, “TUE”, “WED”, “THU”, “FRI” or “SAT”?
f) Is the return value “SUN”, “MON”, “TUE”, “WED”, “THU”, “FRI” or “SAT”?

5
Select one of the following three questions (Q6, Q7, or Q8) to answer. Be sure to mark the
“Select” circle corresponding to the question that you select to answer on your answer sheet.
Note that if you select two or more questions, only the first question that you select will be scored.

Q6. Read the following description of a C program and the program itself, and then answer the
sub-question.

[Program Description]
The function CountColors is a program that scans the image data in a specified
rectangular region that is 320 pixels wide by 240 pixels high and counts the number of
colors that are actually used. A pixel is stored in the following RGB structure:

typedef struct {
unsigned char Red ; /* Red brightness; 256 levels, from 0 to 255 */
unsigned char Green ; /* Green brightness; 256 levels, from 0 to 255 */
unsigned char Blue ; /* Blue brightness; 256 levels, from 0 to 255 */
} RGB ;

The image data is stored in a two-dimensional array of the RGB structures. The definition
of the image data is shown below. The relationship between the image and the coordinate
system is shown in the figure.

RGB Image[ 240 ][ 320 ] ;

Fig. Coordinate System for Image Data

After the image data is loaded into the array Image, the function CountColors is called
with the parameters that indicate the rectangular region in which the colors are to be
counted. The number of colors is then returned by the function as a return value.

6
The prototype for the CountColors function is as follows:
long int CountColors( int sx, int sy, int dx, int dy );
The figure shows the relationship between the parameters and the point coordinates.

[Program]

typedef struct {
unsigned char Red ;
unsigned char Green ;
unsigned char Blue ;
} RGB ;

#define Width 320


#define Height 240
#define TRUE 1
#define FALSE 0

RGB Image[ Height ][ Width ] ;

long int CountColors( int sx, int sy, int dx, int dy )
{
int w, h ;
int px, py ;
long int Colors ;
int Counted[ Height ][ Width ] ;

for( h = sy ; h <= dy ; h++ )


for( w = sx ; w <= dx ; w++ )
Counted[h][w] = FALSE ;

Colors = 0 ;
for( py = sy ; py <= dy ; py++ )
for( px = sx ; px <= dx ; px++ ) {
if ( Counted[py][px] == FALSE ) {
;
Counted[py][px] = TRUE ;

for( h = py ; h <= dy ; h++ )


for( w = ( ) ; w <= dx ; w++ ) {
if ( Counted[h][w] == FALSE ) {
if (( Image[py][px].Red == Image[h][w].Red )
&&( Image[py][px].Green == Image[h][w].Green )
&&( Image[py][px].Blue == Image[h][w].Blue ))
;
}
}
}
}
return Colors ;
}

7
Sub-question
From the answer groups below, select the correct answers to be inserted in the boxes
in the program.

Answer group for “a”:


a) Colors = Counted[py][px] b) Colors = Counted[sy][sx]
c) Colors++ d) Colors
e) Counted[h][w] = FALSE f) Counted[h][w] = TRUE

Answer group for “b”:


a) h == py ? 0 : dx b) h == py ? px + 1 : sx
c) h == py ? sx : px + 1 d) h == sy ? 0 : dx + 1
e) h == sy ? sx : px + 1

Answer group for “c”:


a) Counted[dy][dx] = FALSE b) Counted[dy][dx] = TRUE
c) Counted[h][w] = FALSE d) Counted[h][w] = TRUE
e) Counted[py][px] = FALSE f) Counted[py][px] = TRUE
g) Counted[sy][sx] = FALSE h) Counted[sy][sx] = TRUE

8
Q7. Read the following description of a COBOL program and the program itself, and then
answer sub-questions 1 and 2.

[Program Description]
A manufacturer selects suppliers of each of the materials required for production and
manage the suppliers with a supplier-by-material file. Consider the process to delete from
this file those suppliers with whom the company is no longer dealing.

(1) The format of records in the supplier-by-material file is shown below:


Material code Supplier count Supplier code
6 digits 1 digit 4 digits  4 digits

The file is an indexed file that uses the material code as a key.
The supplier count stores the number of suppliers registered in the file.
Up to five supplier codes (or no codes) are registered for each material code.
Supplier codes are registered starting from the first field; a space is stored in any field in
which no supplier code is registered.

(2) The format of records in the deletion instruction file is shown below:
Material code Supplier code
6 digits 4 digits

The program reads from the material-supplier file the record which corresponds to the
material code, deletes the corresponding supplier code, and reduces the supplier count by
one.
As part of the deletion processing, the program alters the supplier-by-material file so that
item under (1) above may be satisfied.
Assume that all of the data in the deletion instruction file is correct.

9
[Program]

(Line No.)
1 DATA DIVISION.
2 FILE SECTION.
3 FD SUPPLIER.
4 01 ORDER-R.
5 03 O-MATERIAL PIC X(6).
6 03 O-COUNT PIC 9.
7 03 O-TABLE.
8 05 O-ORDER OCCURS 5 PIC X(4).
9 FD INSTRUCT.
10 01 INSTRUCT-R.
11 03 I-MATERIAL PIC X(6).
12 03 I-ORDER PIC X(4).
13 WORKING-STORAGE SECTION.
14 01 END-SW PIC X VALUE SPACE.
15 01 CNT PIC 9.
16 01 W-CNT PIC 9.
17 PROCEDURE DIVISION.
18 START.
19 OPEN INPUT INSTRUCT I-O SUPPLIER.
20 PERFORM UNTIL END-SW = "Z"
21 READ INSTRUCT AT END MOVE "Z" TO END-SW END-READ
22 IF END-SW = SPACE
23 MOVE I-MATERIAL TO O-MATERIAL
24 READ SUPPLIER
25 INVALID DISPLAY "READ-ERROR I-MATERIAL = ", I-MATERIAL
26 NOT INVALID PERFORM SEARCH
27 PERFORM D-RTN
28 END-READ
29 END-IF
30 END-PERFORM.
31 CLOSE INSTRUCT SUPPLIER.
32 STOP RUN.
33 SEARCH.
34 PERFORM VARYING CNT FROM 1 BY 1 UNTIL
35 CONTINUE
36 END-PERFORM.
37 D-RTN.
38 PERFORM UNTIL CNT = O-COUNT
39 COMPUTE W-CNT = CNT + 1
40 MOVE O-ORDER(W-CNT) TO O-ORDER(CNT)
41 COMPUTE CNT = CNT + 1
42 END-PERFORM.
43 MOVE SPACE TO O-ORDER(O-COUNT).
44 COMPUTE O-COUNT = O-COUNT  1.
45 REWRITE ORDER-R
46 INVALID DISPLAY "REWRITE-ERROR", O-MATERIAL, I-ORDER.

10
Sub-question 1
From the answer group below, select the correct answer to insert in the box in
the program.

Answer group:
a) I-ORDER = O-ORDER(CNT)
b) I-ORDER = O-ORDER(O-COUNT)
c) I-MATERIAL = O-MATERIAL

Sub-question 2
Lines 38 to 42 in the program are being changed to avoid repetition. From the answer
groups below, select the correct answers to insert in the boxes in the modified
code below.
Note that W1, W2, and W3 are all defined as two-digit work areas, and W-TABLE is defined
as a 20 (alphanumeric)-character item.

IF CNT NOT = O-COUNT


MOVE O-TABLE TO W-TABLE
COMPUTE W1 =
COMPUTE W2 =
COMPUTE W3 =
MOVE W-TABLE(W1:W3) TO O-TABLE(W2:W3)
END-IF.

Answer group:
a) CNT * 4  1 b) CNT * 4 + 1
c) (CNT  1) * 4  1 d) (CNT  1) * 4 + 1
e) (CNT + 1) * 4  1 f) (CNT + 1) * 4 + 1
g) (O-COUNT  1) * 4 + 1 h) (O-COUNT  CNT) * 4  1
i) (O-COUNT  CNT) * 4 j) (O-COUNT  CNT) * 4 + 1

11
Q8. Read the following description of an assembler program and the program itself, and then
answer sub-questions 1 and 2.

[Program Description]
“n” consecutive words are regarded as a bit string consisting of 16  n bits. The sub-
program SHIFT shifts this bit string right by m positions.

Fig. 1 Processes by the Subprogram SHIFT

(1) The main program stores the following values in GR1 through GR3, respectively, and
then passes these values to SHIFT.
GR1 : Address of the first word of the bit string
GR2 : m
GR3 : n
(2) Assume that 1 ≦ n ≦ 32767 and that 0 ≦ m ≦16.
(3) The shifted bit string is stored in the original area.
(4) “0” is stored in the empty bit positions before the left end of the string. The bits
removed from the right side of the register are discarded.
(5) The functions of the RPUSH and RPOP macro instructions used in the program are as
described below:
RPUSH : Saves the contents of GR1 through GR7 into the stack.
RPOP : Restores the contents of the stack into GR1 through GR7.

12
[Program]

(Line No.)
1 SHIFT START ;
2 RPUSH ; Save registers
3 ;
4 SUBA GR4,GR2 ; (16m)GR4
5 LAD GR5,0 ; ‘0’ bit string to be stored at the left end
6 LOOP SLL GR5,0,GR4 ; Move to the left end the remaining bit string from
the previous word
7 LD GR0,0,GR1 ; The bit string in the current wordGR0
8 ;
9 OR GR0,GR5 ; Catenate the left-over bit string
10 LD GR5,0,GR1 ; Save bit string in current word into GR5
11 ST GR0,0,GR1 ; Store catenated bit strings into the current word
12 LAD GR1,1,GR1 ; Obtain the address of the next word
13 SUBA GR3,=1 ;
14 ;
15 RPOP ; Restore registers
16 RET ;
17 END ;

Sub-question 1
From the answer groups below, select the correct answer to insert in the boxes
in the program.

Answer group for “a”:


a) AND GR4,=16 b) LAD GR4,16
c) LD GR4,16 d) OR GR4,=16

Answer group for “b”:


a) SLL GR0,0,GR2 b) SLL GR0,0,GR4
c) SRL GR0,0,GR2 d) SRL GR0,0,GR4

Answer group for “c”:


a) JMI LOOP b) JOV LOOP
c) JPL LOOP d) JZE LOOP

13
Sub-question 2
The LAD instruction in line 5 has been replaced with the following three instructions in
order to store the bit substring removed from the right end in the open bit positions at the
left end of the string, as shown in Fig. 2. From the answer group below, select the correct
answer to insert in the box below.

LD GR5,GR1
ADDL GR5,GR3

Fig. 2 The removed bit substring is stored on the left side.

Answer group:
a) LD GR5,1,GR5 b) LD GR5,0,GR5 c) LD GR5,1,GR5
d) ST GR5,1,GR1 e) ST GR5,0,GR1 f) ST GR5,1,GR1

14
Select one of the following three questions (Q9, Q10, or Q11) to answer. Be sure to mark the
“Select” circle corresponding to the question that you select to answer on your answer sheet.
Note that if you select two or more questions, only the first question that you select will be scored.

Q9. Read the following description of a C program and the program itself, and then answer
sub-questions 1 through 4.

[Program Description]
A function DrawCurve was created to draws a free curve between point S at coordinates
(sx, sy) and point E at coordinates (ex, ey) on the screen through approximation by using a
sequence of minute line segments. In order to determine the shape of the curve, two
control points are specified as parameters: C1 at coordinates (x1, y1) and C2 at coordinates
(x2, y2). The polygonal curve that is formed by the four points given as shown in the
figure is then divided recursively, and the final series of straight line segments are drawn
when the convergent condition determined by the parameter len (len > 2) is met.

(The enlarged dots  are intended as a symbol that indicates the coordinates of a point,

and are not drawn by the program).

Fig. Coordinates of the Four Points Given

The prototype for the function DrawCurve is as follows:


void DrawCurve( int sx, int sy, int x1, int y1, int x2, int y2,
int ex, int ey, int len ) ;
The relationship between the parameters and the point coordinates is shown in the figure.

15
The following two functions are provided for the purpose of drawing straight segment that
connect two points:

void MoveTo( int sx, int sy ) ;


Function: Sets the coordinates (sx, sy) as the starting point for drawing a straight line
segment.

void LineTo( int ex, int ey ) ;


Function: Draws a straight line segment from the current starting point to the coordinates
(ex, ey), and then updates the starting point to the coordinates (ex, ey).

[Program]
void MoveTo( int sx, int sy ) ;
void LineTo( int ex, int ey ) ;
int CmpLine( int xs, int ys, int xe, int ye, int len ) ;
void DrawCurve( int sx, int sy, int x1, int y1, int x2, int y2,
int ex, int ey, int len )
{
int p1x, p1y, p2x, p2y, p3x, p3y ;
int p4x, p4y, p5x, p5y, p6x, p6y ;
if ( CmpLine( sx, sy, x1, y1, len ) &&
CmpLine( x1, y1, x2, y2, len ) &&
CmpLine( x2, y2, ex, ey, len ) ) {
MoveTo( sx, sy ) ; LineTo( x1, y1 ) ;
LineTo( x2, y2 ) ; LineTo( ex, ey ) ;
return ;
}
p1x = ( sx + x1 ) / 2 ; p1y = ( sy + y1 ) / 2 ;
p2x = ( x1 + x2 ) / 2 ; p2y = ( y1 + y2 ) / 2 ;
p3x = ( x2 + ex ) / 2 ; p3y = ( y2 + ey ) / 2 ;
p4x = ( p1x + p2x ) / 2 ; p4y = ( p1y + p2y ) / 2 ;
p5x = ( p2x + p3x ) / 2 ; p5y = ( p2y + p3y ) / 2 ;
p6x = ( p4x + p5x ) / 2 ; p6y = ( p4y + p5y ) / 2 ;
DrawCurve( sx, sy, p1x, p1y, p4x, p4y, p6x, p6y, len ) ;
DrawCurve( p6x, p6y, p5x, p5y, p3x, p3y, ex, ey, len ) ;
return ;
}
int CmpLine( int xs, int ys, int xe, int ye, int len )
{
int len1 = xe  xs ;
int len2 = ye  ys ;
if ( len1 < 0 ) len1 = len1 ;
if ( len2 < 0 ) len2 = len2 ;
if ( ( len1 < len ) && ( len2 < len ) )
return 1 ;
return 0 ;
16
}

17
Sub-question 1
In order to divide a polygonal curve into two, it calculates the coordinates of the midpoints
of three line segments, and then calculates the coordinates of the midpoints of additional
line segments. From the answer group below, select the figure that illustrates the method
for determining the four vertices of the new polygonal curve.

Answer group:

a) b)

  

c) d)

  

18
Sub-question 2
From the answer group below, select the correct condition for ending the recursive division
processing.

Answer group:
a) When each of the three line segments of the polygonal curve becomes longer than the
length given by the parameter len.
b) When each of the three line segments of the polygonal curve becomes shorter than the
length given by the parameter len.
c) When each of the three line segments of the polygonal curve becomes short enough to
fit within a square with sides of the length given by the parameter len.
d) When one of the three line segments of the polygonal curve becomes longer than the
length given by the parameter len.
e) When one of the three line segments of the polygonal curve becomes shorter than the
length given by the parameter len.
f) When one of the three line segments of the polygonal curve becomes short enough to
fit within a square with sides of the length given by the parameter len.

19
Sub-question 3
From the answer group below, select the correct responses to insert in the boxes
in the following description of the characteristics of this program.

In case a free curve was drawn with a value of “8” for the parameter len, a

caused the function LineTo (which draws straight lines) to be called the largest number
of times.
If the same curve were drawn with a value of “16” specified for the parameter len, the
number of times the function LineTo was called would be the number of times
the function LineTo was called when the value of Len is “8.”

Answer group for “a”:

a) b)

c) d)

Answer group for “b”:


a) greater than b) equal to c) less than

20
Sub-question 4
From the answer group below, select the figure that correctly shows the results produced
by executing the following program.

int Lines ;
int cx1, cy1 ;
int cx2, cy2 ;

for ( Lines = 0, cx1 = 128, cy1 = 160, cx2 = 256, cy2 = 160 ;
Lines < 16 ;
Lines++, cx1 += 16, cy1 = 16, cx2 = 16, cy2 += 16 ) {
DrawCurve( 50, 160, cx1, cy1, cx2, cy2, 384, 160, 8 ) ;
}

Answer group:

a) b)

c) d)

21
Q10. Read the following description of a COBOL program and the program itself, and then
answer the sub-question.

[Program Description]
Assume that there is a seminar application file in which applications for seminars are
registered. Each individual can apply only once for a seminar, but can apply for up to 10
different seminars. This program flags as an error any application that requests more than
one seminar held on the same day, and then prints an error listing.
(1) The record format in the seminar application file is shown below.

Assume that the same seminar number will not be specified more than once.
The seminars being applied for are listed sequentially, starting from field 1; if there are
fewer than ten seminars requested, the remaining fields are left empty.
Assume that the seminar numbers are stored in the seminar schedule file.
(2) The record format in the seminar schedule file, in which the details of each seminar
are registered, is as follows.
Seminar number Scheduled date Room number
4 digits 8 digits 10 digits

This file is an indexed file, using the seminar number as the key.
All the seminars that are to be held are registered.
(3) The following is an example of the table CHK-TBL that is used by this program to
check each application for multiple seminars being held on the same day.

Example: Assume that the following data from the seminar application file and from
the seminar schedule file has been provided.

Data from the seminar application file

Data from the seminar schedule file


A001 20010411 TORAN-F801
B002 20010412 TORAN-F801
C003 20010411 TORAN-F802

22
In this case, the contents of the table CHK-TBL are shown below.

As a result, it is clear that the shaded entries in the table CHK-SEM-NO, A001
and C003, are held on the same day.
(4) The printing format for the error listing is shown below.
Application Applicant Scheduled Seminar
No. No. date No.
XXXXX XXXXX XXXXXXXX XXXX XXXX XXXX  XXXX
XXXXXXXX XXXX XXXX XXXX  XXXX
XXXXX XXXXX XXXXXXXX XXXX XXXX XXXX  XXXX
 ・
・    ・  
 ・    ・ 
XXXXX XXXXX XXXXXXXX XXXX XXXX XXXX  XXXX
XXXXX XXXXX XXXXXXXX XXXX XXXX XXXX  XXXX

The headings are pre-printed.


If one application number contains multiple seminars that are held on the same day, all of
those seminar numbers are printed on one line.
If there are multiple groups of seminars for which  applies under one application number,
the seminars for each day are printed on separate lines. In this case, the application number
and the applicant number are printed on the first line, but not on the subsequent lines.

23
[Program]

DATA DIVISION.
FILE SECTION.
FD APPLY-FILE.
01 APPLY-REC.
02 APP-NO PIC X(05).
02 APP-PSN-NO PIC X(05).
02 APP-SEM-NO OCCURS 10 PIC X(04).
FD SEMINAR-FILE.
01 SEMINAR-REC.
02 SEM-NO PIC X(04).
02 SEM-YMD PIC X(08).
02 SEM-ROOM PIC X(10).
FD CHECK-FILE.
01 CHECK-REC PIC X(85).
WORKING-STORAGE SECTION.
01 INFILE-EOF PIC 9(01) VALUE 0.
01 PRINT-WRK.
02 PRI-NO PIC X(05).
02 PIC X(05).
02 PRI-PSN-NO PIC X(05).
02 PIC X(07).
02 PRI-YMD PIC X(08).
02 PIC X(01).
02 OCCURS 10.
03 PIC X(01).
03 PRI-SEM-NO PIC X(04).
01 CHK-TBL.
02 OCCURS 10.
03 CHK-NUM PIC 9(02).
03 CHK-YMD PIC X(08).
03 CHK-SEM-NO OCCURS 10 PIC X(04).
01 CHK-CNT PIC 9(02).
01 CHK-WK PIC 9(02).
01 CNT1 PIC 9(02).
01 CNT2 PIC 9(02).
01 CNT3 PIC 9(02).
PROCEDURE DIVISION.
MAIN-RTN.
OPEN INPUT APPLY-FILE SEMINAR-FILE OUTPUT CHECK-FILE.
PERFORM UNTIL INFILE-EOF = 1
READ APPLY-FILE AT END
MOVE 1 TO INFILE-EOF
NOT AT END
PERFORM CHECK-RTN
PERFORM PRINT-RTN
END-READ
END-PERFORM.
CLOSE APPLY-FILE SEMINAR-FILE CHECK-FILE.
STOP RUN.

24
CHECK-RTN.
INITIALIZE CHK-TBL CHK-CNT.
PERFORM VARYING CNT1 FROM 1 BY 1 UNTIL CNT1 > 10
OR APP-SEM-NO (CNT1) = SPACE

READ SEMINAR-FILE INVALID KEY


DISPLAY “SEMINAR NUMBER ERROR”
NOT INVALID KEY
PERFORM TABLE-SET-RTN
END-READ
END-PERFORM.
TABLE-SET-RTN.
MOVE 0 TO CNT3.
PERFORM VARYING CNT2 FROM 1 BY 1 UNTIL
IF SEM-YMD = CHK-YMD (CNT2) THEN

END-IF
END-PERFORM.
IF CNT3 = 0 THEN
COMPUTE CHK-CNT = CHK-CNT + 1
MOVE SEM-YMD TO CHK-YMD (CHK-CNT)
MOVE CHK-CNT TO CNT3
END-IF.
COMPUTE CHK-NUM (CNT3) = CHK-NUM (CNT3) + 1.
MOVE CHK-NUM (CNT3) TO CHK-WK.
MOVE APP-SEM-NO (CNT1) TO CHK-SEM-NO (CNT3 CHK-WK).
PRINT-RTN.
MOVE 0 TO CNT3.
PERFORM VARYING CNT1 FROM 1 BY 1 UNTIL
MOVE SPACE TO PRINT-WRK
IF THEN
IF CNT3 = 0 THEN
MOVE APP-NO TO PRI-NO
MOVE APP-PSN-NO TO PRI-PSN-NO
MOVE 1 TO CNT3
END-IF
MOVE CHK-YMD (CNT1) TO PRI-YMD
PERFORM VARYING CNT2 FROM 1 BY 1
UNTIL CNT2 > CHK-NUM (CNT1)

END-PERFORM
WRITE CHECK-REC FROM PRINT-WRK AFTER 1
END-IF
END-PERFORM.

25
Sub-question
From the answer groups below, select the correct answers to be inserted in the boxes
in the program.

Answer group for “a” and “c”:


a) MOVE CNT1 TO CNT2 b) MOVE CNT1 TO SEM-NO
c) MOVE CNT2 TO CNT1 d) MOVE CNT2 TO CNT3
e) MOVE CNT2 TO SEM-NO f) MOVE CNT3 TO CNT1
g) MOVE CNT3 TO CNT2 h) MOVE APP-SEM-NO TO CNT1
i) MOVE SEM-NO TO PRI-SEM-NO (CNT1)
j) MOVE APP-SEM-NO (CNT1) TO SEM-NO

Answer group for “b” and “d”:


a) CHK-CNT > CNT1 b) CHK-CNT > CNT2
c) CHK-CNT > CNT3 d) CHK-NUM (CNT1) > CNT2
e) CHK-NUM (CNT2) > CNT3 f) CNT1 > CHK-CNT
g) CNT2 > CHK-CNT h) CNT2 > CHK-NUM (CNT1)
i) CNT3 > CHK-CNT j) CNT3 > CHK-NUM (CNT2)

Answer group for “e”:


a) CHK-NUM (CNT1) > 1 b) CHK-NUM (CNT1) > CNT1
c) CHK-NUM (CNT3) > 1 d) CHK-NUM (CNT3) > CNT3
e) CNT1 > 1 f) CNT3 > 1

Answer group for “f”:


a) MOVE CHK-SEM-NO (CNT1 CNT2) TO PRI-SEM-NO (CNT1)
b) MOVE CHK-SEM-NO (CNT1 CNT2) TO PRI-SEM-NO (CNT2)
c) MOVE CHK-SEM-NO (CNT1 CNT3) TO PRI-SEM-NO (CNT3)
d) MOVE CHK-SEM-NO (CNT2 CNT1) TO PRI-SEM-NO (CNT1)
e) MOVE CHK-SEM-NO (CNT2 CNT1) TO PRI-SEM-NO (CNT2)
f) MOVE CHK-SEM-NO (CNT2 CNT3) TO PRI-SEM-NO (CNT2)

26
Q11. Read the following description of an assembler program and the program itself, and then
answer sub-questions 1 and 2.

[Program Description]
This is a subprogram group that manages reserved seats in a movie theater. The movie
theater has 1,024 reserved seats, numbered from 0 to 1023. The subprograms include
INIT, which initializes the seat reservation table RSVTBL; RESERVE, which reserves a
seat; and CANCEL, which cancels a reserved seat. The structure of the seat reservation
table, which stores the status of each reserved seat, is shown in the figure below.

Fig. Seat Reservation Table RSVTBL

(1) The subprogram INIT sets all of the bits in the seat reservation table to the
“available” state.
(2) The subprogram RESERVE reserves one seat. The subprogram searches through the
seats, starting from seat 0, until it finds an “available” seat, and then changes the
status of that seat to “reserved” and stores the seat number in GR0. If all of the seats
are already reserved, the subprogram stores the value “1” in GR0.
(3) The subprogram CANCEL cancels the reservation of the seat number that is specified
by GR1. After confirming that the status of the specified seat is “reserved,” the
subprogram changes the status to “available.” If the cancellation processing ends
normally, the subprogram stores the value “0” in GR0. If there is an error in the seat
number specification, or if the seat specified by the seat number is already in the
“available” state, the subprogram stores the value “1” in GR0.
(4) Except for GR0, the contents of all the general-purpose registers that are used by the
subprograms are saved.
(5) The functions of the RPUSH and RPOP macro instructions used in the program are as
described below:
RPUSH : Saves the contents of GR1 through GR7 into the stack.
RPOP : Restores the contents of the stack into GR1 through GR7.
27
[Program]

MAIN START
·
·
·

; Initializes the seat reservation table


INIT PUSH 0,GR1
LD GR1,RSVTBLSZ
LAD GR0,0
CLEARP LAD GR1,1,GR1
; 0  RSVTBL
LD GR1,GR1
JNZ CLEARP
POP GR1
RET
; Reserves a seat
RESERVE RPUSH
LAD GR2,0
LD GR0,GR2
RSV01 LD GR1,RSVTBL,GR2
; Are 16 seats all reserved?
JZE RSV03
LAD GR3,#8000
RSV02 LD GR4,GR1
AND GR4,GR3 ; Checks reservation status of each seat
JZE RSV04
ADDL GR0,=1
; Prepares for next seat
JUMP RSV02
RSV03 ADDL GR0,=16
LAD GR2,1,GR2
CPL GR2,RSVTBLSZ
JNZ RSV01
; No available seats
JUMP RRET
RSV04 OR GR1,GR3
ST GR1,RSVTBL,GR2
RRET RPOP
RET
; Cancels a reserved seat
CANCEL RPUSH
LD GR2,GR1
; Determines word position
CPL GR1,RSVTBLSZ
JPL CERROR
JZE CERROR
LAD GR1,RSVTBL,GR1
AND GR2,=#000F
LAD GR3,#8000
SRL GR3,0,GR2 ; Determines bit position
LD GR0,0,GR1

28
AND GR0,GR3
JZE CERROR
; Inverts the bits
LD GR0,0,GR1
AND GR0,GR3
ST GR0,0,GR1
LAD GR0,0
JUMP CRET
CERROR LAD GR0,1
CRET RPOP
RET
;
RSVTBLSZ DC 64 ; Size of reservation table
RSVTBL DS 64 ; Reservation table
END

Sub-question 1
From the answer groups below, select the correct answers to be inserted in the boxes
in the program.

Answer group for “a”:


a) ST GR0,0,GR1 b) ST GR0,RSVTBL,GR1
c) ST GR1,0,GR1 d) ST GR1,RSVTBL,GR1
e) ST GR2,0,GR1 f) ST GR2,RSVTBL,GR1

Answer group for “b”:


a) CPL GR0,1 b) CPL GR0,=0 c) CPL GR0,=#FFFF
d) CPL GR1,1 e) CPL GR1,=0 f) CPL GR1,=#FFFF

Answer group for “c” and “e”:


a) SLL GR1,1 b) SLL GR1,4 c) SLL GR3,1
d) SLL GR3,4 e) SRL GR1,1 f) SRL GR1,4
g) SRL GR3,1 h) SRL GR3,4

Answer group for “d”:


a) LAD GR0,1 b) LAD GR1,1 c) LD GR0,1
d) LD GR1,1

Answer group for “f”:


a) AND GR3,1 b) AND GR3,=#FFFF c) OR GR3,1
d) OR GR3,=#FFFF e) XOR GR3,1 f) XOR GR3,=#FFFF

29
Sub-question 2
The locations labeled  and  in the program are changed as shown below. From the
answer group below, select the maximum number of reserved seats that can be handled by
this program as a result of this change.

RSVTBLSZ DC 120 ; Size of reservation table


RSVTBL DS 120 ; Reservation table

Answer group:
a) 960 b) 1,440 c) 1,920
d) 2,400 e) 2,880

30
Assembly Language Specifications

1. COMET II Hardware Specifications


1.1 Hardware Specifications
(1) One word is 16 bits, and the bit format is as follows:

(2) Main storage capacity is 65,536 words with address numbers 0 through 65,535.
(3) Numeric values are expressed as 16-bit binary numbers. Negative numbers are expressed in complements of two.
(4) Control is sequential. COMET II utilizes a one-word or two-word instruction word.
(5) The COMET II has four types of registers: GR (16 bits), SP (16 bits), PR (16 bits) and FR (3 bits).
There are eight GR (General Register) registers, GR0 through GR7. These eight registers are used for arithmetic, logical, compare and shift
operations. Of these, GR1 through GR7 are also used as index registers to modify addresses.
The stack pointer stores the address currently at the top of the stack.
The PR (Program Register) stores the first address of the next instruction.
The FR (Flag Register) consists of three bits: OF (Overflow Flag), SF (Sign Flag) and ZF (Zero Flag). The following values are set,
depending on the result generated by certain operation instructions. These values are referenced by conditional branch instructions.

When the result of an arithmetic operation instruction is out of the range of –32,768 to 32,767, the value is 1,
OF
and in other cases, the value is 0. When the result of a logical operation instruction is out of the range of 0 to

65,535, the value is 1, and in other cases, the value is 0.

SF When the sign of the operation result is negative (bit number 15 = 1), the value is 1, and in other cases, the

value is 0.

ZF When the operation result is 0 (all bits are 0), the value is 1, and in other cases, the value is 0.
(6) Logical addition or logical subtraction: Treats the data to be added or subtracted as unsigned data, and performs addition or subtraction.

1.2 Instructions
Formats and functions of instructions are described in the following chart. When an instruction code has two types of operands, the upper
operand shows the instruction between registers and the lower operand shows the instruction between register and main storage.
Instruction Format FR
Description of instructions
Opcode Operand setting
(1) Load, store, load address instruction
r1,r2 r1 ← (r2)
LoaD LD *1
r,adr [,x] r ← (effective address)
STore ST r,adr [,x] Effective address ← (r)

Load ADdress LAD r,adr [,x] r ← effective address
(2) Arithmetic and logical operation instructions
r1,r2 r1 ← (r1) + (r2)
ADD Arithmetic ADDA
r,adr [,x] r ← (r) + (effective address)
r1,r2 r1 ← (r1) +L (r2)
ADD Logical ADDL
r,adr [,x] r ← (r) +L (effective address)

r1,r2 r1 ← (r1)  (r2)
SUBtract Arithmetic SUBA
r,adr [,x] r ← (r)  (effective address)
r1,r2 r1 ← (r1) L (r2)
SUBtract Logical SUBL
r,adr [,x] r ← (r) L (effective address)
r1,r2 r1 ← (r1) AND (r2)
AND AND
r,adr [,x] r ← (r) AND (effective address)
r1,r2 r1 ← (r1) OR (r2)
OR OR *1
r,adr [,x] r ← (r) OR (effective address)
r1,r2 r1 ← (r1) XOR (r2)
eXclusive OR XOR
r,adr [,x] r ← (r) XOR (effective address)

31
(3) Compare operation instructions
Performs an arithmetic compare or logical
r1,r2 compare operation on (r1) and (r2) or (r) and
(effective address), and sets FR as follows,
ComPare Arithmetic CPA according to the result of the compare operation.
r,adr [,x]

*1
r1,r2

ComPare Logical CPL


r,adr [,x]

(4) Shift operation instructions


Shifts (r) (excluding the sign bit) left or right by
the number of bits specified by the effective
Shift Left Arithmetic SLA r,adr [,x]
address.
When a left shift is performed, those bits that are
left vacant by the shift operation are filled with
zeroes. When a right shift is performed, those
Shift Right Arithmetic SRA r,adr [,x]
bits that are left vacant by the shift operation are *2
filled with the same value as the sign bit.
Shifts (r) (including the sign bit) left or right by
Shift Left Logical SLL r,adr [,x] the number of bits specified by the effective
address.
Shift Right Logical SRL r,adr [,x] Those bits that are left vacant by the shift
operation are filled with zeroes.
(5) Branch instructions
Branches to the effective address, depending on
Jump on PLus JPL adr [,x] the value of FR. If control does not branch to a
new address, execution continues with the next
Jump on MInus JMI adr [,x] instruction.

Jump on Non Zero JNZ adr [,x]



Jump on ZEro JZE adr [,x]

Jump on OVerflow JOV adr [,x]

Branches unconditionally to the effective


unconditional JUMP JUMP adr [,x]
address.
(6) Stack operation instructions
SP ← (SP) L 1,
PUSH PUSH adr [,x]
(SP) ← effective address

r ← ((SP)),
POP POP r
SP ← (SP) +L 1
(7) Call and return instructions
SP ← (SP) L 1,
CALL subroutine CALL adr [,x]
(SP) ← (PR),

PR ← effective address
PR ← ((SP)),
RETurn from subroutine RET
SP ← (SP) +L 1
(8) Other

32
Determine based on the effective address as the
SuperVisor Call SVC adr [,x] argument. After the execution, GR and FR are
undefined. 
No OPeration NOP N/A

(Note) r, r1, r2 All of these represent GR. Values from GR0 to GR7 can be specified.

adr This represents the address. A value from 0 to 65,535 can be specified.

x This represents GR used as the index register. A value from GR1 to GR7 can be specified.

[ ] Square brackets ([ ]) indicate that the specification contained in the brackets may be

omitted.

( ) The contents of the register or address contained in the parentheses ( ).

Effective A value produced by adding, through "logical addition," adr and the contents of x, or the

address address pointed at by that value.

← This means that the operation result is stored in the left part register or address.
+L, L Logical addition and logical subtraction.

Effective  : Setting is performed.

address for FR *1 : Setting is performed, but 0 is set to OF.

setting *2 : Setting is performed, but the bit value sent from the register is set to OF.

 : The value before execution is stored.

1.3 Character Set 02 03 04 05 06 07


(1) A JIS X0201 Romaji/katakana character set that uses 8-bit codes is used. 0Column Space 0 @ P ` p
(2) Part of the character set is shown in the right table. Eight bits are used to represent one 1 ! 1 A Q a q
character; the upper four bits indicate the column in the table, and the lower four bits 2 ” 2 B R b r
indicate the row. For example, the hexadecimal codes for the space character, "4," "H," and 3 # 3 C S c s
"\" are 20, 34, 48 and 5C, respectively. The characters that correspond to the hexadecimal
codes 21 to 7E (and A1 to DF omitted in this table) are called "graphics characters."
4 $ 4 D T d t
Graphics characters can be displayed (printed) as characters on an output device. 5 % 5 E U e u
(3) If any characters not listed in this table and the bit configuration for those characters are 6 & 6 F V f v
needed, they are given in the problem. 7 ' 7 G W g w
8 ( 8 H X h x
2 Specifications of the CASL II Assembly Language
2.1 Specifications of the language 9 ) 9 I Y i y
(1) CASL II is an assembly language for the COMET II. 10 * : J Z j z
(2) A program consists of instruction lines and comment lines. 11 + ; K [ k {
(3) One instruction is described in one instruction line, and cannot continue to the next 12 , < L \ l |
line. 13 - = M ] m }
(4) Instruction lines and comment lines are written from the first character of the line in the ^ ~
following description formats:
14 . > N n
15 / ? O _ o

Line type Description format

Instruction With operand [label]{blank}{instruction code}{blank}{operand}[{blank}[comment]]

line Without operand [label]{blank}{instruction code}[{blank}[{;}[comment] ] ]

Comment line [blank]{;}[comment]

(Note) [ ] Square brackets ([ ]) indicate that the specification contained in the brackets may be omitted.

{ } Braces ({ }) indicate that the specification contained in the braces is mandatory.


Label is the name used to refer to the address of (the first word of) the instruction from other
Label
instructions and programs. A label must be 1 to 8 characters in length, and the leading character must
be an uppercase alphabetic letter. Either uppercase alphabetic letters or numeric characters can be used
for the subsequent characters. Reserved words, GR0 through GR7, are not available.

Blank One or more space characters.

33
Instruction
The description format is defined by instruction.
code

Operand The description format is defined by instruction.


Optional information such as memorandums that can be written in any characters allowed by the
Comment
processing system.

34
2.2 Instruction Types
CASL II consists of four assembler instructions (START, END, DS and DC), two macro instructions (IN and OUT) and machine language
instructions (COMET II instructions). The specifications are as follows:

Instruction type Label Instruction code Operand Function


Defines the top of a program.

Label START [Execution start address] Defines the starting address for execution of a
program.
Assembler
Defines the entry name for reference in other
instruction
programs.
END Defines the end of a program.
[label] DS Word length Allocates an area.
[label] DC Constant[, constant] Defines a constant.
[label] IN Input area, input Input character data from input devices.
Macro instruction
character length area
[label] OUT Output area, output Output character data from output devices.
character length area
Machine language [label] (See "1.2 Instructions")
instruction

2.3 Assembler Instructions


Assembler instructions are used for assembler control, etc.

(1) START [Execution start address]


The START instruction defines the top of a program.
The label name that is defined within this program specifies the execution start address. If the label is specified, execution begins from the
address, and if the label is omitted, execution begins from the next instruction of the START instruction.
The label for this instruction can be referred to from other programs as the entry name.

(2) END
The END instruction defines the end of a program.

(3) DS Word length


The DS instruction allocates an area of the specified word length.
The word length is specified by a decimal constant ( 0). If "0" is specified for the word length of an area, the area is not allocated, but the
label is valid.

(4) DC Constant[, constant] 


The DC instruction stores the data that has been specified as a constant in (consecutive) words.
There are four types of constants: decimal constants, hexadecimal constants, character constants and address constants.

Type of constant Format Description of instruction


Decimal This instruction stores the decimal value specified by "n" as one word of binary data. If "n" is
n
constant outside of the range of –32,768 to 32,767, only the lower 16 bits of n are stored.
Assume "h" is a four-digit hexadecimal number. (Hexadecimal notation uses 0 through 9 and
Hexadecimal
#h A through F.) This instruction stores the hexadecimal value specified by "h" as one word of
constant
binary data. (0000  h  FFFF)
This instruction allocates a continuous area for the number of characters (> 0) in the character
string. The first character is stored in bits 8 through 15 of the first word, the second character is
Character 'character stored in bits 8 through 15 of the second word, and so on, so that the character data is stored
constant string' sequentially in memory. Bits 0 through 7 of each word are filled with zeroes.
Spaces and any of the graphics characters can be written in a character string. Apostrophes (')
must be written twice consecutively.
Address constant Label This instruction stores an address corresponding to the label name as one word of binary data.

35
2.4 Macro Instructions
Macro instructions use a pre-defined group of instructions and operand data to generate a group of instructions that performs a desired
function (the word length is undefined).

(1) IN Input area, input character length area


The IN instruction reads one record of character data from a previously assigned input device.
The input area operand should be the label of a 256-word work area, and the input data is input in this area beginning at the starting address,
one character per word. No record delimiter code (such as a line return code, when using a keyboard) is stored. The storage format is the same
as character constants with the DC instruction. If the input data is less than 256 characters long, the previous data is left as is in the remaining
portion of the input area. If the input data exceeds 256 characters, the excess characters are ignored.
The input character length area should be the label of the one-word work area, and the character length that was input (  0) is stored as binary
data. If the end-of-file indicator is encountered, -1 is stored.
When the IN instruction is executed, the contents of GR registers are saved but the contents of FR are undefined.
Output area, output character length area
(2) OUT
The OUT instruction writes character data as one record of data to the previously assigned output device.
The output area operand should be the label of the area where the data to be output is stored, one character per word. The storage format is
the same as character constants with the DC instruction. Bits 0 through 7 do not have to be zeroes because the OS ignores them.
The output character length area should be the label of the one-word work area, and the character length that is to be output ( 0) is stored as
binary data.
When the OUT instruction is executed, the contents of the GR registers are saved but the contents of FR are undefined.

2.5 Machine Language Instructions


Operands of machine language instructions are described in the following formats:
r, r1, r2 GR is specified using a symbol from GR0 to GR7.
x GR used as the index register can be specified by a symbol from GR1 to GR7.
adr The address is specified by a decimal constant, a hexadecimal constant, an address constant or a literal.
A literal can be described by attaching the equal sign (=) before a decimal constant, a hexadecimal
constant or a character constant. CASL II generates a DC instruction by specifying the constant after
the equal sign as the operand, and sets the address to the adr value.

2.6 Other
(1) The relative positions of the instruction words and areas generated by the assembler conform to the order of the descriptions in the assembly
language program. All DC instructions generated from literals are located just before the END instruction.
(2) The instruction words and areas that are generated occupy a continuous area in the main memory.

3. Guide to Program Execution


3.1 OS
The following arrangements exist regarding program execution.
(1) The assembler interprets undefined labels (of those labels written in the operand column, any that are not defined within the program) as
entry names (START instruction labels) for other programs. In this case, the assembler refrains from determining the address and entrusts that task
to the OS. Before executing the program, the OS performs link processing with entry names for other programs and determines the addresses
(program linking).
(2) The program is started up by the OS. Although the area in the main memory where a program is loaded is undefined, the address value
corresponding to the label in the program is corrected to the actual address by the OS.
(3) During program startup, the OS allocates enough stack area for the program, then adds one to the last address and sets that value in the SP.
(4) The OS passes control to the program by the CALL instruction. When returning control to the OS after executing the program, the RET
instruction is used.
(5) The assignment of an input device to the IN instruction or of an output device to the OUT instruction is made by the user before executing the
program.
(6) The OS handles the differences that may arise in input and output procedures due to the different I/O devices and media involved; I/O is
performed using the system’s standard format and procedures (including error handling). Therefore, the user of these IN and OUT instructions
does not need to be concerned with differences among I/O devices.

3.2 Undefined Items


Ensure that any items concerning program execution that are not defined in these specifications are handled by the processing system.

36

You might also like