do_sets.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Sources of the "SETS" group instructions
  3. */
  4. /* $Id$ */
  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. PRIVATE bit_test(), create_set();
  13. DoINN(l)
  14. register size l;
  15. {
  16. /* INN w: Bit test on w byte set (bit number on top of stack) */
  17. LOG(("@Y6 DoINN(%ld)", l));
  18. spoilFRA();
  19. bit_test(arg_w(l));
  20. }
  21. DoSET(l)
  22. register size l;
  23. {
  24. /* SET w: Create singleton w byte set with bit n on (n is top of stack) */
  25. LOG(("@Y6 DoSET(%ld)", l));
  26. spoilFRA();
  27. create_set(arg_w(l));
  28. }
  29. /********************************************************
  30. * bit testing *
  31. * *
  32. * Tests whether the bit with number to be found *
  33. * on TOS is on in 'w'-byte set. *
  34. * ON --> push 1 on stack. *
  35. * OFF -> push 0 on stack. *
  36. ********************************************************/
  37. PRIVATE bit_test(w)
  38. size w;
  39. {
  40. register int bitno =
  41. (int) swpop(); /* bitno on TOS */
  42. register char test_byte = (char) 0;/* default value to be tested */
  43. register int wordoff = bitno / 8;
  44. register int bitoff = bitno % 8;
  45. if (bitoff < 0) bitoff += 8;
  46. if (must_test && !(IgnMask&BIT(ESET))) {
  47. /* Only w*8 bits CAN be tested */
  48. if (wordoff >= w) {
  49. trap(ESET);
  50. }
  51. }
  52. test_byte = stack_loc(SP + wordoff);
  53. st_dec(w);
  54. wpush((long)((test_byte & BIT(bitoff)) ? 1 : 0));
  55. }
  56. /********************************************************
  57. * set creation *
  58. * *
  59. * Creates a singleton 'w'-byte set with as *
  60. * singleton member, the bit with number on *
  61. * TOS. The w bytes constituting the set are *
  62. * pushed on the stack. *
  63. ********************************************************/
  64. PRIVATE create_set(w)
  65. size w;
  66. {
  67. register int bitno = (int) swpop();
  68. register size nbytes = w;
  69. register int wordoff = bitno / 8;
  70. register int bitoff = bitno % 8;
  71. if (bitoff < 0) bitoff += 8;
  72. st_inc(nbytes);
  73. while (--nbytes >= 0) {
  74. st_stn(SP + nbytes, 0L, 1L);
  75. }
  76. if (must_test && !(IgnMask&BIT(ESET))) {
  77. if (wordoff >= w) {
  78. trap(ESET);
  79. }
  80. }
  81. st_stn(SP + wordoff, (long)BIT(bitoff), 1L);
  82. }