Advertisement
dllbridge

Шаблон ассемблерных функций FASM

Nov 22nd, 2022 (edited)
1,644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Ниже показан шаблон ассемблерного кода (компилируется).
  2. ;В функции нужно добавить недостающий код.
  3.  
  4. include    'win32a.inc'
  5.  
  6.  
  7. format      MS COFF
  8.  
  9.  
  10. public     _RGB                     as '__RGB@12'
  11. public     _decomposition_RGB       as '__decomposition_RGB@4'
  12.  
  13.  
  14.  
  15. section   '.text' code readable executable
  16. ;/////////////////////////////////////////////////////////////
  17. proc   _RGB   red, green, blue                             ;//
  18.  
  19.         mov  eax , [green]
  20.  
  21.  
  22.  
  23.  
  24.  
  25.         ret
  26. endp
  27.  
  28.  
  29.  
  30. ;/////////////////////////////////////////////////////////////
  31. proc   _decomposition_RGB   color                           ;//
  32.  
  33.  
  34.  
  35.  
  36.  
  37.         mov  eax, arr
  38.         ret
  39. endp
  40.  
  41.  
  42. section '.data' data readable writeable
  43. ;-------------------------------------------------------------     Создание переменных:
  44.    arr   dd   4 dup(333)
  45.  
  46. ; Решение на FASM
  47.  
  48.  
  49.  
  50. include 'win32a.inc'
  51.  
  52.  
  53.  
  54. format      MS COFF
  55.  
  56.  
  57.  
  58. public   _RGB                   as '__RGB@12'
  59.  
  60. public   _decomposite_RGB       as '__decomposite_RGB@4'
  61.  
  62.  
  63. section '.text' code readable executable
  64.  
  65.  
  66.  
  67. ;/////////////////////////////////////////////////////////////
  68. proc   _RGB   red, green, blue                             ;//
  69.  
  70.          mov  eax , [green]
  71.          mov  ebx , [blue]
  72.  
  73.          shl eax  ,  8
  74.          shl ebx  , 16
  75.          add eax  ,ebx
  76.          add eax  ,[red]
  77.  
  78.  
  79.          ret
  80. endp
  81.  
  82.  
  83.  
  84. ;/////////////////////////////////////////////////////////////
  85. proc  _decomposite_RGB   color
  86.  
  87.        mov  ebx, [color]
  88.        mov  eax, 0
  89.        mov   al, bl
  90.        mov  [arr +  4], eax   ; Red
  91.        shr  ebx, 8
  92.        mov   al, bl
  93.        mov  [arr +  8], eax   ; Green
  94.        shr  ebx, 8
  95.        mov   al, bl
  96.        mov  [arr + 12], eax   ; Blue
  97.  
  98.        shr  ebx, 8
  99.        mov  [arr], ebx
  100.  
  101.        mov  eax, arr
  102.        ret
  103. endp
  104.  
  105.  
  106. section '.data' data readable writeable
  107. ;-----------------------------------------------------------
  108.  
  109.  
  110.  
  111.  
  112.    arr   dd   4 dup(111111)
  113.  
  114.  
  115.  
  116.                
  117.  
  118.  
  119. ; Решение на Си
  120.  
  121.  
  122.  
  123. #include     <stdio.h>
  124. #include   <windows.h>
  125.  
  126.  
  127.  
  128.  
  129. int nArr[4],
  130.     nRGB;
  131.  
  132.  
  133. int     _RGB(int R, int G, int B);
  134. int  asm_RGB(int R, int G, int B);
  135.  
  136. ///////////////////////////////////////////////////////
  137. int main()                                           //
  138. {
  139.  
  140.     nRGB = asm_RGB(11, 22, 33);
  141.          
  142.     printf("nRGB = %d\n", nRGB);
  143. }
  144.  
  145.  
  146.  
  147. ///////////////////////////////////////////////////////
  148. int asm_RGB(int R, int G, int B)                     //
  149. {
  150.  
  151.     int nRes = 0;
  152.  
  153.  
  154.   __asm
  155.     {
  156.        
  157.          mov eax, B
  158.          shl eax, 8
  159.          add eax, G
  160.          shl eax, 8
  161.          add eax, R
  162.          mov nRes, eax
  163.     }
  164.  
  165. return nRes;
  166. }
  167.  
  168.  
  169.  
  170.  
  171. ///////////////////////////////////////////////////////
  172. int _RGB(int R, int G, int B)                        //
  173. {
  174.  
  175.      int nRes = 0;
  176.  
  177.      nRes = nRes  | B;
  178.      nRes = nRes << 8;
  179.  
  180.      nRes = nRes  | G;
  181.      nRes = nRes << 8;
  182.  
  183.      nRes = nRes  | R;
  184.  
  185. return nRes;
  186. }
  187.  
  188.  
  189.  
  190. ;Интерфейс на Си
  191.  
  192.  
  193.  
  194.  
  195. #include     <stdio.h>
  196. #include   <windows.h>
  197.  
  198.  
  199. extern "C"
  200. {                          
  201.        
  202.     int   __stdcall _RGB(  int, int, int)
  203.     int*  __stdcall _decomposite_RGB(int);             
  204. }
  205.  
  206.  
  207. ///////////////////////////////////////////////////////
  208. int main()                                           //
  209. {
  210.    
  211.     int n = RGB(11, 22, 33);
  212.  
  213.     printf("_RGB = %d \n", _RGB(11, 22, 33));
  214.     printf(" RGB = %d \n",  n);
  215.  
  216.     int  *pn = _decomposite_RGB(2168331);
  217.  
  218.     printf(" arr[0] = %d \n",  pn[0]);    
  219.     printf(" Red    = %d \n",  pn[1]);
  220.     printf(" Green  = %d \n",  pn[2]);    
  221.     printf(" Blue   = %d \n",  pn[3]);  
  222.    
  223.    
  224. return 0;      
  225. }
  226.  
  227.  
  228.  
  229.  
  230.  
  231.              
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement