Implement the rules required to simulate a computer that supports the instructions: move, add, decrement, jump, and jump_on_zero.
Details:
Handin Requirements
cat Hmwk6.pp
cat GivenRules.pp
cat Simulate1.pp
pprolog Hmwk6.pp GivenRules.pp Simulate1.pp
answer(X).
cat Simulate2.pp
pprolog Hmwk6.pp GivenRules.pp Simulate2.pp
answer(X).
cat Simulate3.pp
pprolog Hmwk6.pp GivenRules.pp Simulate3.pp
answer(X).
NOTE: after the answer(X). query, each answer returned should be
responded to with a carriage return. To exit pprolog, one types the end
of file character, which on gaul is usually control-D. The test data files
can be found on gaul in: /gaul/s1/usr/faculty/webber/CS342/Homework6 .
Reference:
Chapters 1, 2, and 3 of the Spivey text on Prolog are sufficient for this assignment. For plus and integer, it is useful to take a look at Section 14.2 of the text.
Sample Run:
This is an example of what it looks like to run this assignment on a sample program that moves the contents of the first location in memory to the eight location and then quits.
brown[205]: cat x.pp
answer(X) :- simulate(
state(1,
3:nil,
instruction(move,1,8):
instruction(jump,0,0):
nil),
X).
brown[206]: pprolog Hmwk6.pp GivenRules.pp x.pp
Welcome to picoProlog
Reading Hmwk6.pp
Reading GivenRules.pp
Reading x.pp
# :- answer(X).
X = 3:0:0:0:0:0:0:3:nil ?
no
# :- ^D
Hints:
pprolog Hmwk6.pp GivenRules.pp x.pp Welcome to picoProlog Reading Hmwk6.pp Reading GivenRules.pp Reading x.pp # :- change_memory(3, 2:nil, 7, X). X = 2:0:7:nil ? nolets us see that when we try to change the 3rd memory location to 7 in a memory list of just one cell that has the value 2, the right new memory list is produced (with a 0 second element and the first element unchanged).