Thread: C codes for reading ASM file

  1. #1
    Registered User khpuce's Avatar
    Join Date
    May 2003
    Posts
    165

    C codes for reading ASM file

    Hi,

    I want to write a c program that will read .asm file and identify the assembly keywords. It should create a .lst file which will also display an error message if there is any error in any line of the source code.

    I am not sure where to start and looking for some example C codes that does the job.

    Any help please ???

  2. #2
    .
    Join Date
    Nov 2003
    Posts
    307
    What platform and which assembler?

  3. #3
    .
    Join Date
    Nov 2003
    Posts
    307
    PS: a lot of C compilers will produce assembly code listings, and some will also compile assmbly code. This is what I'm going to suggest for finding "errors"

  4. #4
    Registered User khpuce's Avatar
    Join Date
    May 2003
    Posts
    165
    I think I better explain my problem a bit more.

    In the first phase, I am trying to write a C file that will read a text file which will have some assembly codes in it. When my program (C) is run, it will ask for a file name. Then it should read the text file (e.g. Myassembly.asm ) and check each line of that file to see whether it contains a valid code in a valid format. If it is a valid code it will just copy that line to another file (e.g. Myassembly.lst) including the line number. If it is not valid line or contains unrecognizable instruction in a line then it should copy the line to myassembly.lst with a suitable error message (e.g error in line 12). If the source line contains instuctions such as ADD R4,R5 then it should show (in the lst file) the correct encodded 16 bit instruction (e.g. 1100 0001 0000 0100 )

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Sounds like what you really need is an assembler. That would seem to be the most effective way of validating an assembler file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User khpuce's Avatar
    Join Date
    May 2003
    Posts
    165
    Thanks Salem and sorry for my poor english. But that's exactly what I am trying to do. CREATING AN ASSEMBLER in C

    The thing is I don't know where to start. That's why I am looking for some pseudocodes/diagrams or some example C codes to do the job.

  7. #7
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    these look like they might be pretty useful
    http://www.google.com/search?hl=en&i...assembler+in+c

  8. #8
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    You need to parse (analyse) each line of your file:

    Read a line
    Start at the beginning of the line
    Skip whitespace until you find a non-whitespace character. Save this location, say p1
    Skip ahead to the next whitespace character, say p2
    Now check the string from p1 thru p2-1 with your list of acceptable commands. If you find a match, you know the command you're dealing with.
    Parse the rest of the line using the format of the command found (1 register; 1 reg, 1 memloc; 2 reg; etc)

    Continue on until daylight...
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  3. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM