实现将二进制原码转换为补码的图灵机
Instruction | Current State | Current Value of M | New Value of M | Operation on M | New State |
---|---|---|---|---|---|
1 | Begin | * | * | NOP | Start |
2 | Start | * | * | R | IsNegative |
3 | IsNegative | 0 | 0 | L | Halt |
4 | IsNegative | 1 | 1 | R | Flip |
5 | Flip | 1 | 0 | R | Flip |
6 | Flip | 0 | 1 | R | Flip |
7 | Flip | * | * | L | Addition |
8 | Addition | 0 | 1 | L | Return |
9 | Addition | 1 | 0 | L | Carry |
10 | Carry | 0 | 1 | L | Return |
11 | Carry | 1 | 0 | L | Carry |
12 | Carry | * | 1 | L | Overflow |
13 | Overflow | blank | * | NOP | Halt |
14 | Return | 0 | 0 | L | Return |
15 | Return | 1 | 1 | L | Return |
16 | Return | * | * | NOP | Halt |
输入的二进制数据按从左到右类似于大端法
读取,第一位为符号位
样例:
-
*00101110* 经过 (1 2 3) 变为 *00101110*
-
*11001001* 经过 (1 2 4 5 6 6 5 6 6 5 7 8 15 15 14 15 15 14 15 16) 变为 *10110111*
在corelab运行以下程序,initial state值为IsNegative
IsNegative 0 0 L Halt
IsNegative 1 1 R Flip
Flip 1 0 R Flip
Flip 0 1 R Flip
Flip * * L Addition
Addition 0 1 L Return
Addition 1 0 L Carry
Carry 0 1 L Return
Carry 1 0 L Carry
Carry * 1 L Overflow
Overflow _ * * Halt
Return 0 0 L Return
Return 1 1 L Return
Return * * * Halt