aboutsummaryrefslogtreecommitdiffgithub
path: root/novice/assembler/opspec/complx.ts
blob: 3b705e855bd6b012a5828330a3ee33d6d9d05525 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { AsmContext, oneWord, OpOperands, PseudoOpSpec } from './opspec';

const complxOpSpec: PseudoOpSpec = {
    ops: [
        {op: 'fill',
         operands: [{kind: 'int', name: 'num'}],
         asm: (ctx: AsmContext, operands: OpOperands) =>
            // TODO: complain if too big
            [operands.ints.num & ~(-1 << ctx.isa.mem.addressability)]},

        {op: 'fill',
         operands: [{kind: 'label', name: 'label'}],
         size: oneWord,
         asm: (ctx: AsmContext, operands: OpOperands) =>
            // TODO: complain if nonexistent
            [ctx.symbtable[operands.labels.label]]},

        {op: 'stringz',
         operands: [{kind: 'string', name: 'str'}],
         asm: (ctx: AsmContext, operands: OpOperands) =>
            // TODO: how is non-ascii handled? probably blow up
            operands.strings.str.split('').map(c => c.charCodeAt(0)).concat([0])},

        {op: 'blkw',
         operands: [{kind: 'int', name: 'count'}],
         asm: (ctx: AsmContext, operands: OpOperands) => {
            // TODO: needs to be randomized/uninitialized
            const result = new Array<number>(operands.ints.count);
            for (let i = 0; i < result.length; i++) {
                result[i] = 0;
            }
            return result;
        }},
    ],
};

export { complxOpSpec };