Tutorial by Examples

The obvious way to zero a register is to MOV in a 0—for example: B8 00 00 00 00 MOV eax, 0 Notice that this is a 5-byte instruction. If you are willing to clobber the flags (MOV never affects the flags), you can use the XOR instruction to bitwise-XOR the register with itself: 33 C0 ...
Background If the Carry (C) flag holds a value that you want to put into a register, the naïve way is to do something like this: mov al, 1 jc NotZero mov al, 0 NotZero: Use 'sbb' A more direct way, avoiding the jump, is to use "Subtract with Borrow": sbb al,a...
Background To find out if a register holds a zero, the naïve technique is to do this: cmp eax, 0 But if you look at the opcode for this, you get this: 83 F8 00 cmp eax, 0 Use test test eax, eax ; Equal to zero? Examine the opcode you get: 85 c0 test ea...
In 32-bit Linux, system calls are usually done by using the sysenter instruction (I say usually because older programs use the now deprecated int 0x80) however, this can take up quite alot of space in a program and so there are ways that one can cut corners in order to shorten and speed things up. ...
Background To get the product of a register and a constant and store it in another register, the naïve way is to do this: imul ecx, 3 ; Set ecx to 5 times its previous value imul edx, eax, 5 ; Store 5 times the contend of eax in edx Use lea Multiplications are expensive operation...

Page 1 of 1