Homework #2 - Due Oct. 7 (Tuesday)

The high-level language program to calculate xy could be written as


Main Program:
	result := 1
	for counter := 1 to y do
	     result := result * x
	end for

In assembly language this translates to the following program:

#  Mark Fienup <Your name here as a comment> 
 	.data
x:	.word 2
y:	.word 3
result:	.word 0

	.text
	.globl main
main:
	lw	$8, x			# store x in reg. $8
	lw 	$9, y			# store y in reg. $9
	li 	$10, 1			# store result in $10 and initialize it to 1
for:
	li 	$11, 1			# store counter in $11 and initialize it to 1
for_compare:
	bgt	$11, $9, end_for
for_body:
	mul	$10, $10, $8		# mult. result by x
	addi	$11, $11, 1
	j	for_compare
end_for:

	sw	$10, result

	li	$v0, 10		# system code for exit
	syscall

Your assignment is to type in the above program using some editor like Notepad (directions on back). Run the assembly language programming using pcspim. 

Turn in: Print out of the file containing the program and the resulting PCSpim window after running the program (directions on back).

Entering the Program using Notepad:

  1. Start | All Programs | Accessories | Notepad
  2. Type in the program in a new file
  3. File | Save As
  4. Print a copy of the program to hand in
  1. Start | All Programs | Programming | PCSpim
  2. Maximize the window by clicking on the 2nd icon in the upper right of the window
  3. Load the program by File | Open
  4. Run the program by Simulator | Go
  5. Copy the PCSpim window to the Window's Clipboard using <Alt><Print Screen> keys

Printing the PCSpim window using Word:

  1. Start | All Programs | Microsoft Office XP | Microsoft Word
  2. Paste in the PCSpim window from the Clipboard by Edit | Paste
  3. Change to landscape by File | Page Setup and then click "Lanscape" button
  4. Resize the frame containing the PCSpim picture by
  5. Print this picture of the PCSpim window to hand in