CSCI 463 Marie Assembler assignment 100 Points

Due 1 Nov 2006 Wednesday at start of class - Hard copy of program to be handed in at beginning of class. Source code to be emailed to me at berezin@cs.niu.edu and Eric at z087607@students.niu.edu.

Write a program that takes 2 two word unsigned integer numbers of 15-bit word size (16th bit will be used as a carry) and sums them up. The programmer must handle the carry when the sum exceeds the size of the 15 bit word size.

The numbers will be stored in memory as 2 two word arrays. Use the Jump to subroutine to set up a pointer to the start of the table. Then use the pointer to index through the table. I will provide examples on how to do this. Store and manipulate the values as hex values to more easily see what is happening.

Marie recognizes signed numbers by testing the high bit of a word to recognize a signed number. If you consider a word as a 15 bit unsigned number, you can use the high (sign) bit of the number as a carry flag.

This limits the value range of each word to 0 - 7fff or 0 - 32767. However, several words can be used together to store very large values.

Assume the words of the 2-word number are arranged in little-endian mannor.

48573 = 1011 1101 1011 1101b = 0)000 0000 0000 0001 0)011 1101 1101 1101

Traditionally, bits are numbered from 0 not 1 so 16th or high bit of number is referenced as bit 15. Example of using bit 15 as a carry flag :

 7FFF    0111 1111 1111 1111 b
+7FFF    0111 1111 1111 1111 b
-----    
 FFFE    1111 1111 1111 1110 b or bit 15 = 1 and bits 14-0 = 7FFE 

Carry the sign to the next memory location and subtract the high bit.

 FFFE    1111 1111 1111 1110 b or bit 15 = 1 and bits 14-0 = 7FFE 
-8000    1000 0000 0000 0000 b
------
 7FFE    7111 1111 1111 1110 b or bit 15 = 1 and bits 14-0 = 7FFE 
 
Carry the sign bit to the next storage word.

0001 7FFE 

Data areas should contain :

Hard code the 8 15-bit word values into the program's data table area. Also set the 2 words of sum storage to zero and initialize a word to hold a counter (set to 8) to track how far through the table you are.

Algorithm:

Jump over each of the number tables and initialize pointer to tables.

Clear the Sum storage area. 

While table counter indicates more values in table
  Fetch and sum low word of 1st value to low sum. (use add indirect)
  Fetch and sum low word of 2st value to low sum. (use add indirect)
  Test sum for overflow (negative value)
  If overflow
    Call overflowlow subroutine.

  Endif

  Increment number pointers for each number.
 
  Fetch and sum high word of 1st value to high sum. (use add indirect)
  Test sum for overflow (negative value) (may be carry from low sum).
  If overflow
    Call overflowhigh subroutine.

  Endif

  Fetch and sum high word of 2st value to high sum. (use add indirect)
  Test sum for overflow (negative value)
  If overflow
    Call overflowhigh subroutine.

  Endif
End

Terminate program

Overflowlow routine
   Add 1 to high sum word
   Clear high bit of current low sum word.
Return

Overflowhigh routine
   Add 1 to carry sum word
   Clear high bit of current high sum word.
Return
Remember that there is only one work register, so it may be neccessary to store the current contents before taking a new action.

DO document your code. Also, prove your program by working the solution manually. On paper, show the work of converting your zid to the specified format and performing the math. You may find that summing the numbers in binary the easist way to perform calculations.

Email the source code to your TA.

Hand in your proof paperwork, a hard copy of the program and a printed dump of memory in Marie after execution. Circle and label the carry, high, and low words containing the sum.