MegaProcessor

Check-in [34e6793e25]
Login

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

Overview
Comment:Have the EQU directive only handled in pass 1, and fix a list-file issue for the ORG directive.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:34e6793e259b673e32100e6192b27903be8a4884
User & Date: jos 2015-08-22 17:59:52
Context
2015-08-22
18:12
DRYed up the output of listing-file lines. check-in: dcc9eecbd2 user: jos tags: trunk
17:59
Have the EQU directive only handled in pass 1, and fix a list-file issue for the ORG directive. check-in: 34e6793e25 user: jos tags: trunk
16:18
A little extra in the symbol-table dump : decimal format besides hex. check-in: 6dba3c8041 user: jos tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to asm.lua.

48
49
50
51
52
53
54








55
56
57
58
59
60
61
62
63
64
65





66
67
68
69
70
71
72
..
79
80
81
82
83
84
85
86
87
88
89
90


91



92
93
94
95
96
97
98
        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 Pass1_line( l ) -- Processing for pass 1, gathering of all symbols and labels.
    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 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
        if( label ) then symtab_addLabel(label) end;
................................................................................

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

    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); Printf("%s : %s\n",PC_get(),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







>
>
>
>
>
>
>
>




<






>
>
>
>
>







 







|




>
>
|
>
>
>







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
..
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
        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 handle_EQU(label,op1)
    if( label == nil ) then Error("EQU must have a label"); end;
    if( op1 == nil ) then Error("EQU must have a value"); end;
     
    if( op1 == "$" ) then op1 = '0x' .. PC_get(); end;
    symtab_add( label, tonumber(op1) ); 
end 

function Pass1_line( l ) -- Processing for pass 1, gathering of all symbols and labels.
    local asm_instr;
    local n,label,Mnemonic,op1,op2 = Fields(l);

    local insLen = 0;

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

    Mnemonic = Mnemonic:upper();

    if( Mnemonic == "EQU" ) then 
        handle_EQU(label,op1); 
        return 
    end;

    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
        if( label ) then symtab_addLabel(label) end;
................................................................................

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

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

    Mnemonic = Mnemonic:upper();

    asm_instr = Directive[ Mnemonic ];
    if( asm_instr ) then -- ORG is a special case, listing output must reflect value of PC after evaluation
        if(Mnemonic ~= 'ORG') then Printf("%s : %s\n",PC_get(),l); end;--if
        asm_instr(label,Mnemonic,op1,l); 
        if(Mnemonic == 'ORG') then Printf("%s : %s\n",PC_get(),l); end;--if
        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

Changes to asm_instr.lua.

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
['DW'] = function( lbl,mnem,op1,srcLine ) 
    -- Printf("DW %s\n", srcLine);
    if( lbl ~= nil and AssemblerPass==1 ) then symtab_addLabel( lbl ); end;
    PC_add(2);
    return 'DW';
end,

['EQU'] = function( lbl,mnem,op1,srcLine ) 
    if( op1 == "$" ) then op1 = PC_get(); end;

    if( lbl ~= nil and AssemblerPass==1 ) then symtab_add( lbl, op1 ); end;
    
    return 'EQU';
end,

['ORG'] = function( lbl,mnem,op1,srcLine ) 
    PC_set( tonumber(op1) ); -- TODO more advanced evaluation of op1.
    if( lbl ~= nil and AssemblerPass==1 ) then symtab_addLabel( lbl ); end;
    return 'ORG';
end

};

-- End module
return M;







<
<
<
<
<
<
<











31
32
33
34
35
36
37







38
39
40
41
42
43
44
45
46
47
48
['DW'] = function( lbl,mnem,op1,srcLine ) 
    -- Printf("DW %s\n", srcLine);
    if( lbl ~= nil and AssemblerPass==1 ) then symtab_addLabel( lbl ); end;
    PC_add(2);
    return 'DW';
end,









['ORG'] = function( lbl,mnem,op1,srcLine ) 
    PC_set( tonumber(op1) ); -- TODO more advanced evaluation of op1.
    if( lbl ~= nil and AssemblerPass==1 ) then symtab_addLabel( lbl ); end;
    return 'ORG';
end

};

-- End module
return M;