Download CP1E CPU Unit Software
Transcript
4 Understanding Programming Caution Program so that the memory area of the start address is not exceeded when using a word address or symbol for the offset. If an indirect specification causes the address to exceed the area of the start address, the system will access data in other area, and unexpected operation may occur. 4-5-2 Application Examples for Address Offsets It is possible to dynamically specify the offset by specifying a word address in I/O memory for the offset in the brackets. The contents of the specified word address will be used as the offset. For example, execution can be performed by increasing the address by incrementing the value in the brackets and using only one instruction. 4 Ladder Program Example The contents of corresponding words are added starting from the specified starting point, W0, to the end of the areas and the sums are output to D200 to D299 starting from the specified offset from D200. For example, if W0 is 30, the corresponding words from D30 to D99 and D130 to D199 are added, and the sums are output to D230 to D299. Set the value of W0 to the offset word (W1) using the MOV instruction. Use the operand of the addition instruction to specify and execute D0[W1] + D100[W1] = D200[W1]. Increment W1 to increase the offset. Repeat this process 100 times. Each process is performed with an input comparison instruction (<) as the execution condition so that W1 does not exceed &100 to make sure that the upper limit of the indirect addressing range is not exceeded. Execution condition a < W1 &100 MOV W0 W1 When execution condition a (upwardly differentiated) turns ON, the value of W0 is set to W1. FOR &100 Starts FOR loop + D0[W1] D100[W1] D200[W1] If execution condition a is ON and the value of W1 is less than &100, the data from the start position until D99 and the data until D199 are added, and the sum for each is output until D299. ++ While execution condition a is ON, W0 is incremented. W1 NEXT CP1E CPU Unit Software User’s Manual(W480) Returns to FOR 4-21 4-5-2 Application Examples for Address Offsets In this example, two areas of consecutive data are used: D0 to D99 and D100 to D199. Execution condition a 4-5 Specifying Offsets for Addresses For example, write the program so that processing is executed only when the indirect specification does not cause the final address to exceed the memory area by using an input comparison instruction or other instruction.