Question

xor ebx,ebx
mov bh ,0x04 ;how to change that "bh" to "ebx" ,and keep  codes  same meaning?

and why people always use xor instead of mov XXX,0 ?

Was it helpful?

Solution

xor ebx,ebx mov bh ,0x04;how to change that "bh" to "ebx" ,and keep codes same meaning?

Assuming I understand you correctly, what you want is this:

mov ebx, 0x0400

(bh is the upper 8 bits of bx, which is itself the lower 16 bits of ebx. So the value you need is the original value shifted left by 8, which we get by adding two hex 0 digits).

why people always use xor instead of mov XXX,0 ?

To put it simply: because it's shorter and faster. See What is the purpose of XORing a register with itself? and Does using xor reg, reg give advantage over mov reg, 0?

OTHER TIPS

Since bh is the second lowest byte of ebx, you can just do mov ebx, 0x0400.

xor is used because it's shorter opcode and the processors have special support to recognize it as zeroing the register. See the optimization manual, section 3.5.1.8 Clearing Registers and Dependency Breaking Idioms.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top