siamtic s7

Hello sayahan;

Say you want to MOVE the decimal value 3600 to MW200, defined as an integer register, you can MOVE 3600 to MW200 (no errors from Step 7).
Now, if you want to MOVE the decimal value 3600 to MD2002, defined as a Double Integer register, Step 7 will give you an error (Try it). Now try MOVE-ing L#3600 into the same MD202. The value will be accepted.

L# defines an intger value over 4 bytes, (Long format)so it can be used with DINT functions( MOVE, math, compare...).

Hope this helps,
Daniel Chartier
 
Prefix L# means double integer constant, empty prefix means integer constant.
As long as double integer is a positive number and is not greater than 2^15-1 the bit pattern of int and dint is the same.
 
maybe example would be fine too...

L 3600
T MW 70.0 // ok

L L#3600 // can work too... because 3600 < 65535
T MW 70.0 // but it's not so cool :)

L L#3600
T MD 80.0 // ok

L 3600
ITD
T MD 80.0 // this is correct

L 3600
T MD 80.0 // this is real problem... if first half of stack is nonzero

L L#360000
T MD 80.0 // this is why L# sign exist...


well... to understand this, learn how stack works... it's practically same on every CPU...
http://en.wikipedia.org/wiki/Stack_(data_structure)
 
marius said:
L 3600
T MD 80.0 // this is real problem... if first half of stack is nonzero

According to Step 7 help, the load instruction operates as follows:

L <address> loads the addressed byte, word, or double word into ACCU 1 after the old contents of ACCU 1 have been saved into ACCU 2, and ACCU 1 is reset to "0"

This means that if you load an integer into the accumulator the top 16 bits will be zero. The only problem is loading integers and maintaining the sign if you store the value in a double word.
 
marius said:
L L#3600 // can work too... because 3600 < 65535
T MW 70.0 // but it's not so cool :)

If you try to load dint larger than 32767 and use it as an integer then you'll get "nicely" suprised. This is because 16th bit in case of integer is a sign. And as integers are U2 coded you will get negative number.
 
simon, jacekd
... i had stack value in my mind during writing... so thanks both for correction
 

Similar Topics

Hello everybody! A code question: I want to load large amounts of data from one DB to another one. One option is this: L DB100.DBW0 T...
Replies
4
Views
2,255
Back
Top Bottom