-
Notifications
You must be signed in to change notification settings - Fork 5
/
AddInt64.scl
99 lines (80 loc) · 2.2 KB
/
AddInt64.scl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Name: FС353
// Symbolic Name: AddInt64
// Symbol Comment: Addition of two 64-bit integer variables
// Family: System
// Version: 2.0
// Author: AdvLib80
// Last modified: 07/04/2011
// Use: UDT23
// Size: 422 bytes
// Original SCL source name: ExtendedPrecision
// Signature: generiert vom SCL Übersetzer Version: SCLCOMP K05.03.07.00_01.02.00.01 release
FUNCTION FC1353 : VOID
TITLE ='Addition of two 64-bit integer variables'
AUTHOR : AdvLib80
FAMILY : System
NAME : AddInt64
VERSION : '2.0'
//reversed
VAR_INPUT
Int64_1 : STRUCT
UpperDInt : DINT ;
LowerDInt : DINT ;
END_STRUCT ;
Int64_1_dw AT Int64_1 : STRUCT
x0 : DWORD ;
x1 : DWORD ;
END_STRUCT ;
Int64_2 : STRUCT
UpperDInt : DINT ;
LowerDInt : DINT ;
END_STRUCT ;
Int64_2_dw AT Int64_2 : STRUCT
x0 : DWORD ;
x1 : DWORD ;
END_STRUCT ;
END_VAR
VAR_OUTPUT
OutInt64 : STRUCT
UpperDInt : DINT ;
LowerDInt : DINT ;
END_STRUCT ;
END_VAR
VAR_TEMP
retval : STRUCT
UpperDInt : DINT ;
LowerDInt : DINT ;
END_STRUCT ;
retval_dw AT retval : STRUCT
x0 : DWORD ;
x1 : DWORD ;
END_STRUCT ;
TempDINT1 : DINT ;
TempDINT2 : DINT ;
l1_lowbit : DINT ;
l1_lowbit_dw AT l1_lowbit : DWORD ;
l2_lowbit : DINT ;
l2_lowbit_dw AT l2_lowbit : DWORD ;
AddOne : DINT ;
AddTwo : DINT ;
carry : DINT ;
END_VAR
BEGIN
l1_lowbit:=DWORD_TO_DINT(Int64_1_dw.x1 AND DW#16#1);
l2_lowbit:=DWORD_TO_DINT(Int64_2_dw.x1 AND DW#16#1);
AddOne:=DWORD_TO_DINT(DINT_TO_DWORD(l1_lowbit) XOR DINT_TO_DWORD(l2_lowbit));
AddTwo:=DWORD_TO_DINT(DINT_TO_DWORD(l1_lowbit) AND DINT_TO_DWORD(l2_lowbit));
carry:=0;
TempDINT1:=DWORD_TO_DINT(SHR(IN:=Int64_1_dw.x1,N:=1));
TempDINT2:=DWORD_TO_DINT(SHR(IN:=Int64_2_dw.x1,N:=1));
retval.LowerDInt:=TempDINT1 + TempDINT2 + AddTwo;
IF retval.LowerDInt<0
THEN
carry:=1;
END_IF;
retval.LowerDInt:=DWORD_TO_DINT(SHL(IN:=retval_dw.x1,N:=1));
retval.LowerDInt:=retval.LowerDInt + AddOne;
retval.UpperDInt:=Int64_1.UpperDInt + Int64_2.UpperDInt + carry;
OutInt64.UpperDInt:=retval.UpperDInt;
OutInt64.LowerDInt:=retval.LowerDInt;
END_FUNCTION