test_op_assign.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* This file is part of asmc, a bootstrapping OS with minimal seed
  2. Copyright (C) 2018-2019 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. int test_ptr_assign() {
  15. int *x = 1000;
  16. if (x != 1000) return 0;
  17. if ((x += 50) != 1200) return 0;
  18. if (x != 1200) return 0;
  19. long long *y = 10000;
  20. if (y != 10000) return 0;
  21. if ((y -= 10) != 9920) return 0;
  22. if (y != 9920) return 0;
  23. return 1;
  24. }
  25. int test_int_assign() {
  26. int x = 1000;
  27. if (x != 1000) return 0;
  28. if ((x += 50) != 1050) return 0;
  29. if (x != 1050) return 0;
  30. long long y = 10000;
  31. if (y != 10000) return 0;
  32. if ((y -= 10) != 9990) return 0;
  33. if (y != 9990) return 0;
  34. long long y = 10000;
  35. if (y != 10000) return 0;
  36. if ((y <<= 4) != 16 * 10000) return 0;
  37. if (y != 16 * 10000) return 0;
  38. // Test that writes smaller than a dword are done correctly
  39. short ar[10];
  40. int i;
  41. for (i = 0; i < 10; i += 1) {
  42. ar[i] = i;
  43. }
  44. ar[5] *= 1;
  45. for (i = 0; i < 10; i += 1) {
  46. if (ar[i] != i) return 0;
  47. }
  48. return 1;
  49. }
  50. int test_ptr_incdec() {
  51. int *p = 1000;
  52. if (p++ != 1000) return 0;
  53. if (p != 1004) return 0;
  54. if (p-- != 1004) return 0;
  55. if (p != 1000) return 0;
  56. if (++p != 1004) return 0;
  57. if (p != 1004) return 0;
  58. if (--p != 1000) return 0;
  59. if (p != 1000) return 0;
  60. return 1;
  61. }
  62. int test_int_incdec() {
  63. int x = 100;
  64. int y = x++;
  65. if (x != 101) return 0;
  66. if (y != 100) return 0;
  67. x = 100;
  68. y = ++x;
  69. if (x != 101) return 0;
  70. if (y != 101) return 0;
  71. x = 100;
  72. y = x--;
  73. if (x != 99) return 0;
  74. if (y != 100) return 0;
  75. x = 100;
  76. y = --x;
  77. if (x != 99) return 0;
  78. if (y != 99) return 0;
  79. return 1;
  80. }