In the program below, instr_1, instr_2, and instr_3 are exactly as in the previous addition program. Instr_1 and instr_2 copy the right digits of A (9) and B (7) into instr_3 and instr_3 copies the result (16) from addtable to the right two digits of C.

Instr_4, instr_5, instr_6, and instr_7 add the left digits of A and B together with the carry bit in C. Instr_4 copies the left digit of A (9) into instr_7. Instr_5 copies the left digit of B (8) into instr_7. Instr_6 copies the carry bit (1) from the middle digit of C to instr_7. Instr_7 copies the result, (1 + 9 + 8 =) 18, into the left two digits of C for a total result in all three digits of C of 186.

Add Two Digits Program

 label        address            data          comment

start    0000000000000000  0000000000010000  start 0000000000000100
A        0000000000000001  0000000010011001  99 (A)
B        0000000000000010  0000000010000111  87 (B)
C        0000000000000011  0000000000000000  answer (C)
instr_1  0000000000000100  0000000000000001  from address of A
         0000000000000101  0000000000001100  to instr_3's from addr.
         0000000000000110  0000000011110000  copy to these bits
         0000000000000111  0000000000100100  go to instr_2, rot. 4
instr_2  0000000000001000  0000000000000010  from address of B
         0000000000001001  0000000000001100  to instr_3's from addr.
         0000000000001010  0000000000001111  copy to these bits
         0000000000001011  0000000000110000  go to instr_3, no rot.
instr_3  0000000000001100  0000001000000000  from addtable
         0000000000001101  0000000000000011  to address of C
         0000000000001110  0000000011111111  copy to these bits
         0000000000001111  0000000001000000  go to instr_4, no rot.
instr_4  0000000000010000  0000000000000001  from address of A
         0000000000010001  0000000000011100  to instr_7's from addr.
         0000000000010010  0000000011110000  copy to these bits
         0000000000010011  0000000001010000  go to instr_5, no rot.
instr_5  0000000000010100  0000000000000010  from address of B
         0000000000010101  0000000000011100  to instr_7's from addr.
         0000000000010110  0000000000001111  copy to these bits
         0000000000010111  0000000001101100  to instr_6,rot.4 right
instr_6  0000000000011000  0000000000000011  from addr.of C (carry)
         0000000000011001  0000000000011100  to instr_7's from addr.
         0000000000011010  0000000100000000  copy to this bit
         0000000000011011  0000000001110100  to instr_7,rot.4 left
instr_7  0000000000011100  0000001000000000  from addtable
         0000000000011101  0000000000000011  to address of C
         0000000000011110  0000111111110000  copy to these bits
         0000000000011111  0000000010000100  go to instr_8, rot. 4
instr_8  0000000000100000  0000000000000000  doesn't matter
         0000000000100001  0000000000000000  doesn't matter
         0000000000100010  0000000000000000  copy NO bits
         0000000000100011  0000000010000000  go to this instruction
 
addtable 0000001000000000  0000000000000000  0 + 0 + 0 = 00
         0000001000000001  0000000000000001  0 + 0 + 1 = 01
         0000001000000010  0000000000000010  0 + 0 + 2 = 02
                                 .
                                 .
                                 .
         0000001010010110  0000000000010101  0 + 9 + 6 = 15
         0000001010010111  0000000000010110  0 + 9 + 7 = 16
         0000001010011000  0000000000010111  0 + 9 + 8 = 17
         0000001010011001  0000000000011000  0 + 9 + 9 = 18

         0000001100000000  0000000000000001  1 + 0 + 0 = 01
         0000001100000001  0000000000000010  1 + 0 + 1 = 02
         0000001100000010  0000000000000011  1 + 0 + 2 = 03
                                 .
                                 .
                                 .
         0000001110010110  0000000000010110  1 + 9 + 6 = 16
         0000001110010111  0000000000010111  1 + 9 + 7 = 17
         0000001110011000  0000000000011000  1 + 9 + 8 = 18
         0000001110011001  0000000000011001  1 + 9 + 9 = 19

In some high level languages, instructions 1 through 7 can be written with one instruction, 'C = A + B.' You type in 'C = A + B.' Then you run another program that is called a compiler. The compiler converts 'C = A + B' into all that machine language, instr_1 through instr_7. A compiler can greatly ease writing programs. Writing programs in machine language (1's and 0's) is relatively difficult. (Most other processors have a hardware adder, so C = A + B becomes few instructions though many bits are added.)


Page 34

Page 33 . . . Page 1 . . . Page 35