MegaProcessor

Check-in [3e524fe20d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:First stab at processing of lables and symbols.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:3e524fe20d341721e67b057000e4548934238e78
User & Date: jos 2015-08-14 21:22:25
Context
2015-08-15
14:00
Added a tool to directly print the mnemonic form of the bit-oriented instructions. Changed dis_d8_db.lua to make 'require' work again. check-in: 4f89728dfa user: jos tags: trunk
2015-08-14
21:22
First stab at processing of lables and symbols. check-in: 3e524fe20d user: jos tags: trunk
14:16
Moved the generator-script dis_d8_db to 'tools', added functionality to skip printing the redundant instructions. check-in: 65f2d4419c user: jos tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to asm.lua.

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
38
39
40
41
42
43
44
45
46
47
48
49




50
51

52
53
54
55
56
57
58
59
60
61
62
63
64
65
                        );

    for l in inFile:lines() do
        Printf("%04d : ", LineNr ); 
        ProcessLine( Chomp(l) );
        LineNr = LineNr + 1;
    end


end

function Fields( line )
    if( line == "" or line:match("^%s*[;//]") ) then return 0; end;
    local retVal = 0;
    local n, n1, label, instr, dst, src;
    n = 1;
    label,n1 = line:match("^(%S+)()");  -- Start of string, (one+ non-space), (empty capture)
    if( label ) then n=n1; retVal = retVal + 1; end
    instr,n1 = line:match("%s+([^%s,;]+)%s+()",n); -- one+ space, (one+ non-space), one+ space, (empty capture)
    if( instr ) then n=n1; retVal = retVal + 1; end
    if( line:sub(n,n) == '(' ) then
        dst,n1 = line:match("(%b())()")
    else
        dst,n1 = line:match("([^%s,;]+)()",n);
    end
    if( dst ) then n=n1; retVal = retVal + 1; end
    src,n1  = line:match("[%s,]+([^%s;]+)()",n);
    if( src ) then n=n1; retVal = retVal + 1; end
    return retVal, label, instr, dst, src;
end

function ProcessLine( l )
    local asm_instr;
    local n,f1,f2,f3,f4 = Fields(l);
    local b1, b2, b3;
    local insLen;

    if( n == 0 ) then print(l); return; end





    asm_instr = Directive[ string.lower(f2 or f3) ];
    if( asm_instr ) then print( asm_instr() ); return; end

    
    asm_instr = CPU_instr[ string.upper(f2 or f3) ];
   
    if( asm_instr ) then
        insLen = asm_instr[1];
        if( type(insLen)== 'function' ) then insLen = insLen(f2,f3,f4) end;
        b1, b2, b3 = asm_instr[2](f2,f3,f4);
    end

    Printf("%s : %s: %s\n", PC_get(), fmtBytes(b1,b2,b3), l );
    PC_add(insLen);

end








>
>









|




|









|

|

|

>
>
>
>
|
<
>

|
<


|
|







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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

57
58
59

60
61
62
63
64
65
66
67
68
69
70
                        );

    for l in inFile:lines() do
        Printf("%04d : ", LineNr ); 
        ProcessLine( Chomp(l) );
        LineNr = LineNr + 1;
    end

    symtab_dump();
end

function Fields( line )
    if( line == "" or line:match("^%s*[;//]") ) then return 0; end;
    local retVal = 0;
    local n, n1, label, instr, dst, src;
    n = 1;
    label,n1 = line:match("^(%S+)()");  -- Start of string, (one+ non-space), (empty capture)
    if( label ) then n=n1; retVal = retVal + 1; end
    instr,n1 = line:match("%s+([^%s,;]+)%s*()",n); -- one+ space, (one+ non-space), 0+ space, (empty capture)
    if( instr ) then n=n1; retVal = retVal + 1; end
    if( line:sub(n,n) == '(' ) then
        dst,n1 = line:match("(%b())()")
    else
        dst,n1 = line:match("([^%s,;]+)()",n); -- Note, a comma ends the match, this screws up things like '(SP,0x45)'
    end
    if( dst ) then n=n1; retVal = retVal + 1; end
    src,n1  = line:match("[%s,]+([^%s;]+)()",n);
    if( src ) then n=n1; retVal = retVal + 1; end
    return retVal, label, instr, dst, src;
end

