☕ 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
  • 406
    Views
  • 1
    Participants
Last reply from:
fireclouu

Online now

Members online
1,044
Guests online
722
Total visitors
1,766

Forum statistics

Threads
2,276,975
Posts
28,973,480
Members
1,229,674
Latest member
Mjivo
Back
Top