I'm trying to write Checksum Algorithm using MARIE.js, but I'm stuck on doing 1's complement. I saw other assembly languages have CMA code, but I couldn't find that information on MARIE. Thus, I typed G that opcode is 2F to find the checksum byte but the output is not what I expected. What did I miss or do something wrong?
Input /Takes user input
Store A /Stores user input to A
Input /Takes user input
Store B /Stores user input to B
Input /Takes user input
Store C /Stores user input to C
Input /Takes user input
Store D /Stores user input to D
Load A /Load A to AC
Add B /Add B to A
Add C /Add C to B
Add D /Add D to C
Subt F /Subtract F from Sum of data 1,2,3,4
Store E /Sum of data 1,2,3,4 ignoring carry
Subt G
/Add ONE
Output /Print checksum byte
HALT /End program
/Variable decleration
A, HEX 0 /Data 1
B, HEX 0 /Data 2
C, HEX 0 /Data 3
D, HEX 0 /Data 4
E, HEX 0 /Checksum byte
F, HEX 100 /Ignore carry
G, HEX 2F
ONE, DEC 1
Two's complement,
-n
, is defined as one's complement + 1, e.g.~n + 1
Therefore, since MARIE has subtraction you can make two's complement (e.g.
0-n
) and subtracting 1 from that will yield one's complement,~n
.