问题
I have this code
addInt:
add cx, bx
cmp cx, 0FFFFh
JBE convert
I'm trying to add cx and bx registers, each have the same value of FFFF, instead of getting 1FFFE, I get only FFFE, and when I try to use JBE to jump to convert loop, JBE istruction does nothing because ecx register now contain only FFFE, but not 1FFF, so how can i fix this code to make ecx contain 1FFFE and how do I compare to check if it is still 16 bits or not. I cannot use any 32 bits registers which make thing more complicated
Thank in advance
回答1:
addInt:
clc ;clear carry flag
add cx,bx
jnc convert ;jump no carry
cmp cx,FFFEh ;This now needs to be true, only FFFF+FFFF will succeed
because it generates a carry AND matches the cmp
Jnz convert ;will let it through
This will work, but it's very limited and simplistic
To "count" the carry use adc dx,0 inserted after jnc convert
The carry flag is set if a register goes round the clock, so it acts like a single bit
ADD FFFF+2 will set it off, giving you a +ve carry flag and 0001 in the register
You can store that flag count in a separate register with adc [other register],0
using the carry flag allows you slap your registers together to count up to something like
1,208,741,363,432,547,555,475,424 with 4x16 bit registers
which is quite a lot and miles better than 65,534
来源:https://stackoverflow.com/questions/16641366/adding-16-bits-registers