Closed Thread
Results 1 to 4 of 4

Thread: How to write a Simulator for SML code

  1. #1
    debug is offline Newbie
    Join Date
    Aug 2007
    Posts
    17
    Rep Power
    0

    How to write a Simulator for SML code

    i have written a SML code(below) which ask the user to input positive number and print out the total sum. the program will jump out of the input if user enter negative number. But don't really know how to write a simulator with C++ to test the code. hope somebody can help me with it.

    Location Number
    -------- ------
    00 +1009 (10=read,09=location of A)
    01 +2009 (20=load, 09=location of A)
    02 +4108 (41=branch negative, 08=write to screen)
    03 +2010 (20=load,10=location of B)
    04 +3009 (30=add,09=location of A)
    05 +2110 (21=store,10=location of B
    06 +4000 (40=branch,00=read A)
    07 +1110 (11=write,10=location of B)
    08 +4300 (halt)
    09 +0000 variable of a
    10 +0000 variable of b

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143
    Do you know how to dynamically allocate memory? Do you know how to create a linked list? Do you have any compiler theory in your background? Depending on your answers to those questions, we may be able to help. In general, writing a simulator is a non-trivial project.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    debug is offline Newbie
    Join Date
    Aug 2007
    Posts
    17
    Rep Power
    0
    yup i have learn about creating a link list and allocating memory but i dun have any complier theory background.

  5. #4
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143
    I would do something like the following:
    Create a map between instruction numbers and instructions.
    Load the instructions into the map.
    Create another map between "memory" locations and text representations of their values.
    Have a variable to store the current instruction.
    Have an instruction processor based on what counts as a valid statement.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 09-19-2011, 03:01 PM
  2. how to write tis program code
    By 2612 in forum C and C++
    Replies: 12
    Last Post: 12-18-2010, 12:11 PM
  3. How Do I Write This Code ?????
    By byronwells in forum PHP Development
    Replies: 11
    Last Post: 01-21-2010, 08:45 PM
  4. How to write code to make summary
    By modakindia in forum Database & Database Programming
    Replies: 0
    Last Post: 05-05-2009, 04:08 AM
  5. How to write such code???
    By stephen0606 in forum C and C++
    Replies: 5
    Last Post: 10-10-2007, 06:24 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts