1
0

sum.g 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # This file is part of asmc, a bootstrapping OS with minimal seed
  2. # Copyright (C) 2018 Giovanni Mascellani <gio@debian.org>
  3. # https://gitlab.com/giomasce/asmc
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. const FROM 20
  15. const TO 0x64
  16. ifun do_sum 2
  17. fun main 0 {
  18. "The sum of numbers from " log ;
  19. FROM itoa log ;
  20. " to " log ;
  21. TO itoa log ;
  22. " is " log ;
  23. FROM TO do_sum itoa log ;
  24. "\n" log ;
  25. }
  26. fun do_sum 2 {
  27. $from
  28. $to
  29. @from 1 param = ;
  30. @to 0 param = ;
  31. $i
  32. $sum
  33. @i from = ;
  34. @sum 0 = ;
  35. while i to <= {
  36. @sum sum i + = ;
  37. @i i 1 + = ;
  38. }
  39. sum ret ;
  40. }