Difference between revisions of "Simple Instructions"

From SkullSecurity
Jump to navigation Jump to search
(New page: {{Infobox assembly}})
 
Line 1: Line 1:
{{Infobox assembly}}
{{Infobox assembly}}
== Moving Data Around ==
The commands in this section deal with moving around numbers and pointers.
=== mov, movsx, movzx ===
''mov'' is the command used for assignment, much like the "=" sign in most languages. mov can move data between a register and memory, two registers, or a constant to a register. Here are some examples:
mov eax, 1  ; set eax to 1 (eax = 1)
mov edx, ecx ; set edx to whatever ecx is (edx = ecx)
mov eax, 18h ; set eax to 0x18
''movsx'' and ''movzx'' are special versions of mov which are designed to be used between signed (movsx) and unsigned (movzx) registers of different sizes.
''movsx'' means ''move with sign extension''. The data is moved from a smaller register into a bigger register, and the sign is preserved by either padding with 0's (for positive values) or F's (for negative values). Here are some examples:
* '''0x1000''' becomes '''0x00001000''', since it was positive
* '''0x7FFF''' becomes '''0x00007FFF''', since it was positive
* '''0xFFFF''' becomes '''0xFFFFFFFF''', since it was negative (note that 0xFFFF is -1 in 16-bit signed, and 0xFFFFFFFF is -1 in 32-bit signed)
* '''0x8000''' becomes '''0xFFFF8000''', since it was negative (note that 0x8000 is -32768 in 16-bit signed, and 0xFFFF8000 is -32768 in 32-bit signed)
''movzx'' means ''move with zero extension''. The data is moved from a smaller register into a bigger register, and the sign is ignored. Here are some examples:
* '''0x1000''' becomes '''0x00001000'''
* '''0x7FFF''' becomes '''0x00007FFF'''
* '''0xFFFF''' becomes '''0x0000FFFF'''
* '''0x8000''' becomes '''0x00008000'''
=== lea ===
''lea'' is very similar to mov, except that math can be done on the original value before it's used. The "[" and "]" characters always surround the second parameter, but in this case they don't indicate dereferencing (which will be explained later), it's easiest to think of them as just being part of the formula.
== Math and Logic ==
=== add, sub ===
=== inc, dec ===
=== and, or, xor ===
=== neg ===
=== mul, div ===
== Pointers and Dereferencing==

Revision as of 20:31, 12 March 2007

Assembly Language Tutorial
Please choose a tutorial page:

Moving Data Around

The commands in this section deal with moving around numbers and pointers.

mov, movsx, movzx

mov is the command used for assignment, much like the "=" sign in most languages. mov can move data between a register and memory, two registers, or a constant to a register. Here are some examples:

mov eax, 1   ; set eax to 1 (eax = 1)
mov edx, ecx ; set edx to whatever ecx is (edx = ecx)
mov eax, 18h ; set eax to 0x18

movsx and movzx are special versions of mov which are designed to be used between signed (movsx) and unsigned (movzx) registers of different sizes.

movsx means move with sign extension. The data is moved from a smaller register into a bigger register, and the sign is preserved by either padding with 0's (for positive values) or F's (for negative values). Here are some examples:

  • 0x1000 becomes 0x00001000, since it was positive
  • 0x7FFF becomes 0x00007FFF, since it was positive
  • 0xFFFF becomes 0xFFFFFFFF, since it was negative (note that 0xFFFF is -1 in 16-bit signed, and 0xFFFFFFFF is -1 in 32-bit signed)
  • 0x8000 becomes 0xFFFF8000, since it was negative (note that 0x8000 is -32768 in 16-bit signed, and 0xFFFF8000 is -32768 in 32-bit signed)

movzx means move with zero extension. The data is moved from a smaller register into a bigger register, and the sign is ignored. Here are some examples:

  • 0x1000 becomes 0x00001000
  • 0x7FFF becomes 0x00007FFF
  • 0xFFFF becomes 0x0000FFFF
  • 0x8000 becomes 0x00008000

lea

lea is very similar to mov, except that math can be done on the original value before it's used. The "[" and "]" characters always surround the second parameter, but in this case they don't indicate dereferencing (which will be explained later), it's easiest to think of them as just being part of the formula.


Math and Logic

add, sub

inc, dec

and, or, xor

neg

mul, div

Pointers and Dereferencing