function ProcessLine( l )
    local asm_instr;
    local n,label,Mnemonic,op1,op2 = Fields(l);
    local b1, b2, b3;
    local insLen = 0;

    if( label and not Mnemonic ) then symtab_addLabel(label) end;

    if( not Mnemonic ) then Printf("%s : %s\n", PC_get(), l ); return; end

    Mnemonic = Mnemonic:upper();

    asm_instr = Directive[ Mnemonic ];

    if( asm_instr ) then asm_instr(label,Mnemonic,op1,l); return; end
    
    asm_instr = CPU_instr[ Mnemonic ];

    if( asm_instr ) then
        insLen = asm_instr[1];
        if( type(insLen)== 'function' ) then insLen = insLen(Mnemonic,op1,op2) end;
        b1, b2, b3 = asm_instr[2](Mnemonic,op1,op2);
    end

    Printf("%s : %s: %s\n", PC_get(), fmtBytes(b1,b2,b3), l );
    PC_add(insLen);

end

Changes to asm_instr.lua.


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


local M = {
['db'] = function( srcLine ) 



    return 'DB';
end,

['dl'] = function( srcLine ) 

    return 'DL';
end,

['dm'] = function( srcLine ) 

    return 'DM';
end,

['ds'] = function( srcLine ) 


    return 'DS';
end,

['dw'] = function( srcLine ) 



    return 'DW';
end,

['equ'] = function( srcLine ) 



    return 'EQU';
end,

['org'] = function( srcLine ) 

    return 'ORG';
end

};

-- End module
return M;
>


|
>
>
>



|
>



|
>



|
>
>



|
>
>
>



|
>
>
>



|
>







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
38
39
40
41
42
43
44
45
46
47
48
49
require('./symtab');

local M = {
['DB'] = function( lbl,mnem,op1,srcLine ) 
    Printf("%s\n", srcLine);
    symtab_addLabel( lbl );
    PC_add(1);
    return 'DB';
end,

['DL'] = function( lbl,mnem,op1,srcLine ) 
    Printf("%s\n", srcLine);
    return 'DL';
end,

['DM'] = function( lbl,mnem,op1,srcLine ) 
    Printf("%s\n", srcLine);
    return 'DM';
end,

['DS'] = function( lbl,mnem,op1,srcLine ) 
    Printf("%s\n", srcLine);
    symtab_addLabel( lbl );
    return 'DS';
end,

['DW'] = function( lbl,mnem,op1,srcLine ) 
    Printf("%s\n", srcLine);
    symtab_addLabel( lbl );
    PC_add(2);
    return 'DW';
end,

['EQU'] = function( lbl,mnem,op1,srcLine ) 
    Printf("%s\n", srcLine);
    symtab_add( lbl, tonumber(op1) );
    
    return 'EQU';
end,

['ORG'] = function( lbl,mnem,op1,srcLine ) 
    Printf("%s\n", srcLine);
    return 'ORG';
end

};

-- End module
return M;

Changes to opcodes.lua.

1
2
3
4
5
6
7
8
require('eval_op');

function do_ABS(f1, f2, f3) -- Intermingles with CMP, where Rx would be compared with itself.
    local retVal = { [0] = 0x70, 0x75, 0x7a, 0x7f };
    return retVal[ isReg(f2) ] ; 
end

function do_ADD(f1, f2, f3)  -- Note: it's OK to add a register to itself.
|







1
2
3
4
5
6
7
8
require('./eval_op');

function do_ABS(f1, f2, f3) -- Intermingles with CMP, where Rx would be compared with itself.
    local retVal = { [0] = 0x70, 0x75, 0x7a, 0x7f };
    return retVal[ isReg(f2) ] ; 
end

function do_ADD(f1, f2, f3)  -- Note: it's OK to add a register to itself.

Changes to symtab.lua.

5
6
7
8
9
10
11
12
13
14
15






16
17
18
19







20
21
22
23
24
25
26


local symtab = {};

function symtab_add(symbol,value)
    if( symtab[symbol] ) then
        print( "Redefining symbol" );
        os.exit();
    end
    symtab[symbol] = value;
end







function symtab_lookup(symbol)
    return( symtab[symbol] )
end








ProgramCounter = 0;

function PC_reset()
    ProgramCounter = 0;
end








|



>
>
>
>
>
>




>
>
>
>
>
>
>







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
38
39


local symtab = {};

function symtab_add(symbol,value)
    if( symtab[symbol] ) then
        print( "Redefining symbol" );
        -- os.exit();
    end
    symtab[symbol] = value;
end

function symtab_addLabel( label )
    label = label or ( '_L' .. PC_get() );
    if( label:sub(-1,-1) == ':' ) then label = label:sub(1,-2) end;
    symtab_add( label, ProgramCounter );
end

function symtab_lookup(symbol)
    return( symtab[symbol] )
end

function symtab_dump()
    Printf( "\n-------- SYMBOLS -------\n" );
    for k,v in pairs(symtab) do
        Printf("%32.32s : 0x%04x\n", k, v );
    end
end

ProgramCounter = 0;

function PC_reset()
    ProgramCounter = 0;
end