0

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
xeecq
  • 1
  • 1
  • 2
    Please [edit] your question title to something that describes the problem you're having or question you're asking. The `marie` tag you added tells everyone that it is about the Marie Assembly Language, so putting that in the title is useless noise. Your title should be clear and descriptive enough to have meaning to a future site user who is skimming a list of search results trying to find a solution to a problem, and your current title is meaningless. You'll find your experiences here will be much better if you take the [tour] and read the [help] pages to learn how the site works. – Ken White Apr 09 '22 at 02:50
  • I presume you realize that computing a 1's complement checksum means adding up all the numbers including any carry bits. – WJS Apr 09 '22 at 03:03

1 Answers1

0

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.

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53