13: P
ROGRAM
B
RANCHING
I
NSTRUCTIONS
13-6 FC6A S
ERIES
MICROS
MART
L
ADDER
P
ROGRAMMING
M
ANUAL
FC9Y-B1726
Example: DJNZ and LABEL
The following example demonstrates a program to store consecutive values 1,000 through 1,049 to data registers D100 through
D149, respectively.
LABEL
255
M8120
END
M8120
REPS1 –
D0
D1 –
D99
IMOV(W) S2 D2
D1
REPS1 –
1049
D1 –
D0
MOV(W)
REPS1 –
50
D1 –
D1
MOV(W)
S/D
D0
DEC(W)
S2
255
S1
D1
DJNZ
M8120 is the initialize pulse special internal relay.
At start-up, MOV instructions store initial data.
1049 → D0 to store the value for the first cycle.
50 → D1 to determine the jump cycles.
IMOV moves D0 data 1049 to D1049 in the first cycle.
DEC decrements D0 data to 1048.
DJNZ jumps to label 255 until D1 value reduces to 0.
1049
D0
Destination: D99 + 50 = D149
1049
D149
50
D1
1st cycle:
1048
D0
Destination: D99 + 49 = D148
1048
D148
49
D1
2nd cycle:
1047
D0
Destination: D99 + 48 = D147
1047
D147
48
D1
3rd cycle:
1046
D0
Destination: D99 + 47 = D146 1046
D146
47
D1
4th cycle:
1001
D0
Destination: D99 + 2 = D101 1001
D101
2
D1
49th cycle:
1000
D0
Destination: D99 + 1 = D100 1000
D100
1
D1
50th cycle: