Truth Tables and programming

Thread Starter

RiJoRI

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

Rich (BB code):
  ifgt   X,#0
   jp    p05
  ifbit  B
   jp    p10
p05:
  jsr    findbit
  jp     p20
p10:
  jsr    ofindbit
p20:
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.

Rich (BB code):
          B
   \   0     1
X 0   p05   p10
 >0   p05   p05
All of a sudden, it all came clear:
Rich (BB code):
if((X==0) && (B==1)
  ofindbit();
else
  findbit()
I hope this can help someone else. Actually, I hope no one else needs to convert ASM to C!!

--Rich
 
Top