tw0736.pp 2.2 KB

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