Write a program that takes 8 one word unsigned integer numbers of 15-bit word size and sums them up. The programmer must handle the carry when the sum exceeds the size of the 15 bit number size.
The numbers will be stored in memory as an array of word values. 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 uses signed words and tests 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.
7FFF 0111 1111 1111 1111 b +7FFF 0111 1111 1111 1111 b ----- 1111 1111 1111 1110 b or bit 15 = 1 and bits 14-0 = 7FFE FFFE
Using the sign bit as an indicator to increment the next significant word and then zeroing out the sign(carry) bit, the result can be represented in two words as
0001 7FFE
Data areas should contain :
Example: 912730 15-bit hex
1001 0001 0 010 0111 0011 0000 2730
0100 1000 1 001 0011 1001 1000 1398
0010 0100 0 100 1001 1100 1100 49cc
0001 0010 0 010 0100 1110 0110 24e6
0000 1001 0 001 0010 0111 0011 1273
1000 0100 1 000 1001 0011 1001 0939
1100 0010 0 100 0100 1001 1100 449c
0110 0001 0 010 0010 0100 1110 224e
cntr, hex 0008
one, hex 0001
Algorithm:
Jump over data area and initialize pointer to table.
While table counter indicates more values in table
Fetch and sum a value from table (use add indirect)
Test sum for overflow (negative value)
If overflow
Call overflow subroutine.
Increment table pointer.
Decrement table counter.
End
Terminate program
Overflow routine
Add 1 to high sum word
Clear high bit of current low 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 doc your code. Also, show the work of converting your zid to the
15 bit binary and hex values on a separate piece of paper. Hand
calculate the math on the numbers you have generated to confirm your
progrm is functioning. You may find that summing the 1st 2 15-bit numbers
in binary then adding each additional binary representation to the
preceeding sum is the easiest.Hand in your paperwork, a hard copy of the program along with the source code on floppy, and a printed dump of memory in Marie after execution. Circle and label the high and low words containing the sum.