tw0736.pp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. {$ifdef FPC}
  2. {$ASMMODE INTEL}
  3. {$INLINE ON}
  4. {$endif FPC}
  5. program test;
  6. type
  7. tobj = object
  8. x : word;
  9. constructor init;
  10. procedure test;virtual;
  11. procedure testx;
  12. end;
  13. constructor tobj.init;
  14. begin
  15. x:=1;
  16. end;
  17. procedure tobj.testx;
  18. begin
  19. asm
  20. mov ax,3
  21. mov word ptr[x],ax
  22. end;
  23. end;
  24. procedure tobj.test;
  25. var
  26. pattern: word;
  27. dummyval : word;
  28. function rotate: boolean; assembler; {$ifdef FPC}inline;{$endif FPC}
  29. asm
  30. mov al,0
  31. rol word ptr [pattern],1
  32. rcl al,1
  33. end;
  34. { this does still not work because
  35. it can only work as inline not as normal sub function
  36. because dummyval and pattern are not reachable !! PM
  37. function rotateb(dummy : byte) : boolean; assembler; inline;
  38. asm
  39. movzx byte ptr [dummy],ax
  40. mov ax,word ptr [dummyval]
  41. mov al,0
  42. rol word ptr [pattern],1
  43. rcl al,1
  44. end; }
  45. var
  46. i : byte;
  47. begin
  48. pattern:= $a0a0;
  49. for i:=1 to 16 do
  50. begin
  51. Write('obj pattern = ',
  52. {$ifdef FPC}
  53. hexstr(pattern,4),' ');
  54. {$else}
  55. pattern,' ');
  56. {$endif}
  57. if rotate then
  58. Writeln('bit found')
  59. else
  60. Writeln('no bit found');
  61. end;
  62. end;
  63. procedure changepattern;
  64. var
  65. pattern: word;
  66. dummyval : word;
  67. function rotate: boolean; assembler; {$ifdef FPC}inline;{$endif FPC}
  68. asm
  69. mov al,0
  70. rol word ptr [pattern],1
  71. rcl al,1
  72. end;
  73. { this does still not work because
  74. it can only work as inline not as normal sub function
  75. because dummyval and pattern are not reachable !! PM
  76. function rotateb(dummy : byte) : boolean; assembler; inline;
  77. asm
  78. movzx byte ptr [dummy],ax
  79. mov ax,word ptr [dummyval]
  80. mov al,0
  81. rol word ptr [pattern],1
  82. rcl al,1
  83. end; }
  84. var
  85. i : byte;
  86. begin
  87. pattern:= $a0a0;
  88. for i:=1 to 16 do
  89. begin
  90. Write('pattern = ',
  91. {$ifdef FPC}
  92. hexstr(pattern,4),' ');
  93. {$else}
  94. pattern,' ');
  95. {$endif}
  96. if rotate then
  97. Writeln('bit found')
  98. else
  99. Writeln('no bit found');
  100. end;
  101. end;
  102. var
  103. t : tobj;
  104. begin
  105. changepattern;
  106. t.init;
  107. t.test;
  108. t.testx;
  109. if t.x<>3 then
  110. begin
  111. Writeln('Unable to access object fields in assembler');
  112. Halt(1);
  113. end;
  114. end.