Added MOV (8 bits version) instruction.

This commit is contained in:
mooz 2018-11-10 00:23:56 +01:00
parent 6708ddaecc
commit 2d96e4e1d2
3 changed files with 83 additions and 21 deletions

View File

@ -40,7 +40,7 @@ local Keywords_data = {
local Keywords_7801 = {
'aci','adi','adinc','ani',
'block','calb','calf','call','calt','clc','ei','eqi','daa','di','dcr','dcx',
'ex','exx','gti','halt','inr','inx','jb','jmp','jr','lti','lxi','mvi','nei','nop',
'ex','exx','gti','halt','inr','inx','jb','jmp','jr','lti','lxi','mov','mvi','nei','nop',
'offi','oni','ori','pen','per','pex','ret','reti','rets','rld','rrd','sio','softi','stc','stm',
'sbi','sui','suinb','table','xri',
}
@ -80,6 +80,9 @@ local opcode_relative = lookupify{
local opcode_reg = lookupify{
'dcr','dcx','inr','inx'
}
local opcode_reg_reg = lookupify{
'mov'
}
local opcode_regb = lookupify{
'aci','adi','adinc','ani','eqi','gti','lti','mvi','nei','offi','oni','ori','sbi','sui','suinb','xri',
}
@ -101,6 +104,36 @@ local opcode_reg_list = {
sp = lookupify{'dcx','inx','lxi'},
}
local opcode_reg_reg_list = {
a = {
b = lookupify{'mov'},
c = lookupify{'mov'},
d = lookupify{'mov'},
e = lookupify{'mov'},
h = lookupify{'mov'},
l = lookupify{'mov'},
},
b = {
a = lookupify{'mov'},
},
c = {
a = lookupify{'mov'},
},
d = {
a = lookupify{'mov'},
},
e = {
a = lookupify{'mov'},
},
h = {
a = lookupify{'mov'},
},
l = {
a = lookupify{'mov'},
},
v = {},
}
local addressing_map = {
imp = opcode_implied,
imm = opcode_immediate,
@ -1415,7 +1448,26 @@ local function ParseLua(src, src_name)
end
stat = emit_call{name=op, args={expr, mod_expr}, inverse_encapsulate=inverse_encapsulate, paren_open_white=paren_open_whites} break
end
if opcode_reg[op] or opcode_regb[op] or opcode_regw[op] then
if opcode_reg_reg[op] then
tok:Save()
local r0_name = tok:Get(tokenList).Data
if not Registers_7801[r0_name] then tok:Restore()
return false, GenerateError(r0_name .. " is not a valid register")
end
if not tok:ConsumeSymbol(',', tokenList) then tok:Restore()
return false, GenerateError("Opcode " .. op .. " doesn't support this addressing mode")
end
local r1_name = tok:Get(tokenList).Data
if not Registers_7801[r1_name] then tok:Restore()
return false, GenerateError(r0_name .. " is not a valid register")
end
if not (opcode_reg_reg_list[r0_name] and opcode_reg_reg_list[r0_name][r1_name] and opcode_reg_reg_list[r0_name][r1_name][op]) then
tok:Restore()
return false, GenerateError("Opcode " .. op .. " doesn't support this addressing mode")
end
tok:Commit()
stat = emit_call{name=op .. r0_name .. r1_name} break
elseif opcode_reg[op] or opcode_regb[op] or opcode_regw[op] then
tok:Save()
local register_name = tok:Get(tokenList).Data
local call_args = {name=op..register_name}

View File

@ -64,5 +64,18 @@ section{"rom", org=0x8000}
rld
rrd
stc
mov a,b
mov a,c
mov a,d
mov a,e
mov a,h
mov a,l
mov b,a
mov c,a
mov d,a
mov e,a
mov h,a
mov l,a
writebin(filename .. '.bin')

View File

@ -114,6 +114,20 @@ for k,v in pairs(opaxx) do
end
end
local opr8r8 ={
movab=M.op(0x0a,4), movac=M.op(0x0b,4),
movad=M.op(0x0c,4), movae=M.op(0x0d,4),
movah=M.op(0x0e,4), moval=M.op(0x0f,4),
movba=M.op(0x1a,4), movca=M.op(0x1b,4),
movda=M.op(0x1c,4), movea=M.op(0x1d,4),
movha=M.op(0x1e,4), movla=M.op(0x1f,4),
} M.opr8r8 = opr8r8
for k,v in pairs(opr8r8) do
M[k] = function()
table.insert(M.section_current.instructions, { size=1, cycles=v.cycles, bin=v.opc })
end
end
local opw = {
call=M.op(0x44,16),
jmp=M.op(0x54,10),
@ -216,16 +230,7 @@ return M
8 bits instructions:
JRE+ 0x4e xx 17
JRE- 0x4f xx 17
ani
ori
gti
lti
oni
offi
nei
mvi
eqi
-- d
ldaxm=M.op(0x2e,7),
ldaxp=M.op(0x2c,7),
@ -252,14 +257,6 @@ return M
bit6=M.op(0x5e,10),
bit7=M.op(0x5f,10)
-- r8,r8
movab=M.op(0x0a,4), movac=M.op(0x0b,4),
movad=M.op(0x0c,4), movae=M.op(0x0d,4),
movah=M.op(0x0e,4), moval=M.op(0x0f,4),
movba=M.op(0x1a,4), movca=M.op(0x1b,4),
movda=M.op(0x1c,4), movea=M.op(0x1d,4),
movha=M.op(0x1e,4), movla=M.op(0x1f,4),
-- hhll
call=M.op(0x44,16),
jmp=M.op(0x54,10),