The other day I posted the simple microporcessor design that I created as an undergraduate. As a part of that project I also had to write an assembler and simulator for the processor. Way back in 2011, when I was working on this project, the Hipster movement was nearing its peak in the US, and I had to find a nerdy way to get some irony. I decided it would be awesome to write the assembler and simulator in JavaScript. So, for those of you who want to run some Simple-12 programs online, check out my web-based Simple-12 simulator. Below are some sample programs.

#
# Print the first 7 Fibonacci numbers
# Christopher Stoll
#

	.code
main:	ld	parm1
		print		# print the number

		ld	limit	# load limit decrementor
		jz	end		# decremented to zero, exit

		sub	one		# decrement counter
		st	limit	# store decrementor

		ld	parm1
		add	parm2
		st	parm3	# next Fibonacci
		ld	parm2
		st	parm1	# parm1 = parm2
		ld	parm3
		st	parm2	# parm2 = parm3

		j	main	# loop

end:	exit

	.data
one:	word	1	# constant: 1
parm1:	word	1	# Fibonacci 1
parm2:	word	1	# Fibonacci 2
parm3:	word	0	# Fibonacci temp
limit:	word	6	# decrementor
#
# Find maximum value in a vector of positive integers
# Christopher Stoll, 2001
#
	.data
one:	word 1
ary1:	word 1
		word 3
		word 7
		word 5
		word 2
		word 6
		word 9
		word 4
		word 8
		word -1
arypo:	word @ary1
highv:	word 0

	.code
main:	li   arypo	# load array mem location
	
		add  @one	# add 1 to the value
		jz   end	# if acc is zero end (sentinel)
		sub  @one	# subtract 1 back out

		sub  highv	# subtract the high value
		jn   inc	# high value > current, loop
		jz   inc	# high value == current, loop

		li   arypo	# load current value
		st   highv	# store new high value

inc:	ld   arypo	# load array position
		add  @one	# increment array position
		st   arypo	# store array position
		j    main	# loop

end:	ld   highv	# load the high value
		print		# show the high value
		exit

Tags: Assembler Computer Architecture ISA Simple-12 Microprocessor Simulator

Published: 2014-02-22