CS33 -Laboratory 6

Due 11:59pm Thursday, Oct 7

email to me at: cfk@cs.swarthmore.edu a message in text form (no word, html or any other format than plain text) that contains labeled solutions to the exercises below. Make the subject of the email: cs33lab6. Make sure it is posted to me before 11:59 pm on Thursday, 7 Oct. If you are totally successful, the solution will just be one big annotated program in LC3 Assembly Language. If you can't get the whole thing. Send me whatever pieces you can get.

Don't forget that you are encouraged to work with a partner on these labs. AND to get those legal CS highs, code and test small pieces at a time.

In this lab, we will write assembly language programs for the LC-3, assemble them to object code for the LC-3 (lc3as), and then run them in the LC-3 simulator (lc3sim-tk).

Your program(s) must follow these following guidelines:

For this lab assignment, you will write one LC-3 assembly language program. Your program should begin at x3000 and you should not make any assumptions about the initial state of registers or memory locations.

You will store your answers in the file lab06.asm. This should be the text file you submit in your email.

  1. Write a function called MULTFN which takes two arguments named ARG1_MULT and ARG2_MULT, multiplies them together, and stores the result in RET_MULT. You can use any code we wrote in class as a basis for your solution. You should assume that both arguments are zero or positive.
  2. Write a function called MULT10FN which takes one argument named ARG_MULT10, multiplies it by 10, and stores the result in RET_MULT10. Your solution should use the MULTFN function.
  3. Write a function called DIVMODFN which takes two parameters named ARG1_DIVMOD and ARG2_DIVMOD. In DIV_DIVMOD, you should store the (integer) result ARG1_DIVMOD divided by ARG2_DIVMOD. In MOD_DIVMOD, you should store the remainder of that division also known as ARG1_DIVMOD mod ARG2_DIVMOD.
  4. Write a function called DIV10FN which takes one argument, ARG_DIV10, and stores into RET_DIV10 the result of dividing ARG_DIV10 by 10. Your solution should use the DIVMODFN function.

In the remaining portion of the lab, you will reimplement your solution to the decimal-binary conversion program of the last lab, and you will add new functionality. Your solution will make use of the MULT10FN and DIV10FN which you wrote above.

Continue to use the lab06.asm file.

  1. Write a function called INDIGITSFN which reads in up to 4 digits from the keyboard and stores them in a block of memory you have reserved labeled DIGITS. The function takes no arguments and has no return value. Your function should: How you chose to implement these two conditions is up to you.
  2. Write a function called DEC2BINFN which converts the contents of the memory location DIGITS to binary. The function has no arguments and stores its result in RET_DEC2BIN. The correct solution will use the MULT10FN function. Note: You should assume that the correct digits are already in DIGITS. Do not call the INDIGITSFN in this function.
  3. Write a function called PRINTBFN which outputs the contents of its single argument, ARG_PRINTB in binary. The function has no return value.
  4. Write a function called BIN2DECFN which takes an argument, ARG_BIN2DEC and converts this value to its decimal equivalent (as a string, similar to what you stored in DIGITS). You should reserve a block of 6 words (for up to 5 digits plus a marker to indicate the end of the string) called RET_BIN2DEC which will store the decimal string. The correct solution will use the DIV10FN function. Note: The value in RET_BIN2DEC needs to be a string in the LC-3 sense: that is, if you load the address RET_BIN2DEC into R0 (LEA R0, RET_BIN2DEC) and then call PUTS, the string should be printed to the screen.
  5. Be sure your "main program" requires no more than these statements:
    	.ORIG	x3000
    
    	;; Read digits in DIGITS
    	JSR	INDIGITSFN
    
    	;; Convert contents of memory location DIGITS
    	;; from decimal and store in R3
    	JSR	DEC2BINFN
    	LD	R3, RET_DEC2BIN
    
    	;; Print contents of register R3 as a binary number
    	ST	R3, ARG1_PRINTB
    	JSR	PRINTBFN
    
    	;; Convert contents of register R3 to decimal, 
    	;; and then print it out
    	ST	R3, ARG1_BIN2DEC
    	JSR	BIN2DECFN
    	LEA	R0, RET_BIN2DEC
    	PUTS	
    		
    	HALT
    

The final exam has been scheduled by the registrar for Friday Dec. 17 from 9am to noon. Please mark your calendars. All students must take the final exam at this time.