317 lines
20 KiB
JavaScript
317 lines
20 KiB
JavaScript
import { S16_0, S16_1, S16_2, S16_3, S16_4, S16_5, S16_6, S16_7, S16_8, S16_9, S16_A, S16_B, S16_C, S16_D, S16_E, S16_F } from "../symbol/S16.js"
|
|
|
|
/**
|
|
* @param { symbol } a
|
|
* @param { symbol } b
|
|
* @param { boolean } carry
|
|
* @returns { [value: symbol, carry: boolean] }
|
|
*/
|
|
export function add16B(a, b, carry) {
|
|
switch (a) {
|
|
case S16_0: switch (b) {
|
|
case S16_0: return carry ? [S16_1, false] : [S16_0, false];
|
|
case S16_1: return carry ? [S16_2, false] : [S16_1, false];
|
|
case S16_2: return carry ? [S16_3, false] : [S16_2, false];
|
|
case S16_3: return carry ? [S16_4, false] : [S16_3, false];
|
|
case S16_4: return carry ? [S16_5, false] : [S16_4, false];
|
|
case S16_5: return carry ? [S16_6, false] : [S16_5, false];
|
|
case S16_6: return carry ? [S16_7, false] : [S16_6, false];
|
|
case S16_7: return carry ? [S16_8, false] : [S16_7, false];
|
|
case S16_8: return carry ? [S16_9, false] : [S16_8, false];
|
|
case S16_9: return carry ? [S16_A, false] : [S16_9, false];
|
|
case S16_A: return carry ? [S16_B, false] : [S16_A, false];
|
|
case S16_B: return carry ? [S16_C, false] : [S16_B, false];
|
|
case S16_C: return carry ? [S16_D, false] : [S16_C, false];
|
|
case S16_D: return carry ? [S16_E, false] : [S16_D, false];
|
|
case S16_E: return carry ? [S16_F, false] : [S16_E, false];
|
|
case S16_F: return carry ? [S16_0, true ] : [S16_F, false];
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
case S16_1: switch (b) {
|
|
case S16_0: return carry ? [S16_2, false] : [S16_1, false];
|
|
case S16_1: return carry ? [S16_3, false] : [S16_2, false];
|
|
case S16_2: return carry ? [S16_4, false] : [S16_3, false];
|
|
case S16_3: return carry ? [S16_5, false] : [S16_4, false];
|
|
case S16_4: return carry ? [S16_6, false] : [S16_5, false];
|
|
case S16_5: return carry ? [S16_7, false] : [S16_6, false];
|
|
case S16_6: return carry ? [S16_8, false] : [S16_7, false];
|
|
case S16_7: return carry ? [S16_9, false] : [S16_8, false];
|
|
case S16_8: return carry ? [S16_A, false] : [S16_9, false];
|
|
case S16_9: return carry ? [S16_B, false] : [S16_A, false];
|
|
case S16_A: return carry ? [S16_C, false] : [S16_B, false];
|
|
case S16_B: return carry ? [S16_D, false] : [S16_C, false];
|
|
case S16_C: return carry ? [S16_E, false] : [S16_D, false];
|
|
case S16_D: return carry ? [S16_F, false] : [S16_E, false];
|
|
case S16_E: return carry ? [S16_0, true ] : [S16_F, false];
|
|
case S16_F: return carry ? [S16_1, true ] : [S16_0, true ];
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
case S16_2: switch (b) {
|
|
case S16_0: return carry ? [S16_3, false] : [S16_2, false];
|
|
case S16_1: return carry ? [S16_4, false] : [S16_3, false];
|
|
case S16_2: return carry ? [S16_5, false] : [S16_4, false];
|
|
case S16_3: return carry ? [S16_6, false] : [S16_5, false];
|
|
case S16_4: return carry ? [S16_7, false] : [S16_6, false];
|
|
case S16_5: return carry ? [S16_8, false] : [S16_7, false];
|
|
case S16_6: return carry ? [S16_9, false] : [S16_8, false];
|
|
case S16_7: return carry ? [S16_A, false] : [S16_9, false];
|
|
case S16_8: return carry ? [S16_B, false] : [S16_A, false];
|
|
case S16_9: return carry ? [S16_C, false] : [S16_B, false];
|
|
case S16_A: return carry ? [S16_D, false] : [S16_C, false];
|
|
case S16_B: return carry ? [S16_E, false] : [S16_D, false];
|
|
case S16_C: return carry ? [S16_F, false] : [S16_E, false];
|
|
case S16_D: return carry ? [S16_0, true ] : [S16_F, false];
|
|
case S16_E: return carry ? [S16_1, true ] : [S16_0, true ];
|
|
case S16_F: return carry ? [S16_2, true ] : [S16_1, true ];
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
case S16_3: switch (b) {
|
|
case S16_0: return carry ? [S16_4, false] : [S16_3, false];
|
|
case S16_1: return carry ? [S16_5, false] : [S16_4, false];
|
|
case S16_2: return carry ? [S16_6, false] : [S16_5, false];
|
|
case S16_3: return carry ? [S16_7, false] : [S16_6, false];
|
|
case S16_4: return carry ? [S16_8, false] : [S16_7, false];
|
|
case S16_5: return carry ? [S16_9, false] : [S16_8, false];
|
|
case S16_6: return carry ? [S16_A, false] : [S16_9, false];
|
|
case S16_7: return carry ? [S16_B, false] : [S16_A, false];
|
|
case S16_8: return carry ? [S16_C, false] : [S16_B, false];
|
|
case S16_9: return carry ? [S16_D, false] : [S16_C, false];
|
|
case S16_A: return carry ? [S16_E, false] : [S16_D, false];
|
|
case S16_B: return carry ? [S16_F, false] : [S16_E, false];
|
|
case S16_C: return carry ? [S16_0, true ] : [S16_F, false];
|
|
case S16_D: return carry ? [S16_1, true ] : [S16_0, true ];
|
|
case S16_E: return carry ? [S16_2, true ] : [S16_1, true ];
|
|
case S16_F: return carry ? [S16_3, true ] : [S16_2, true ];
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
case S16_4: switch (b) {
|
|
case S16_0: return carry ? [S16_5, false] : [S16_4, false];
|
|
case S16_1: return carry ? [S16_6, false] : [S16_5, false];
|
|
case S16_2: return carry ? [S16_7, false] : [S16_6, false];
|
|
case S16_3: return carry ? [S16_8, false] : [S16_7, false];
|
|
case S16_4: return carry ? [S16_9, false] : [S16_8, false];
|
|
case S16_5: return carry ? [S16_A, false] : [S16_9, false];
|
|
case S16_6: return carry ? [S16_B, false] : [S16_A, false];
|
|
case S16_7: return carry ? [S16_C, false] : [S16_B, false];
|
|
case S16_8: return carry ? [S16_D, false] : [S16_C, false];
|
|
case S16_9: return carry ? [S16_E, false] : [S16_D, false];
|
|
case S16_A: return carry ? [S16_F, false] : [S16_E, false];
|
|
case S16_B: return carry ? [S16_0, true ] : [S16_F, false];
|
|
case S16_C: return carry ? [S16_1, true ] : [S16_0, true ];
|
|
case S16_D: return carry ? [S16_2, true ] : [S16_1, true ];
|
|
case S16_E: return carry ? [S16_3, true ] : [S16_2, true ];
|
|
case S16_F: return carry ? [S16_4, true ] : [S16_3, true ];
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
case S16_5: switch (b) {
|
|
case S16_0: return carry ? [S16_6, false] : [S16_5, false];
|
|
case S16_1: return carry ? [S16_7, false] : [S16_6, false];
|
|
case S16_2: return carry ? [S16_8, false] : [S16_7, false];
|
|
case S16_3: return carry ? [S16_9, false] : [S16_8, false];
|
|
case S16_4: return carry ? [S16_A, false] : [S16_9, false];
|
|
case S16_5: return carry ? [S16_B, false] : [S16_A, false];
|
|
case S16_6: return carry ? [S16_C, false] : [S16_B, false];
|
|
case S16_7: return carry ? [S16_D, false] : [S16_C, false];
|
|
case S16_8: return carry ? [S16_E, false] : [S16_D, false];
|
|
case S16_9: return carry ? [S16_F, false] : [S16_E, false];
|
|
case S16_A: return carry ? [S16_0, true ] : [S16_F, false];
|
|
case S16_B: return carry ? [S16_1, true ] : [S16_0, true ];
|
|
case S16_C: return carry ? [S16_2, true ] : [S16_1, true ];
|
|
case S16_D: return carry ? [S16_3, true ] : [S16_2, true ];
|
|
case S16_E: return carry ? [S16_4, true ] : [S16_3, true ];
|
|
case S16_F: return carry ? [S16_5, true ] : [S16_4, true ];
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
case S16_6: switch (b) {
|
|
case S16_0: return carry ? [S16_7, false] : [S16_6, false];
|
|
case S16_1: return carry ? [S16_8, false] : [S16_7, false];
|
|
case S16_2: return carry ? [S16_9, false] : [S16_8, false];
|
|
case S16_3: return carry ? [S16_A, false] : [S16_9, false];
|
|
case S16_4: return carry ? [S16_B, false] : [S16_A, false];
|
|
case S16_5: return carry ? [S16_C, false] : [S16_B, false];
|
|
case S16_6: return carry ? [S16_D, false] : [S16_C, false];
|
|
case S16_7: return carry ? [S16_E, false] : [S16_D, false];
|
|
case S16_8: return carry ? [S16_F, false] : [S16_E, false];
|
|
case S16_9: return carry ? [S16_0, true ] : [S16_F, false];
|
|
case S16_A: return carry ? [S16_1, true ] : [S16_0, true ];
|
|
case S16_B: return carry ? [S16_2, true ] : [S16_1, true ];
|
|
case S16_C: return carry ? [S16_3, true ] : [S16_2, true ];
|
|
case S16_D: return carry ? [S16_4, true ] : [S16_3, true ];
|
|
case S16_E: return carry ? [S16_5, true ] : [S16_4, true ];
|
|
case S16_F: return carry ? [S16_6, true ] : [S16_5, true ];
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
case S16_7: switch (b) {
|
|
case S16_0: return carry ? [S16_8, false] : [S16_7, false];
|
|
case S16_1: return carry ? [S16_9, false] : [S16_8, false];
|
|
case S16_2: return carry ? [S16_A, false] : [S16_9, false];
|
|
case S16_3: return carry ? [S16_B, false] : [S16_A, false];
|
|
case S16_4: return carry ? [S16_C, false] : [S16_B, false];
|
|
case S16_5: return carry ? [S16_D, false] : [S16_C, false];
|
|
case S16_6: return carry ? [S16_E, false] : [S16_D, false];
|
|
case S16_7: return carry ? [S16_F, false] : [S16_E, false];
|
|
case S16_8: return carry ? [S16_0, true ] : [S16_F, false];
|
|
case S16_9: return carry ? [S16_1, true ] : [S16_0, true ];
|
|
case S16_A: return carry ? [S16_2, true ] : [S16_1, true ];
|
|
case S16_B: return carry ? [S16_3, true ] : [S16_2, true ];
|
|
case S16_C: return carry ? [S16_4, true ] : [S16_3, true ];
|
|
case S16_D: return carry ? [S16_5, true ] : [S16_4, true ];
|
|
case S16_E: return carry ? [S16_6, true ] : [S16_5, true ];
|
|
case S16_F: return carry ? [S16_7, true ] : [S16_6, true ];
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
case S16_8: switch (b) {
|
|
case S16_0: return carry ? [S16_9, false] : [S16_8, false];
|
|
case S16_1: return carry ? [S16_A, false] : [S16_9, false];
|
|
case S16_2: return carry ? [S16_B, false] : [S16_A, false];
|
|
case S16_3: return carry ? [S16_C, false] : [S16_B, false];
|
|
case S16_4: return carry ? [S16_D, false] : [S16_C, false];
|
|
case S16_5: return carry ? [S16_E, false] : [S16_D, false];
|
|
case S16_6: return carry ? [S16_F, false] : [S16_E, false];
|
|
case S16_7: return carry ? [S16_0, true ] : [S16_F, false];
|
|
case S16_8: return carry ? [S16_1, true ] : [S16_0, true ];
|
|
case S16_9: return carry ? [S16_2, true ] : [S16_1, true ];
|
|
case S16_A: return carry ? [S16_3, true ] : [S16_2, true ];
|
|
case S16_B: return carry ? [S16_4, true ] : [S16_3, true ];
|
|
case S16_C: return carry ? [S16_5, true ] : [S16_4, true ];
|
|
case S16_D: return carry ? [S16_6, true ] : [S16_5, true ];
|
|
case S16_E: return carry ? [S16_7, true ] : [S16_6, true ];
|
|
case S16_F: return carry ? [S16_8, true ] : [S16_7, true ];
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
case S16_9: switch (b) {
|
|
case S16_0: return carry ? [S16_A, false] : [S16_9, false];
|
|
case S16_1: return carry ? [S16_B, false] : [S16_A, false];
|
|
case S16_2: return carry ? [S16_C, false] : [S16_B, false];
|
|
case S16_3: return carry ? [S16_D, false] : [S16_C, false];
|
|
case S16_4: return carry ? [S16_E, false] : [S16_D, false];
|
|
case S16_5: return carry ? [S16_F, false] : [S16_E, false];
|
|
case S16_6: return carry ? [S16_0, true ] : [S16_F, false];
|
|
case S16_7: return carry ? [S16_1, true ] : [S16_0, true ];
|
|
case S16_8: return carry ? [S16_2, true ] : [S16_1, true ];
|
|
case S16_9: return carry ? [S16_3, true ] : [S16_2, true ];
|
|
case S16_A: return carry ? [S16_4, true ] : [S16_3, true ];
|
|
case S16_B: return carry ? [S16_5, true ] : [S16_4, true ];
|
|
case S16_C: return carry ? [S16_6, true ] : [S16_5, true ];
|
|
case S16_D: return carry ? [S16_7, true ] : [S16_6, true ];
|
|
case S16_E: return carry ? [S16_8, true ] : [S16_7, true ];
|
|
case S16_F: return carry ? [S16_9, true ] : [S16_8, true ];
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
case S16_A: switch (b) {
|
|
case S16_0: return carry ? [S16_B, false] : [S16_A, false];
|
|
case S16_1: return carry ? [S16_C, false] : [S16_B, false];
|
|
case S16_2: return carry ? [S16_D, false] : [S16_C, false];
|
|
case S16_3: return carry ? [S16_E, false] : [S16_D, false];
|
|
case S16_4: return carry ? [S16_F, false] : [S16_E, false];
|
|
case S16_5: return carry ? [S16_0, true ] : [S16_F, false];
|
|
case S16_6: return carry ? [S16_1, true ] : [S16_0, true ];
|
|
case S16_7: return carry ? [S16_2, true ] : [S16_1, true ];
|
|
case S16_8: return carry ? [S16_3, true ] : [S16_2, true ];
|
|
case S16_9: return carry ? [S16_4, true ] : [S16_3, true ];
|
|
case S16_A: return carry ? [S16_5, true ] : [S16_4, true ];
|
|
case S16_B: return carry ? [S16_6, true ] : [S16_5, true ];
|
|
case S16_C: return carry ? [S16_7, true ] : [S16_6, true ];
|
|
case S16_D: return carry ? [S16_8, true ] : [S16_7, true ];
|
|
case S16_E: return carry ? [S16_9, true ] : [S16_8, true ];
|
|
case S16_F: return carry ? [S16_A, true ] : [S16_9, true ];
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
case S16_B: switch (b) {
|
|
case S16_0: return carry ? [S16_C, false] : [S16_B, false];
|
|
case S16_1: return carry ? [S16_D, false] : [S16_C, false];
|
|
case S16_2: return carry ? [S16_E, false] : [S16_D, false];
|
|
case S16_3: return carry ? [S16_F, false] : [S16_E, false];
|
|
case S16_4: return carry ? [S16_0, true ] : [S16_F, false];
|
|
case S16_5: return carry ? [S16_1, true ] : [S16_0, true ];
|
|
case S16_6: return carry ? [S16_2, true ] : [S16_1, true ];
|
|
case S16_7: return carry ? [S16_3, true ] : [S16_2, true ];
|
|
case S16_8: return carry ? [S16_4, true ] : [S16_3, true ];
|
|
case S16_9: return carry ? [S16_5, true ] : [S16_4, true ];
|
|
case S16_A: return carry ? [S16_6, true ] : [S16_5, true ];
|
|
case S16_B: return carry ? [S16_7, true ] : [S16_6, true ];
|
|
case S16_C: return carry ? [S16_8, true ] : [S16_7, true ];
|
|
case S16_D: return carry ? [S16_9, true ] : [S16_8, true ];
|
|
case S16_E: return carry ? [S16_A, true ] : [S16_9, true ];
|
|
case S16_F: return carry ? [S16_B, true ] : [S16_A, true ];
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
case S16_C: switch (b) {
|
|
case S16_0: return carry ? [S16_D, false] : [S16_C, false];
|
|
case S16_1: return carry ? [S16_E, false] : [S16_D, false];
|
|
case S16_2: return carry ? [S16_F, false] : [S16_E, false];
|
|
case S16_3: return carry ? [S16_0, true ] : [S16_F, false];
|
|
case S16_4: return carry ? [S16_1, true ] : [S16_0, true ];
|
|
case S16_5: return carry ? [S16_2, true ] : [S16_1, true ];
|
|
case S16_6: return carry ? [S16_3, true ] : [S16_2, true ];
|
|
case S16_7: return carry ? [S16_4, true ] : [S16_3, true ];
|
|
case S16_8: return carry ? [S16_5, true ] : [S16_4, true ];
|
|
case S16_9: return carry ? [S16_6, true ] : [S16_5, true ];
|
|
case S16_A: return carry ? [S16_7, true ] : [S16_6, true ];
|
|
case S16_B: return carry ? [S16_8, true ] : [S16_7, true ];
|
|
case S16_C: return carry ? [S16_9, true ] : [S16_8, true ];
|
|
case S16_D: return carry ? [S16_A, true ] : [S16_9, true ];
|
|
case S16_E: return carry ? [S16_B, true ] : [S16_A, true ];
|
|
case S16_F: return carry ? [S16_C, true ] : [S16_B, true ];
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
case S16_D: switch (b) {
|
|
case S16_0: return carry ? [S16_E, false] : [S16_D, false];
|
|
case S16_1: return carry ? [S16_F, false] : [S16_E, false];
|
|
case S16_2: return carry ? [S16_0, true ] : [S16_F, false];
|
|
case S16_3: return carry ? [S16_1, true ] : [S16_0, true ];
|
|
case S16_4: return carry ? [S16_2, true ] : [S16_1, true ];
|
|
case S16_5: return carry ? [S16_3, true ] : [S16_2, true ];
|
|
case S16_6: return carry ? [S16_4, true ] : [S16_3, true ];
|
|
case S16_7: return carry ? [S16_5, true ] : [S16_4, true ];
|
|
case S16_8: return carry ? [S16_6, true ] : [S16_5, true ];
|
|
case S16_9: return carry ? [S16_7, true ] : [S16_6, true ];
|
|
case S16_A: return carry ? [S16_8, true ] : [S16_7, true ];
|
|
case S16_B: return carry ? [S16_9, true ] : [S16_8, true ];
|
|
case S16_C: return carry ? [S16_A, true ] : [S16_9, true ];
|
|
case S16_D: return carry ? [S16_B, true ] : [S16_A, true ];
|
|
case S16_E: return carry ? [S16_C, true ] : [S16_B, true ];
|
|
case S16_F: return carry ? [S16_D, true ] : [S16_C, true ];
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
case S16_E: switch (b) {
|
|
case S16_0: return carry ? [S16_F, false] : [S16_E, false];
|
|
case S16_1: return carry ? [S16_0, true ] : [S16_F, false];
|
|
case S16_2: return carry ? [S16_1, true ] : [S16_0, true ];
|
|
case S16_3: return carry ? [S16_2, true ] : [S16_1, true ];
|
|
case S16_4: return carry ? [S16_3, true ] : [S16_2, true ];
|
|
case S16_5: return carry ? [S16_4, true ] : [S16_3, true ];
|
|
case S16_6: return carry ? [S16_5, true ] : [S16_4, true ];
|
|
case S16_7: return carry ? [S16_6, true ] : [S16_5, true ];
|
|
case S16_8: return carry ? [S16_7, true ] : [S16_6, true ];
|
|
case S16_9: return carry ? [S16_8, true ] : [S16_7, true ];
|
|
case S16_A: return carry ? [S16_9, true ] : [S16_8, true ];
|
|
case S16_B: return carry ? [S16_A, true ] : [S16_9, true ];
|
|
case S16_C: return carry ? [S16_B, true ] : [S16_A, true ];
|
|
case S16_D: return carry ? [S16_C, true ] : [S16_B, true ];
|
|
case S16_E: return carry ? [S16_D, true ] : [S16_C, true ];
|
|
case S16_F: return carry ? [S16_E, true ] : [S16_D, true ];
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
case S16_F: switch (b) {
|
|
case S16_0: return carry ? [S16_0, true ] : [S16_F, false];
|
|
case S16_1: return carry ? [S16_1, true ] : [S16_0, true ];
|
|
case S16_2: return carry ? [S16_2, true ] : [S16_1, true ];
|
|
case S16_3: return carry ? [S16_3, true ] : [S16_2, true ];
|
|
case S16_4: return carry ? [S16_4, true ] : [S16_3, true ];
|
|
case S16_5: return carry ? [S16_5, true ] : [S16_4, true ];
|
|
case S16_6: return carry ? [S16_6, true ] : [S16_5, true ];
|
|
case S16_7: return carry ? [S16_7, true ] : [S16_6, true ];
|
|
case S16_8: return carry ? [S16_8, true ] : [S16_7, true ];
|
|
case S16_9: return carry ? [S16_9, true ] : [S16_8, true ];
|
|
case S16_A: return carry ? [S16_A, true ] : [S16_9, true ];
|
|
case S16_B: return carry ? [S16_B, true ] : [S16_A, true ];
|
|
case S16_C: return carry ? [S16_C, true ] : [S16_B, true ];
|
|
case S16_D: return carry ? [S16_D, true ] : [S16_C, true ];
|
|
case S16_E: return carry ? [S16_E, true ] : [S16_D, true ];
|
|
case S16_F: return carry ? [S16_F, true ] : [S16_E, true ];
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
default: throw new Error("unexpected symbol");
|
|
}
|
|
} |