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
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.
yup i have learn about creating a link list and allocating memory but i dun have any complier theory background.
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks