Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: macro expanding feature in java

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Thanked 0 Times in 0 Posts

    Default macro expanding feature in java

    Hi Everyone,

    I want to implement the macro expanding feature in java, the project description are

    Write a program to simulate the first phase of an assembler that provides a macro feature. Your program should read in an assembly program that has macro definitions and macros in use. Your program should remove the macro definitions and expand them wherever they are used in the file.

    For example:
    MACRO COPY $0 $1
    MOV AL,$0
    MOV $1,AL

    JMP start ; Jump to 'start' (main code)
    DB 30 ; Data table
    DB 31
    DB 32
    DB 33
    DB 34
    DB 35
    DB 36
    DB 37
    DB 38
    DB 39

    ORG 20 ; Assembler directive - start of main code
    start: ; label
    COPY [02],[C0]
    COPY [03],[C1]
    COPY [04],[C2]
    COPY [05],[C3]
    COPY [06],[C4]
    COPY [07],[C5]
    COPY [08],[C6]
    COPY [09],[C7]

    Would be translated to:

    JMP start ; Jump to 'start' (main code)
    DB 30 ; Data table
    DB 31
    DB 32
    DB 33
    DB 34
    DB 35
    DB 36
    DB 37
    DB 38
    DB 39

    ORG 20 ; Assembler directive - start of main code
    start: ; label
    MOV AL,[02]
    MOV [C0],AL
    MOV AL,[03]
    MOV [C1],AL
    MOV AL,[04]
    MOV [C2],AL
    MOV AL,[05]
    MOV [C3],AL
    MOV AL,[06]
    MOV [C4],AL
    MOV AL,[07]
    MOV [C5],AL
    MOV AL,[08]
    MOV [C6],AL
    MOV AL,[09]
    MOV [C7],AL

    You may use any reasonable macro definition scheme you wish to use. Ensure it can cope with macros with 0 to 5 arguments. Your program is purely a text processor that expands macros. The assembler in the simulator can handle the running of the transformed code.

    Your help will be highly appreciated.



  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 636 Times in 540 Posts

    Default Re: macro expanding feature in java

    What have you tried? Where are you stuck? Please see the link in my signature on asking questions the smart way.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 3
    Last Post: September 1st, 2011, 10:49 AM
  2. want to implement security key feature in the software
    By javasabin in forum Member Introductions
    Replies: 2
    Last Post: January 8th, 2011, 01:52 AM
  3. New Syntax Highlighting Feature!
    By JavaPF in forum Forum Updates & Feedback
    Replies: 15
    Last Post: July 14th, 2010, 09:20 AM
  4. Replies: 5
    Last Post: June 10th, 2010, 10:19 AM
  5. New give thanks feature
    By JavaPF in forum The Cafe
    Replies: 0
    Last Post: April 11th, 2009, 11:14 AM

Tags for this Thread