Added support for Immediate addressing mode

Adding support for Immediate add mode, need to check how 32 bits is returned, currently followed the displacement method.
This commit is contained in:
niravthakkar 2016-12-02 12:55:43 +05:30 committed by GitHub
parent 1b7ded5474
commit 4c7e494e0a

View File

@ -289,6 +289,10 @@ local function is_int20(num)
return -shl(1, 19) <= num and num < shl(1, 19) return -shl(1, 19) <= num and num < shl(1, 19)
end end
local function is_int32(num)
return -shl(1,31) <= num and num <shl(1,31)
end
-- Split a memory operand of the form d(b) or d(x,b) into d, x and b. -- Split a memory operand of the form d(b) or d(x,b) into d, x and b.
-- If x is not specified then it is 0. -- If x is not specified then it is 0.
local function split_memop(arg) local function split_memop(arg)
@ -366,6 +370,14 @@ local function parse_mem_by(arg)
return d, b, a return d, b, a
end end
local function parse_imm(arg)
local imm_val = tonumber(arg,16)
if not is_int32(imm_val) then
werror("Immediate value out of range: ", imm_val)
end
return imm_val
end
local function parse_label(label, def) local function parse_label(label, def)
local prefix = sub(label, 1, 2) local prefix = sub(label, 1, 2)
-- =>label (pc label reference) -- =>label (pc label reference)
@ -1047,7 +1059,9 @@ local function parse_template(params, template, nparams, pos)
elseif p == "m" then elseif p == "m" then
elseif p == "n" then elseif p == "n" then
op0 = op0 + shl(parse_gpr(params[1], 4)
local imm = parse_imm(param[2])
wputhw(op0); waction("IMM32", nil, imm)
elseif p == "q" then elseif p == "q" then
local d, b, a = parse_mem_b(params[3]) local d, b, a = parse_mem_b(params[3])
op1 = op1 + shl(parse_gpr(params[1]), 4) + parse_gpr(params[2]) op1 = op1 + shl(parse_gpr(params[1]), 4) + parse_gpr(params[2])