MegaProcessor

Check-in [d58b8e25e9]
Login

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

Overview
Comment:Making instructions ld.[bw] and st.[bw] do the right thing.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:d58b8e25e99aff5bd347e5dce54fa63cf359d5a2
User & Date: jos 2015-09-22 14:48:39
Context
2015-09-24
17:08
Implemented translation of the BCHG,BCLR,BSET,BTST instructions. Todo, have '#' mode accept symbols besides of decimals. check-in: 5479a8adb6 user: jos tags: trunk
2015-09-22
14:48
Making instructions ld.[bw] and st.[bw] do the right thing. check-in: d58b8e25e9 user: jos tags: trunk
11:38
A little bit of cleanup. check-in: 69958f5974 user: jos tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to eval_op.lua.

110
111
112
113
114
115
116
117












118
            print("Undefined symbol");
            return( nil );
        end
        return( As_table( result ) );
    end

end--Eval()













--EOF--








>
>
>
>
>
>
>
>
>
>
>
>

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
            print("Undefined symbol");
            return( nil );
        end
        return( As_table( result ) );
    end

end--Eval()

function Eval_as_word(exp)
    local t = Eval(exp);
    if( #t == 1 ) then table.insert(t,0x00); end--if : append zero as most-significant byte.
    return t ;
end

function Eval_as_byte(exp)
    local t = Eval(exp);
    if( #t > 1 ) then Error("Byte operand expected"); end--if
    return t ;
end

--EOF--

Changes to opcodes.lua.

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
213
214
215
216
217
218


219


220
221
222
223
224
225
226
227
...
238
239
240
241
242
243
244


245


246
247
248
249
250
251
252
253
...
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410
end

function do_JMP(f1, f2, f3)
    if( f2:sub(1,1) == '(' ) then
        -- TODO check for (r0)
        return 0xf2 ;
    else
        local dst = Eval(f2);
        if( #dst == 1 ) then table.insert(dst,0x00); end--if
        return 0xf3, table.unpack(dst) ;
    end
end

function do_JSR(f1, f2, f3)
    if( f2:sub(1,1) == '(' ) then
        -- TODO check for (r0)
        return 0xce ;
    else

        return 0xcf,0x00,0x00 ;
    end
end


function do_LD_B(f1, f2, f3)
    local ind_dst = (f3:match('%b()')~=nil);
    local autoinc = (ind_dst and (f3:match('++')~=nil) );
    local stack = f3:match("[sS][pP]");

    local ourNr = isReg(f2);

    if( not ind_dst ) then
        if( f3:match('#') ) 


        then return 0xd4 + ourNr, 0x00;


        else return 0xb4 + ourNr, 0x00, 0x00;
        end;
    else
        if( stack ) then return 0xa4 + ourNr, 0x00; end;
        local ourNr2 = tonumber( f3:match("[23]") );
        if( ourNr2 == nil ) then
            Error(": Operand must be R2 or R3", 0 );
        end
................................................................................
    local autoinc = (ind_dst and (f3:match('++')~=nil) );
    local stack = f3:match("[sS][pP]");

    local ourNr = isReg(f2);

    if( not ind_dst ) then
        if( f3:match('#') ) 


        then return 0xd0 + ourNr, 0x00, 0x00;


        else return 0xb0 + ourNr, 0x00, 0x00;
        end;
    else
        if( stack ) then return 0xa0 + ourNr, 0x00; end;
        local ourNr2 = tonumber( f3:match("[23]") );
        if( ourNr2 == nil ) then
            Error("Operand must be R2 or R3");
        end
................................................................................
    local ind_dst = (f2:match('%b()')~=nil);
    local autoinc = (ind_dst and (f2:match('++')~=nil) );
    local stack = f2:match("[sS][pP]");

    local ourNr = isReg(f3);

    if( not ind_dst ) then

        return 0xbc + ourNr, 0x00, 0x00;  -- ST.B 0xWWWW,Rx ;
    else
        if( stack ) then return 0xac + ourNr, 0x00; end;  -- ST.B (SP,0xVV),Rx ;

        local ourNr2 = tonumber( f2:match("[23]") );
        if( ourNr2 == nil ) then
            Error("Operand must be R2 or R3");
        end







|
<









>
|













>
>
|
>
>
|







 







>
>
|
>
>
|







 







>
|







187
188
189
190
191
192
193
194

195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
...
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
...
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
end

function do_JMP(f1, f2, f3)
    if( f2:sub(1,1) == '(' ) then
        -- TODO check for (r0)
        return 0xf2 ;
    else
        local dst = Eval_as_word(f2);

        return 0xf3, table.unpack(dst) ;
    end
end

function do_JSR(f1, f2, f3)
    if( f2:sub(1,1) == '(' ) then
        -- TODO check for (r0)
        return 0xce ;
    else
        local dst = Eval_as_word(f2);
        return 0xcf, table.unpack(dst) ;
    end
end


function do_LD_B(f1, f2, f3)
    local ind_dst = (f3:match('%b()')~=nil);
    local autoinc = (ind_dst and (f3:match('++')~=nil) );
    local stack = f3:match("[sS][pP]");

    local ourNr = isReg(f2);

    if( not ind_dst ) then
        if( f3:match('#') ) 
        then 
            local dst = Eval_as_byte(f3:sub(2,-1))
            return 0xd4 + ourNr, table.unpack(dst) ;
        else 
            local dst = Eval_as_word(f3);
            return 0xb4 + ourNr, table.unpack(dst) ;
        end;
    else
        if( stack ) then return 0xa4 + ourNr, 0x00; end;
        local ourNr2 = tonumber( f3:match("[23]") );
        if( ourNr2 == nil ) then
            Error(": Operand must be R2 or R3", 0 );
        end
................................................................................
    local autoinc = (ind_dst and (f3:match('++')~=nil) );
    local stack = f3:match("[sS][pP]");

    local ourNr = isReg(f2);

    if( not ind_dst ) then
        if( f3:match('#') ) 
        then
            local dst = Eval_as_word(f3:sub(2,-1))
            return 0xd0 + ourNr, table.unpack(dst) ;
        else
            local dst = Eval_as_word(f3);
            return 0xb0 + ourNr, table.unpack(dst) ;
        end;
    else
        if( stack ) then return 0xa0 + ourNr, 0x00; end;
        local ourNr2 = tonumber( f3:match("[23]") );
        if( ourNr2 == nil ) then
            Error("Operand must be R2 or R3");
        end
................................................................................
    local ind_dst = (f2:match('%b()')~=nil);
    local autoinc = (ind_dst and (f2:match('++')~=nil) );
    local stack = f2:match("[sS][pP]");

    local ourNr = isReg(f3);

    if( not ind_dst ) then
        local dst = Eval_as_word(f2);
        return 0xbc + ourNr, table.unpack(dst) ;  -- ST.B 0xWWWW,Rx ;
    else
        if( stack ) then return 0xac + ourNr, 0x00; end;  -- ST.B (SP,0xVV),Rx ;

        local ourNr2 = tonumber( f2:match("[23]") );
        if( ourNr2 == nil ) then
            Error("Operand must be R2 or R3");
        end