☕ Java Two's complement, need help

Status
Not open for further replies.

fireclouu

Fanatic
Hello! May marunong po ba dito mag-perform ng two complement? Bali gumagawa po kasi ako ng intel 8080 emulation, pwede niyo po icheck sa git ko clouu-27 (pakitanggal na lang dash :) ), sa CpuEmulation.java, sa CMP method, eto partial:
Java:
private void CMP(int var) {

        // Need to perform two-complement to achieve such result        // a + (two comp. immediate)

        // complement — defined also as "another set" e.g. another set of binary 1 is binary 0!

        // similar to a - immediate

        // int twoComp = ((~opbyte & 0xff) + 1);

        int res = A.value - var;

       

        Z.flag = (res == 0) ? (byte) 1 : 0;

        S.flag = ((res & 0x80) == 0x80) ? (byte) 1 : 0;

        P.flag = parityFlag(res);  // ensuring only checks for 8-bit variable

        CY.flag = (res > 0xff ) ? 1 : (byte) 0;

        AC.flag = (res > 0x9) ? (byte) 1 : 0;

    }

workaround implementation po yung A.value - var;

kaya po need ng twos comp eh para makuha yung flags, (carry, zero, etc), tumingin na po ako sa internet kaso di ko talaga gets 'yung two's comp, ang alam ko lang "addition to subtract" raw, di ako makaadvance hehe. Thanks!
 
Status
Not open for further replies.

Similar threads

About this Thread

  • 1
    Replies
  • 419
    Views
  • 1
    Participants
Last reply from:
fireclouu

Trending Topics

Online now

Members online
989
Guests online
1,244
Total visitors
2,233

Forum statistics

Threads
2,292,976
Posts
29,080,485
Members
1,208,616
Latest member
sksksksksksksksk
Back
Top