Help me to convert assembly to c(or c++) language

Discussion in 'Embedded Systems and Microcontrollers' started by hijack911, Dec 27, 2009.

  1. hijack911

    Thread Starter New Member

    Dec 23, 2009
    4
    0
    My porject is: " Automatic Room Light Controller with Visitor Counter using Microcontroller." I've made it already in assemby but I can't run it in C.

    Please help me to convert assembly to C language!!! I'm very weak in C programming!:confused:
    Thanks all!
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    Out of curiosity, if it works as is, why does the code need to be translated to C?

    How do your sensors work?
     
  3. Papabravo

    Expert

    Feb 24, 2006
    10,144
    1,790
    It is always possible to transform C or C++ into assembly language. It is not possible in some cases to do the reverse.

    My counter example is anything having to do with the carry flag. Since C and C++ have no semantics for dealing with a "carry" flag or a "borrow" flag, or an "overflow" flag any assembly program written to manipulate numeric quantities that involves these flags may or may not be translatable.

    If you think about it for a minute there are many examples of irreversible operations.
     
  4. hijack911

    Thread Starter New Member

    Dec 23, 2009
    4
    0
    Thank to reply! But my advisor aks me to convert Assembly to C :(. I simulate a circuit on Proteus, it works very well. I mean that I replace sensor by switch(I'll press it to create 'pulse' to be considered people) for which delays to 0.2s. 0.2s is enough for people to cross sensors in reality.
     
  5. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    Probably the point of the exercise was so you would learn C.
     
  6. Papabravo

    Expert

    Feb 24, 2006
    10,144
    1,790
    It will be easier to write the application in C and not worry about doing a literal connversion. The point is to learn C, as Bill said.
     
  7. hijack911

    Thread Starter New Member

    Dec 23, 2009
    4
    0
    i hopse so, i'll try it again but somebody can give me an idea, can't it?
     
  8. Papabravo

    Expert

    Feb 24, 2006
    10,144
    1,790
    Well what exactly are you looking for in the way of ideas?

    For example, evaluating an expression involving addition, subtraction, multiplication, and division should be straightforward. Regular loops should be rendered as one of the three loop types:
    Code ( (Unknown Language)):
    1.  
    2. while([I]condition[/I])
    3.     [I]statement ;[/I]
    4.  
    5. do
    6.     [I]statement ;[/I]
    7. while ([I]condition) ;[/I]
    8.  
    9. for([I]initial; termination; increment)[/I]
    10. [I]  statement;[/I]
    11.  
    Conditional execution is done with if...else... statements or a switch statement.

    Probably your biggest challenge will be to redo irregular control transfers, often referred to as spaghetti code.
     
  9. hijack911

    Thread Starter New Member

    Dec 23, 2009
    4
    0
    I implement in C step by step.
    Thanks all and happy new year!. when i get a code C, i'll post it in forum where everybody can give me an advice for the best solution!
     
Loading...