Sha256: d99770793ef7e9321427f3ca78315f3dd6dea46a330b2ec51de7d4f5111902c4
Contents?: true
Size: 1.49 KB
Versions: 10
Compression:
Stored size: 1.49 KB
Contents
The only operation that the SSEM supports natively is substraction. This program uses the <tt>001 Sub.</tt> instruction to find the difference between <i>a</i> and <i>b</i>, assuming they are loaded into storage addresses 20 and 21 respectively. 00101000000000100000000000000000 0. -20 to c 10100000000001100000000000000000 1. c to 5 10100000000000100000000000000000 2. -5 to c 10101000000000010000000000000000 3. Sub. 21 00000000000001110000000000000000 4. Stop 00000000000000000000000000000000 5. 0 The routine is slightly more complicated than it would otherwise be, because the SSEM cannot load a value into the accumulator (<tt>c</tt> register) from storage without negating it in the process—so we have to shuffle the negation of <i>a</i> back out into storage and then negate it again before we can subtract <i>b</i> from it. This does, however, make it easy to implement addition using negation and subtraction. In this program, we first negate <i>a</i>; then subtract <i>b</i>, and store the result; and finally negate that result, thereby obtaining the sum of the two integers. 00101000000000100000000000000000 0. -20 to c 10101000000000010000000000000000 1. Sub. 21 10100000000001100000000000000000 2. c to 5 10100000000000100000000000000000 3. -5 to c 00000000000001110000000000000000 4. Stop 00000000000000000000000000000000 5. 0 A multiplication program will be found at [[Function definition#SSEM]], and one that performs integer division at [[Loops/For with a specified step#SSEM]].
Version data entries
10 entries across 7 versions & 1 rubygems