Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
59
Task/Four-bit-adder/XPL0/four-bit-adder.xpl0
Normal file
59
Task/Four-bit-adder/XPL0/four-bit-adder.xpl0
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
code CrLf=9, IntOut=11;
|
||||
|
||||
func Not(A);
|
||||
int A;
|
||||
return not A;
|
||||
|
||||
func And(A, B);
|
||||
int A, B;
|
||||
return A and B;
|
||||
|
||||
func Or(A, B);
|
||||
int A, B;
|
||||
return A or B;
|
||||
|
||||
func Xor(A, B);
|
||||
int A, B;
|
||||
return Or(And(A, Not(B)), And(Not(A), B));
|
||||
|
||||
proc HalfAdd(A, B, S, C);
|
||||
int A, B, S, C;
|
||||
[S(0):= Xor(A, B);
|
||||
C(0):= And(A, B);
|
||||
];
|
||||
|
||||
proc FullAdd(A, B, Ci, S, Co);
|
||||
int A, B, Ci, S, Co; \(Ci and Co are reversed from drawing)
|
||||
int S0, S1, C0, C1;
|
||||
[HalfAdd(Ci, A, @S0, @C0);
|
||||
HalfAdd(S0, B, @S1, @C1);
|
||||
S(0):= S1;
|
||||
Co(0):= Or(C0, C1);
|
||||
];
|
||||
|
||||
proc Add4Bits(A0, A1, A2, A3, B0, B1, B2, B3, S0, S1, S2, S3, Co);
|
||||
int A0, A1, A2, A3, B0, B1, B2, B3, S0, S1, S2, S3, Co;
|
||||
int Co0, Co1, Co2;
|
||||
[FullAdd(A0, B0, 0, S0, @Co0);
|
||||
FullAdd(A1, B1, Co0, S1, @Co1);
|
||||
FullAdd(A2, B2, Co1, S2, @Co2);
|
||||
FullAdd(A3, B3, Co2, S3, Co);
|
||||
];
|
||||
|
||||
proc BinOut(D, A0, A1, A2, A3, C);
|
||||
int D, A0, A1, A2, A3, C;
|
||||
[IntOut(D, C&1);
|
||||
IntOut(D, A3&1);
|
||||
IntOut(D, A2&1);
|
||||
IntOut(D, A1&1);
|
||||
IntOut(D, A0&1);
|
||||
];
|
||||
|
||||
int S0, S1, S2, S3, C;
|
||||
[Add4Bits(1, 0, 0, 0, 0, 0, 1, 0, @S0, @S1, @S2, @S3, @C); \0001 + 0100 = 00101
|
||||
BinOut(0, S0, S1, S2, S3, C); CrLf(0);
|
||||
Add4Bits(1, 0, 1, 0, 0, 1, 1, 1, @S0, @S1, @S2, @S3, @C); \0101 + 1110 = 10011
|
||||
BinOut(0, S0, S1, S2, S3, C); CrLf(0);
|
||||
Add4Bits(1, 1, 1, 1, 1, 1, 1, 1, @S0, @S1, @S2, @S3, @C); \1111 + 1111 = 11110
|
||||
BinOut(0, S0, S1, S2, S3, C); CrLf(0);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue