First develop commit. Adding all existing files.
This commit is contained in:
20
resources/TOY/sum_1-n.toy
Normal file
20
resources/TOY/sum_1-n.toy
Normal file
@@ -0,0 +1,20 @@
|
||||
program Sum 1-N
|
||||
// Input: N
|
||||
// Output: The sum of all integers between 1 and N inclusive
|
||||
// Remarks: Please note that the highest value of N that can be processed
|
||||
// without overflow is 00FF.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Initialize
|
||||
10: 7101 R[1] <- 0001
|
||||
11: 82FF read R[2]
|
||||
12: 7300 R[3] <- 0000
|
||||
|
||||
// Add, decrement, and loop
|
||||
13: 1332 R[3] <- R[3] + R[2]
|
||||
14: 2221 R[2] <- R[2] - R[1]
|
||||
15: D213 if (R[2] > 0) goto 13
|
||||
|
||||
// Print the sum
|
||||
16: 93FF write R[3]
|
||||
17: 0000 halt
|
||||
Reference in New Issue
Block a user