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 :
For each of the 2 word tables, set up a pointer (use jsr command to initialize) to the beginning of each table and use the add indirect to perform the addition.
A third table should contain 3 words that would hold the sum of the two numbers. The third word will contain any carry out of the 2nd word. You may use discrete labels for the sum. e.g suml, sumh, sumc.
Example: Lower 12 binary bits of 912730 are 000 1010 0100 1010. 1st number Low word is : 000 1010 0100 1010 or 0a 4a. High word is : 101 0010 0101 0000 or 52 50. 2st number Low word is : 111 1111 1111 1111 or 7f ff High word is : 111 1111 1111 1111 or 7f ff 101 0010 0101 0000 000 1010 0100 1010 + 111 1111 1111 1111 111 1111 1111 1111 -------------------------------------------- 1101 0010 0100 1111 1000 1010 0100 1001 Process carry from bit 16 0101 0010 0100 1111 0000 1010 0100 1001 + 1 1 -------------------------------------------- 1 0101 0010 0101 0000 0000 1010 0100 1001 sumc = 1 or 01 sumh = 0101 0010 0101 0000 or 52 50 suml = 0000 1010 0100 1001 or 0a 49
one, hex 0001
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. ReturnRemember 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.