Rules

Specifications

  • All SAP programs fit in 16 addresses (0 to 15) because the program counter (PC) is 4-bit. [1]

  • The initial state of a SAP program is {PC: 0, Register A: 0, Register B: 0, FlagC: 0, FlagZ: 0, Executing: 1}. [2]

  • A and B registers are 8-bit by default. [3] The bit patterns are always interpreted as unsigned integers by SAPsim.

    • If the registers are interpreted as unsigned ints, what would 0-1 be? What about 255+1? See this footnote for the answer. [4]

General

  • Everything in RAM is a byte. [5] Therefore, instructions and data are both represented as a First Hexit and Second Hexit.

    • An instruction’s First Hexit is its 2 or 3 letter Mnemonic. An instruction’s Second Hexit is its Arg.

      • An instruction’s Arg can be represented in base-10 or base-16.

      • For example, JC 15 could also be written as JC F.

    • All data must fit in a byte.

      • For example, 254 = 0xFE is First Hexit F, Second Hexit E.

      • 10 = 0x0A is First Hexit 0, Second Hexit A. You may not omit the leading 0.

  • Programs run until they HLT or until an Exception is raised. Infinite loops are possible, of course.

Note

These are the same rules a SAP computer implemented by hardware has to follow.

“This is a feature, not a bug”

Allowed syntax

In the First Hexit column, these are allowed

  • Two or three letter Mnemonic [6]

  • Hexit 0 to F

  • Double digit base-10 integer 10 to 15 representing a hexit

In the Second Hexit column, these are allowed

  • Hexit 0 to F

  • Double-digit base-10 integer 10 to 15 representing a hexit

    • e.g. JC 15 and JC F are both legal and represent the same instruction