do_array.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Sources of the "ARRAY" group instructions
  3. */
  4. /* $Header$ */
  5. #include <em_abs.h>
  6. #include "global.h"
  7. #include "log.h"
  8. #include "trap.h"
  9. #include "mem.h"
  10. #include "text.h"
  11. #include "fra.h"
  12. #define LAR 1
  13. #define SAR 2
  14. #define AAR 3
  15. PRIVATE arr();
  16. DoLARl2(arg)
  17. size arg;
  18. {
  19. /* LAR w: Load array element, descriptor contains integers of size w */
  20. register size l = (L_arg_2() * arg);
  21. LOG(("@A6 DoLARl2(%ld)", l));
  22. arr(LAR, arg_wi(l));
  23. }
  24. DoLARm(arg)
  25. size arg;
  26. {
  27. /* LAR w: Load array element, descriptor contains integers of size w */
  28. LOG(("@A6 DoLARm(%ld)", arg));
  29. arr(LAR, arg_wi(arg));
  30. }
  31. DoLARz()
  32. {
  33. /* LAR w: Load array element, descriptor contains integers of size w */
  34. register size l = upop(wsize);
  35. LOG(("@A6 DoLARz(%ld)", l));
  36. arr(LAR, arg_wi(l));
  37. }
  38. DoSARl2(arg)
  39. size arg;
  40. {
  41. /* SAR w: Store array element */
  42. register size l = (L_arg_2() * arg);
  43. LOG(("@A6 DoSARl2(%ld)", l));
  44. arr(SAR, arg_wi(l));
  45. }
  46. DoSARm(arg)
  47. size arg;
  48. {
  49. /* SAR w: Store array element */
  50. LOG(("@A6 DoSARm(%ld)", arg));
  51. arr(SAR, arg_wi(arg));
  52. }
  53. DoSARz()
  54. {
  55. /* SAR w: Store array element */
  56. register size l = upop(wsize);
  57. LOG(("@A6 DoSARz(%ld)", l));
  58. arr(SAR, arg_wi(l));
  59. }
  60. DoAARl2(arg)
  61. size arg;
  62. {
  63. /* AAR w: Load address of array element */
  64. register size l = (L_arg_2() * arg);
  65. LOG(("@A6 DoAARl2(%ld)", l));
  66. arr(AAR, arg_wi(l));
  67. }
  68. DoAARm(arg)
  69. size arg;
  70. {
  71. /* AAR w: Load address of array element */
  72. LOG(("@A6 DoAARm(%ld)", arg));
  73. arr(AAR, arg_wi(arg));
  74. }
  75. DoAARz()
  76. {
  77. /* AAR w: Load address of array element */
  78. register size l = upop(wsize);
  79. LOG(("@A6 DoAARz(%ld)", l));
  80. arr(AAR, arg_wi(l));
  81. }
  82. /********************************************************
  83. * Array arithmetic *
  84. * *
  85. * 1. The address of the descriptor is popped. *
  86. * 2. The index is popped. *
  87. * 3. Calculate index - lower bound. *
  88. * 4. Check if in range. *
  89. * 5. Calculate object size. *
  90. * 6. Perform the correct function. *
  91. *********************************************************/
  92. PRIVATE arr(type, elm_size)
  93. int type; /* operation TYPE */
  94. size elm_size; /* ELeMent SIZE */
  95. {
  96. register ptr desc = dppop(); /* array DESCriptor */
  97. register size obj_size; /* OBJect SIZE */
  98. register long diff = /* between index and lower bound */
  99. spop(elm_size) - mem_lds(desc, elm_size);
  100. register ptr arr_addr = dppop();/* ARRay ADDRess */
  101. if (must_test && !(IgnMask&BIT(EARRAY))) {
  102. if (diff < 0 || diff > mem_lds(desc + elm_size, elm_size)) {
  103. trap(EARRAY);
  104. }
  105. }
  106. obj_size = mem_lds(desc + (2*elm_size), elm_size);
  107. obj_size = arg_o(((long) obj_size));
  108. spoilFRA(); /* array functions don't retain FRA */
  109. switch (type) {
  110. case LAR:
  111. push_m(arr_addr + diff * obj_size, obj_size);
  112. break;
  113. case SAR:
  114. pop_m(arr_addr + diff * obj_size, obj_size);
  115. break;
  116. case AAR:
  117. dppush(arr_addr + diff * obj_size);
  118. break;
  119. }
  120. }