adding 16 bits registers

匆匆过客 提交于 2019-12-11 19:18:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!