CS 353 Lab 7: Writing a PC-231 Assembler

Description

For this lab you will write a PC-231 assembler. It should behave like the supplied Unix version, i.e., it should read assembly codes (including labels and CONST pseudo-instructions) and generate hex codes. You should be familiar with the PC-231 assembly language from programming it, but you may also want to review the PC-231 description to recall features that you may not have used. You aren't required to implement all features that I have in the UNIX version, but the more features you have available to you, the easier it will be to program using your own assembler.

Here is a an assembly "torture test" that uses a lot of obscure features of my assembler:

; -----------------------
; A sample PC 231 program illustrating some assembler features
; Fritz Ruehr # CS 231 # Fall 1998

; To test this file, try the command
;
;	asm231 < sample.asm

; -----------------------

	data	xFF	; lowercase gets fixed in output
			; hex constants start with "x"

	copy DR,R0	; use names for registers
	DATA 'A'	; ASCII characters in quotes
	copy DR,RA	; RA = J0 (synonyms for registers)
	DATA #label	; use labels; generates double hex

	READ R1, d0	; device numbers
	READ r2, AD	; AD = ASCII device;
			; also HD = hex device
			; and DD = decimal device

	JPIF R0, NZ,J0	; use of condition codes
					; (more cruelty)
#label
				; (comment here is more cruel)
		
				; ; ;;
				
	INC DR,	5	; can use pos/neg numbers for INC
	SHIFT DR,-1	; ditto for SHIFT (bug fixed!)
	HALT		; 
	
	CONST xA0	; CONST pseudo-instruction just 
			; places its argument in RAM
	
	CONST xF00	; CONST with all 12 bits 
	CONST 'Z'	; useful for ASCII characters
	CONST -17	; negative numbers (decimal only)
	CONST		#label		; is this allowed?

; Comments from start of line are preserved in hex dump
; For hex dump, call as:

;	asm231 hex < sample.asm

; --------------------------
; End of sample program file
; --------------------------

Of course, if you like, you may implement other features and put a more well-developed interface on your program. For example, the ability to put strings in RAM with a kind of extended CONST would probably be useful, as well as the ability to reserve a set number of locations (e.g. an array for integers). A more ambitious extension would be the addition of some sort of macros: this could be useful, for example, when implementing multiplication in later labs.

You might also want to hook your assembler up directly to your simulator from the last lab, so that you can "load and go" from an assembly program direct to execution. You might also want to have some sort of debugging output for intermediate results; this could work especially well in a multi-pane graphical interface, so that you could see the original assembler, the hex codes, debugging information, etc.