Truth Tables and programming

Discussion in 'Programmer's Corner' started by RiJoRI, Sep 4, 2008.

  1. RiJoRI

    Thread Starter Well-Known Member

    Aug 15, 2007
    536
    26
    I was trying to "C-ify" some code, and came across the following:

    Code ( (Unknown Language)):
    1.  
    2.   ifgt   X,#0
    3.    jp    p05
    4.   ifbit  B
    5.    jp    p10
    6. p05:
    7.   jsr    findbit
    8.   jp     p20
    9. p10:
    10.   jsr    ofindbit
    11. p20:
    12.  
    I struggled for a while with IF-ELSE, and gave up. Looking at the problem, I saw there were only two variables, so I tried a truth table.

    Code ( (Unknown Language)):
    1.  
    2.           B
    3.    \   0     1
    4. X 0   p05   p10
    5.  >0   p05   p05
    6.  
    All of a sudden, it all came clear:
    Code ( (Unknown Language)):
    1.  
    2. if((X==0) && (B==1)
    3.   ofindbit();
    4. else
    5.   findbit()
    6.  
    I hope this can help someone else. Actually, I hope no one else needs to convert ASM to C!!

    --Rich
     
Loading...