Advertisement
Guest User

AssemblerKolo2AJ

a guest
Jan 17th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. /* C:
  2.  
  3. #include <stdio.h>
  4. char * kodowanie(void *cos, int n);
  5. int main() {
  6. int znaki[] = { 2045122341 };
  7. int n = 10;
  8. char *zakodowane = kodowanie(znaki, 7);
  9.  
  10.  
  11. return 0;
  12. }
  13. */
  14.  
  15. // assembler:
  16.  
  17. .686
  18. .model flat
  19.  
  20. public _kodowanie
  21. extern _malloc : PROC
  22.  
  23. .data
  24.  
  25. znaki db 'ABCDEFGHIJKLMNOP'
  26.  
  27. .code
  28.  
  29. _kodowanie PROC
  30.  
  31. push ebp
  32. mov ebp, esp
  33. mov esi, [ebp+8]
  34. mov ecx, [ebp+12]
  35.  
  36. mov eax, ecx
  37.  
  38.  
  39. push ecx
  40. inc eax
  41. push eax
  42. call _malloc
  43. add esp, 4
  44. pop ecx
  45. mov edi, eax
  46.  
  47. mov edx, OFFSET znaki
  48. xor eax, eax
  49.  
  50. shr ecx, 1
  51. jnc dalej
  52.  
  53. mov al, byte ptr[esi+ecx]
  54. shl ecx, 1
  55. and al, 0F0h
  56. shr al, 4
  57. mov bl, [edx+eax]
  58. mov [edi+ecx], bl
  59. mov [edi+ecx+1], byte ptr 0
  60. shr ecx, 1
  61.  
  62. dec ecx
  63.  
  64. dalej:
  65. push eax
  66. mov al, byte ptr[esi+ecx]
  67. shl ecx, 1
  68. and al, 0F0h
  69. shr al, 4
  70. mov bl, [edx+eax]
  71. mov [edi+ecx], bl
  72.  
  73. shr ecx, 1
  74. pop eax
  75.  
  76. mov al, byte ptr[esi+ecx]
  77. shl ecx, 1
  78. and al, 0Fh
  79. mov bl, [edx+eax]
  80. mov [edi+ecx+1], bl
  81.  
  82. shr ecx, 1
  83.  
  84. dec ecx
  85. cmp ecx, -1
  86. jne dalej
  87.  
  88. mov eax, edi
  89. pop ebp
  90. ret
  91.  
  92. _kodowanie ENDP
  93. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement