Suppose I have a number in bh, how do I add it to ecx? I cannot just
add ecx, bh
since it will cause an error:
invalid combination of opcode and operands
because ecx is a 32 bit register and bh is an 8 bit register.
If it's ok to modify ebx, then for unsigned add:
movzx ebx,bh
add ecx,ebx
and for signed add:
movsx ebx,bh
add ecx,ebx
if it's not ok to modify ebx, then for unsigned add:
add cl,bh
jnc nocarry0
add ecx,0100h
nocarry0:
or just use the first two examples preceded by push ebx, and followed by pop ebx.
You can't add values of different sizes (the CPU doesn't support it). Instead, try something like this:
movzx ebx,bl ;Zero-extend BL
add ecx,ebx
Note: For signed numbers you can also use movsx
to sign-extend.
unsigned add:
add cl,bh
adc ecx,0100h
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.