Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Indika Herath
01/13/06 08:29
Read: 507 times
Sri Lanka

#107300 - Reply about ADD/ADDC in a VB project
Responding to: Joseph Hebert's previous message
Sorry for the confusion
CY ,AC ,OV were user defined functions that has the format
In VB [Name(State as Boolean)] equal in C to [void name(Bool state);]

I wrote these functions to set the correct bits in PSW in the simulator.

So if I want to set the OV flag
In VB [OV(True)] equal in C to [OV(1);]

Can you give me a mathematical algorithm to perform the ADD,ADDC,SUBB functions in C or Visual Basic including Altering of the state flags ?

My current definition for ADD function is this (in VB)

Public Function ADD8(ByVal Op1 As Byte, ByVal Op2 As Byte, Optional ByVal Op3 As Byte = 0) As Byte
Dim i As Integer
i = CInt(Op1) + CInt(Op2) + CInt(Op3)

ADD8 = LOW8(i)

AC (LOW4(Op1) + LOW4(Op2) + Op3) > 15
CY i > &HFF
OV (i > &HFF) Xor (((Op1 And &H7F) + (Op2 And &H7F) + Op3) > &H7F)

End Function

SFR is a structure that hold individual register values
To perform ADD A,R0


To perform ADDC A,R0

GetCarry() is also a user defined function that returns the state of the carry flag as 1 or 0

Also in vb the Hex notation is different
&HFF is equal in c to FFh
&H7F is equal in c to 7Fh

I hope this information will give you a clear view.

Thank you!

List of 7 messages in thread
Help about ADD/ADDC in a VB project      Indika Herath      01/11/06 08:52      
   all answers are in "the bible"      Erik Malund      01/11/06 09:04      
   CY AC and OC      Joseph Hebert      01/11/06 09:12      
      Reply about ADD/ADDC in a VB project      Indika Herath      01/13/06 08:29      
         AGAIN: why reinvent the wheel?      Erik Malund      01/13/06 09:12      
   did you consider      Erik Malund      01/11/06 09:27      
      He's writing a simulator?      Joseph Hebert      01/11/06 09:53      

Back to Subject List