Convert C code into assembly PIC12F508

Discussion in 'Embedded Systems and Microcontrollers' started by Vindhyachal Takniki, Nov 18, 2014.

  1. Vindhyachal Takniki

    Thread Starter Member

    Nov 3, 2014
    348
    6
    1. I have written code for PIC12F508. Code has 3 C files & 4 header files.
    Code compiles successfully.

    2. I need to convert into assembly. First thing came into mind is to check diasssembly.
    Below is the part of disassembly code & c code comments removed from it:

    Code (Text):
    1.  
    2.    00F     A9F     GOTO 0x9f
    3.  
    4.    0A0     912     CALL 0x12
    5.  
    6.    0A1     800     RETLW 0
    7.  
    8.    013     A9E     GOTO 0x9e
    9.    014     FFF     XORLW 0xff
    10.    015     FFF     XORLW 0xff
    11.    016     FFF     XORLW 0xff
    12.    017     FFF     XORLW 0xff
    13.    018     FFF     XORLW 0xff
    14.    019     FFF     XORLW 0xff
    15.    01A     FFF     XORLW 0xff
    16.    01B     FFF     XORLW 0xff
    17.    01C     FFF     XORLW 0xff
    18.    01D     FFF     XORLW 0xff
    19.    01E     FFF     XORLW 0xff
    20.    01F     FFF     XORLW 0xff
    21.    020     FFF     XORLW 0xff
    22.    021     FFF     XORLW 0xff
    23.    022     FFF     XORLW 0xff
    24.    023     FFF     XORLW 0xff
    25.    024     FFF     XORLW 0xff
    26.    025     FFF     XORLW 0xff
    27.    026     FFF     XORLW 0xff
    28.    027     FFF     XORLW 0xff
    29.    028     FFF     XORLW 0xff
    30.    029     FFF     XORLW 0xff
    31.    02A     FFF     XORLW 0xff
    32.    02B     FFF     XORLW 0xff
    33.    02C     FFF     XORLW 0xff
    34.    02D     FFF     XORLW 0xff
    35.    02E     FFF     XORLW 0xff
    36.    02F     FFF     XORLW 0xff
    37.    030     FFF     XORLW 0xff
    38.    031     FFF     XORLW 0xff
    39.    032     FFF     XORLW 0xff
    40.    033     FFF     XORLW 0xff
    41.    034     FFF     XORLW 0xff
    42.    035     FFF     XORLW 0xff
    43.    036     FFF     XORLW 0xff
    44.    037     FFF     XORLW 0xff
    45.    038     FFF     XORLW 0xff
    46.    039     FFF     XORLW 0xff
    47.    03A     FFF     XORLW 0xff
    48.    03B     FFF     XORLW 0xff
    49.    03C     FFF     XORLW 0xff
    50.    03D     FFF     XORLW 0xff
    51.    03E     FFF     XORLW 0xff
    52.    03F     FFF     XORLW 0xff
    53.    040     FFF     XORLW 0xff
    54.    041     FFF     XORLW 0xff
    55.    042     FFF     XORLW 0xff
    56.    043     FFF     XORLW 0xff
    57.    044     FFF     XORLW 0xff
    58.    045     FFF     XORLW 0xff
    59.    046     FFF     XORLW 0xff
    60.    047     FFF     XORLW 0xff
    61.    048     FFF     XORLW 0xff
    62.    049     FFF     XORLW 0xff
    63.    04A     FFF     XORLW 0xff
    64.    04B     FFF     XORLW 0xff
    65.    04C     FFF     XORLW 0xff
    66.    04D     FFF     XORLW 0xff
    67.    04E     FFF     XORLW 0xff
    68.    04F     FFF     XORLW 0xff
    69.    050     FFF     XORLW 0xff
    70.    051     FFF     XORLW 0xff
    71.    052     FFF     XORLW 0xff
    72.    053     FFF     XORLW 0xff
    73.    054     FFF     XORLW 0xff
    74.    055     FFF     XORLW 0xff
    75.    056     FFF     XORLW 0xff
    76.    057     FFF     XORLW 0xff
    77.    058     FFF     XORLW 0xff
    78.    059     FFF     XORLW 0xff
    79.    05A     FFF     XORLW 0xff
    80.    05B     FFF     XORLW 0xff
    81.    05C     FFF     XORLW 0xff
    82.    05D     FFF     XORLW 0xff
    83.    05E     FFF     XORLW 0xff
    84.    05F     FFF     XORLW 0xff
    85.    060     FFF     XORLW 0xff
    86.    061     FFF     XORLW 0xff
    87.    062     FFF     XORLW 0xff
    88.    063     FFF     XORLW 0xff
    89.    064     FFF     XORLW 0xff
    90.    065     FFF     XORLW 0xff
    91.    066     FFF     XORLW 0xff
    92.    067     FFF     XORLW 0xff
    93.    068     FFF     XORLW 0xff
    94.    069     FFF     XORLW 0xff
    95.    06A     FFF     XORLW 0xff
    96.    06B     FFF     XORLW 0xff
    97.    06C     FFF     XORLW 0xff
    98.    06D     FFF     XORLW 0xff
    99.    06E     FFF     XORLW 0xff
    100.    06F     FFF     XORLW 0xff
    101.    070     FFF     XORLW 0xff
    102.    071     FFF     XORLW 0xff
    103.    072     FFF     XORLW 0xff
    104.    073     FFF     XORLW 0xff
    105.    074     FFF     XORLW 0xff
    106.    075     FFF     XORLW 0xff
    107.    076     FFF     XORLW 0xff
    108.    077     FFF     XORLW 0xff
    109.    078     FFF     XORLW 0xff
    110.    079     FFF     XORLW 0xff
    111.    07A     FFF     XORLW 0xff
    112.    07B     FFF     XORLW 0xff
    113.    07C     FFF     XORLW 0xff
    114.    07D     FFF     XORLW 0xff
    115.    07E     FFF     XORLW 0xff
    116.    07F     FFF     XORLW 0xff
    117.    080     FFF     XORLW 0xff
    118.    081     FFF     XORLW 0xff
    119.    082     FFF     XORLW 0xff
    120.    083     FFF     XORLW 0xff
    121.    084     FFF     XORLW 0xff
    122.    085     FFF     XORLW 0xff
    123.    086     FFF     XORLW 0xff
    124.    087     FFF     XORLW 0xff
    125.    088     FFF     XORLW 0xff
    126.    089     FFF     XORLW 0xff
    127.    08A     FFF     XORLW 0xff
    128.    08B     FFF     XORLW 0xff
    129.    08C     FFF     XORLW 0xff
    130.    08D     FFF     XORLW 0xff
    131.    08E     FFF     XORLW 0xff
    132.    08F     FFF     XORLW 0xff
    133.    090     FFF     XORLW 0xff
    134.    091     FFF     XORLW 0xff
    135.    092     FFF     XORLW 0xff
    136.    093     FFF     XORLW 0xff
    137.    094     FFF     XORLW 0xff
    138.    095     FFF     XORLW 0xff
    139.    096     FFF     XORLW 0xff
    140.    097     FFF     XORLW 0xff
    141.    098     FFF     XORLW 0xff
    142.    099     FFF     XORLW 0xff
    143.    09A     FFF     XORLW 0xff
    144.    09B     FFF     XORLW 0xff
    145.    09C     FFF     XORLW 0xff
    146.    09D     FFF     XORLW 0xff
    147.  
    148.    09E     800     RETLW 0
    149.  
    150.    0A2     90F     CALL 0xf
    151.  
    152.    0A3     90E     CALL 0xe
    153.  
    154.    0A4     AA4     GOTO 0xa4
    155.  
    156.    0A5     C20     MOVLW 0x20
    157.  

    3. If I copy code as it in assembly will it work??

    4. Any other method to convert c code to assembly.

    5. For code I am using MPLAB & Hi-tech C
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    1. That's nice.
    2. That's what I'd do
    3. It should.
    4. You could interpret the functionality of the C code and write the assembly version yourself.
    5. Okay.
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    #3 is a bit trickier. Your dissassembly listing gives line numbers and op codes. These need to be removed as they are not legal assembly constructs. Then it should build no trouble, but...

    The trouble will commence when your professor looks at your uncommented code and immediately deduces you skipped the assignment to write something in assembler but instead wrote it in another language. Sure, "CALL 0xe" is a legal statement, but no one ever wrote that in any assembler program ever.

    Method described by tshuck in #4 would work best for even a chance at a passing grade.
     
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Yes, if you are attempting to turn in a disassembled code for an assignment requiring you write in assembly, you'll find yourself being easily found out - you'd be better served actually learning the material.

    There exists plenty of material to learn assembly from (Nigel's PIC tutorial comes to mind).
     
  5. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    I wouldnt be sure on that. But as mentioned, it makes it clear the code is compiler generated.
     
  6. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,675
    2,722
    Says you. I used to hand assemble Z80 code into machine code for later POKEing into Basic programs. Granted, I've never typed the exact address "0xe", but i have coded calls to specific addresses -- often.
     
  7. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,796
    831
    Ditto! And on a Z80. Asynch comms emulating a Western Union TWX network terminal coded in assembly.
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Not on your first pass. You wrote a symbolic address, and once you discovered (counted) where that was going to be you went back and wrote the address next to the op code.

    I had the luxury of banging my op codes into my Timex Sinclair that I'd built an EPROM programmer onto (and one 'E' is not a mistake), then transfer that over to my Z80 platform.
     
Loading...