CSC103 2011 Assembly Language Examples

From dftwiki3
Revision as of 11:47, 15 February 2011 by Thiebaut (talk | contribs)
Jump to: navigation, search

--D. Thiebaut 11:37, 15 February 2011 (EST)


Program 1

A program that computes the sum of all the integers between 1 and 5 and stores it into a variable called sum.

start:	lod	counter
		add sum
		sto sum
		lod counter
		sub-c 1
		sto counter
		jmz	done
		jmp	start
done:	hlt


counter:	5
sum:		0

Program 2

; program to display a bit pattern in graphics memory
start:		lod 	pattern			;get the pattern
			sto-i	index				;store it in the image, at a location
			lod		index				;get the image index
			add-c	1					;make it point to next word in mem
			sto		index				;store it back
			lod		count				;get the counter
			sub-c	1					;subtract one
			sto		count				;store back
			jmz		done				;if counter is 0, we're done
			lod		pattern			;if not, we check the pattern
			add		pattern			;shift it to the left by 1 bit
			sto		pattern			;store it back
			jmz		resetPattern		;if pattern is 0, reset it
			jmp		start				;loop back
resetPattern:							;reset pattern to 1
			lod-c	1
			sto		pattern
			jmp		start
done:		hlt							;we're done!

pattern:	1							;the pattern to store in graphics mem
count:		1000						;how many words we fill up
index:		image						;pointer to the image words
image:		data						;the image starts here