assembler design

This is a discussion on assembler design within the C Programming forums, part of the General Programming Boards category; i need tips for designing a one-pass and two pass assembler using c...

  1. #1
    Unregistered
    Guest

    assembler design

    i need tips for designing a one-pass and two pass assembler using c

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    It kinda depends on what you're assembling, but here's the general strategy...

    Pass A: Getting the labels
    1: Start at first address of assembly program
    2: Read in a line
    3: Decompose that line into its seperate parts
    4: If there's a label, store that <label, address> pair
    5: Figure out how much memory the instruction there will take
    6: Increment the address counter
    7: Repeat untill you reach the end of file.

    Now you have a map from labels to addresses, so you can actually assemble the instructions.

    Pass B: Assembly
    1: Start at first address of assembly program
    2: Read in a line
    3: Decompose that line into its seperate parts
    4: Put together the instruction (you'll use the <label, address> map here
    5: Write the instruction to an object file
    6: Repeat untill you reach the end of file


    Decomposing the instruction is just an exercise in character-at-a-time string processing. How you do it depends on your instruction format.

    You'll need to keep some information about the instructions and directives. This is done with a <mneumonic, information> map, where the mneumonic part is the string representation of the mneumonic, and the information part is a structure that contains information about that mneumonic (like, is it an instruction or a directive? How big is it? What is its bytecode? What kind of arguments does it accept?)
    Callou collei we'll code the way
    Of prime numbers and pings!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. which design is better to wrap another class instance
    By George2 in forum C++ Programming
    Replies: 7
    Last Post: 04-13-2008, 12:27 AM
  3. Implementing Inheritence into your design
    By bobthebullet990 in forum C++ Programming
    Replies: 6
    Last Post: 08-05-2006, 04:40 PM
  4. Opinions on new site design
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 01-21-2005, 12:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21