home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-19 | 2.3 KB | 77 lines | [TEXT/CWIE] |
- (*
- Problem 10 - Interpreter
-
- Write an interpreter for this simple 32-bit integer language with 26 registers
- labeled A-Z.
-
- type RegisterArray = array[0..25] of SInt32;
-
- procedure Interpret( source: Handle; var result: RegisterArray );
-
- source consists of a number of lines of the form:
-
- [<label>:][<tab><instruction><tab><operand-list>]<cr>
-
- <label> is a sequence of at least two alphanumerics (0-9a-zA-Z_)
- (casesensitive).
- <operand-list> is a sequence of operators seperated by commas
- other than the tabs and crs, no white space is allowed.
-
- <instruction> (and appropriate operands are:
-
- MOVE <value>,<register> (set <register> to <value>)
- ADD <value1>,<value2>,<register> (set <register> to <value1>+<value2>)
- SUB <value1>,<value2>,<register> (set <register> to <value1>-<value2>)
- JMP <label> (jump to line labeled with <label>)
- JEQ <value1>,<value2>,<label> (jump to <label> if <value1> = <value2>)
- JLE <value1>,<value2>,<label> (jump to <label> if <value1> <= <value2>)
- JSR <label> (jump to subroutine at <label>)
- RTS (return from subroutine)
- PUSH <value> (push value on to stack)
- POP <register> (pop value from stack)
-
- <register> is a single uppercase letter in the range A..Z
- <number> is an optional minus sign followed by decimal digits
- <value> is a <register> or a <number>
-
- Note that the data stack and subroutine stack are independent stacks. A RTS is
- used to stop the program (that is, consider that you have JSRed to the initial
- line of the source handle). For example:
-
- PUSH 10
- JSR setA
- JSE setB
- RTS
- setA:
- POP A
- RTS
- setB: MOVE A,B
- RTS
-
- Interpret takes the source handle and JSRs to it, presetting the registers
- according to the register array. When the code returns, the register array is
- set to the final value of all the registers. Both subroutine and data stacks
- should be large (at least 1000 entries each).
- *)
-
- unit Solution;
-
- interface
-
- // Do not modify the interface
-
- uses
- Types, Files;
-
- type RegisterArray = array[0..25] of SInt32;
-
- procedure Interpret( source: Handle; var result: RegisterArray );
-
- implementation
-
- // Fill in your solution and then submit this folder
-
- // Team Name: FILL IN YOUR TEAM NAME!
-
- end.
-