Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

implemented MOV r/m8, imm8

  • Loading branch information...
commit 7ee7b8ec488db3310061f34d76311cf02a41408e 1 parent b3dad0b
@samsonjs authored
Showing with 16 additions and 1 deletion.
  1. +16 −1 asm/binary.rb
View
17 asm/binary.rb
@@ -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
@@ -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
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.