Pseudocode for PC Interpreter

Reply

Join Date: Oct 2007
Posts: 4
Reputation: sbakca is an unknown quantity at this point 
Solved Threads: 0
sbakca sbakca is offline Offline
Newbie Poster

Pseudocode for PC Interpreter

 
0
  #1
Oct 3rd, 2007
Hi.if possible can somebody tell me how to make a start to write this pseudocode in LC3 assembly lang.
thank you

Pseudocode for PC Interpreter
=======================================================================

subroutine execute(program_pointer) {
while (true) {
switch (the value at the program pointer) {
case '.':
Output the value at the data pointer as an ASCII character
break;
case ',':
Read a character from the keyboard
Set the value at the data pointer to the character you just read
break;
case '>':
Increment the data pointer
break;
case '<':
Decrement the data pointer
break;
case '+':
Increment the value at the data pointer
break;
case '-':
Decrement the value at the data pointer
break;
case 'X':
halt the simulator
case ' ':
case '\n':
Ignore spaces and newline characters
break;
default: //error
This situation will never occur

}
Increment the program pointer by 1
}
}

Each instruction does a particular function, using this data. Here
are the instructions:

'>' This increments the data pointer.

if the data pointer was at x6002, it is now pointing at x6003

'<' This decrements the data pointer.

if the data pointer was at x6005, it is now pointing at x6004

'+' This increments the value at the pointer.

if the data pointer is at x6007, and the value at x6007 is
14, it is now 15

'-' This decrements the value at the pointer.

if the data pointer is at x6003, and the value at x6003 is
27, it is now 26.

'.' This outputs the value (as ASCII) at the pointer.

if the data pointer is at x6008, and the value at x6008 is
65, it will output A.

',' This inputs a character value into the value at the pointer.

if the data pointer is at x6013 and the user types 'A', then
65 will be loaded into memory at x6013.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC