Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Ниже показан шаблон ассемблерного кода (компилируется).
- ;В функции нужно добавить недостающий код.
- include 'win32a.inc'
- format MS COFF
- public _RGB as '__RGB@12'
- public _decomposition_RGB as '__decomposition_RGB@4'
- section '.text' code readable executable
- ;/////////////////////////////////////////////////////////////
- proc _RGB red, green, blue ;//
- mov eax , [green]
- ret
- endp
- ;/////////////////////////////////////////////////////////////
- proc _decomposition_RGB color ;//
- mov eax, arr
- ret
- endp
- section '.data' data readable writeable
- ;------------------------------------------------------------- Создание переменных:
- arr dd 4 dup(333)
- ; Решение на FASM
- include 'win32a.inc'
- format MS COFF
- public _RGB as '__RGB@12'
- public _decomposite_RGB as '__decomposite_RGB@4'
- section '.text' code readable executable
- ;/////////////////////////////////////////////////////////////
- proc _RGB red, green, blue ;//
- mov eax , [green]
- mov ebx , [blue]
- shl eax , 8
- shl ebx , 16
- add eax ,ebx
- add eax ,[red]
- ret
- endp
- ;/////////////////////////////////////////////////////////////
- proc _decomposite_RGB color
- mov ebx, [color]
- mov eax, 0
- mov al, bl
- mov [arr + 4], eax ; Red
- shr ebx, 8
- mov al, bl
- mov [arr + 8], eax ; Green
- shr ebx, 8
- mov al, bl
- mov [arr + 12], eax ; Blue
- shr ebx, 8
- mov [arr], ebx
- mov eax, arr
- ret
- endp
- section '.data' data readable writeable
- ;-----------------------------------------------------------
- arr dd 4 dup(111111)
- ; Решение на Си
- #include <stdio.h>
- #include <windows.h>
- int nArr[4],
- nRGB;
- int _RGB(int R, int G, int B);
- int asm_RGB(int R, int G, int B);
- ///////////////////////////////////////////////////////
- int main() //
- {
- nRGB = asm_RGB(11, 22, 33);
- printf("nRGB = %d\n", nRGB);
- }
- ///////////////////////////////////////////////////////
- int asm_RGB(int R, int G, int B) //
- {
- int nRes = 0;
- __asm
- {
- mov eax, B
- shl eax, 8
- add eax, G
- shl eax, 8
- add eax, R
- mov nRes, eax
- }
- return nRes;
- }
- ///////////////////////////////////////////////////////
- int _RGB(int R, int G, int B) //
- {
- int nRes = 0;
- nRes = nRes | B;
- nRes = nRes << 8;
- nRes = nRes | G;
- nRes = nRes << 8;
- nRes = nRes | R;
- return nRes;
- }
- ;Интерфейс на Си
- #include <stdio.h>
- #include <windows.h>
- extern "C"
- {
- int __stdcall _RGB( int, int, int);
- int* __stdcall _decomposite_RGB(int);
- }
- ///////////////////////////////////////////////////////
- int main() //
- {
- int n = RGB(11, 22, 33);
- printf("_RGB = %d \n", _RGB(11, 22, 33));
- printf(" RGB = %d \n", n);
- int *pn = _decomposite_RGB(2168331);
- printf(" arr[0] = %d \n", pn[0]);
- printf(" Red = %d \n", pn[1]);
- printf(" Green = %d \n", pn[2]);
- printf(" Blue = %d \n", pn[3]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement