Skip to content

Commit

Permalink
implemented MOV r/m8, imm8
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonjs committed Jan 21, 2010
1 parent b3dad0b commit 7ee7b8e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion asm/binary.rb
Expand Up @@ -526,7 +526,7 @@ def log2(x, tol=1e-13)
end


# 8 versions of the mov instruction are supported:
# 9 versions of the mov instruction are supported:
# 1. mov reg32, immediate32
# 2a. mov reg32, r/m32
# 2b. mov eax, memoffset32
Expand All @@ -535,6 +535,7 @@ def log2(x, tol=1e-13)
# 4. mov r/m32, immediate32
# 5. mov r/m8, reg8
# 6. mov reg8, r/m8
# 7. mov r/m8, imm8
def mov(dest, src)

# These 2 are used in the same way, just the name differs to make the
Expand Down Expand Up @@ -590,11 +591,19 @@ def mov(dest, src)
opcode = 0x8a
modrm = [src, dest.regnum]

# version 7: mov r/m8, imm8
elsif rm?(dest, :byte) && immediate?(src, :byte)
opcode = 0xc6
modrm = [dest, 0]
immediate_byte = src

else
# puts "rm?(dest): #{rm?(dest)}\t\trm?(src): #{rm?(src)}"
# puts "register?(dest): #{register?(dest)}\t\tregister?(src): #{register?(src)}"
# puts "immediate?(dest): #{immediate?(dest)}\t\timmediate?(src): #{immediate?(src)}"
# puts "offset?(dest): #{offset?(dest)}\t\toffset?(src): #{offset?(src)}"
# puts "rm?(dest, :byte): #{rm?(dest)}\t\trm?(src, :byte): #{rm?(src, :byte)}"
# puts "immediate?(dest, :byte): #{immediate?(dest)}\t\timmediate?(src, :byte): #{immediate?(src, :byte)}"
raise "unsupported MOV instruction, #{dest.inspect}, #{src.inspect}"
end

Expand All @@ -603,14 +612,20 @@ def mov(dest, src)
asm do
emit_byte(opcode)
emit_modrm(*modrm) if modrm

if dword.is_a?(VariableProxy)
if dword.const?
emit_const(dword)
else
emit_var(dword)
end

elsif dword
emit_dword(dword)

elsif immediate_byte
emit_byte(immediate_byte)

end
end
end
Expand Down

0 comments on commit 7ee7b8e

Please sign in to comment.