|
| 1 | +const subRoutineAddress = 0x3000; |
| 2 | +let i = 0; |
| 3 | + |
| 4 | +writableBytes[i++] = PSH_LIT; |
| 5 | +writableBytes[i++] = 0x33; |
| 6 | +writableBytes[i++] = 0x33; |
| 7 | + |
| 8 | +writableBytes[i++] = PSH_LIT; |
| 9 | +writableBytes[i++] = 0x22; |
| 10 | +writableBytes[i++] = 0x22; |
| 11 | + |
| 12 | +writableBytes[i++] = PSH_LIT; |
| 13 | +writableBytes[i++] = 0x11; |
| 14 | +writableBytes[i++] = 0x11; |
| 15 | + |
| 16 | +writableBytes[i++] = MOV_LIT_REG; |
| 17 | +writableBytes[i++] = 0x12; |
| 18 | +writableBytes[i++] = 0x34; |
| 19 | +writableBytes[i++] = R1; |
| 20 | + |
| 21 | +writableBytes[i++] = MOV_LIT_REG; |
| 22 | +writableBytes[i++] = 0x56; |
| 23 | +writableBytes[i++] = 0x78; |
| 24 | +writableBytes[i++] = R4; |
| 25 | + |
| 26 | +writableBytes[i++] = PSH_LIT; |
| 27 | +writableBytes[i++] = 0x00; |
| 28 | +writableBytes[i++] = 0x00; |
| 29 | + |
| 30 | +// Initiates Abstract Stack |
| 31 | +writableBytes[i++] = CAL_LIT; |
| 32 | +writableBytes[i++] = (subRoutineAddress & 0xff00) >> 8; |
| 33 | +writableBytes[i++] = (subRoutineAddress & 0x00ff) >> 8; |
| 34 | + |
| 35 | +writableBytes[i++] = PSH_LIT; |
| 36 | +writableBytes[i++] = 0x44; |
| 37 | +writableBytes[i++] = 0x44; |
| 38 | + |
| 39 | +// Subroutine |
| 40 | +i = subRoutineAddress; |
| 41 | + |
| 42 | +writableBytes[i++] = PSH_LIT; |
| 43 | +writableBytes[i++] = 0x01; |
| 44 | +writableBytes[i++] = 0x02; |
| 45 | + |
| 46 | +writableBytes[i++] = PSH_LIT; |
| 47 | +writableBytes[i++] = 0x03; |
| 48 | +writableBytes[i++] = 0x04; |
| 49 | + |
| 50 | +writableBytes[i++] = PSH_LIT; |
| 51 | +writableBytes[i++] = 0x05; |
| 52 | +writableBytes[i++] = 0x06; |
| 53 | + |
| 54 | +writableBytes[i++] = MOV_LIT_REG; |
| 55 | +writableBytes[i++] = 0x07; |
| 56 | +writableBytes[i++] = 0x08; |
| 57 | +writableBytes[i++] = R1; |
| 58 | + |
| 59 | +writableBytes[i++] = MOV_LIT_REG; |
| 60 | +writableBytes[i++] = 0x09; |
| 61 | +writableBytes[i++] = 0x0A; |
| 62 | +writableBytes[i++] = R4; |
| 63 | + |
| 64 | +writableBytes[i++] = RET; |
| 65 | + |
| 66 | +cpu.debug(); |
| 67 | +cpu.viewMemoryAt(cpu.getRegister('ip')); |
| 68 | +cpu.viewMemoryAt(0xffff - 1 - 42, 44); // View memory at next 44 bytes |
| 69 | +console.log("\n\n"); |
| 70 | + |
| 71 | +const rl = readline.createInterface({ |
| 72 | + input: process.stdin, |
| 73 | + output: process.stdout |
| 74 | +}); |
| 75 | + |
| 76 | +rl.on('line', () => { |
| 77 | + cpu.step(); |
| 78 | + cpu.debug(); |
| 79 | + cpu.viewMemoryAt(cpu.getRegister('ip')); |
| 80 | + cpu.viewMemoryAt(0xffff - 1 - 42, 44); |
| 81 | + console.log("\n\n"); |
| 82 | +}); |
0 commit comments