Guest User

Untitled

a guest
Jan 16th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. .386
  2. .model flat, stdcall
  3. option casemap:none
  4.  
  5. include masm32includewindows.inc
  6. include masm32includemsvcrt.inc
  7. includelib masm32libmsvcrt.lib
  8.  
  9. .data
  10.  
  11. formatstr db "%d",0
  12.  
  13. .code
  14. start:
  15.  
  16. mov eax , 2
  17. mov ecx , 38
  18. mov esi , eax
  19. mov edx , 0
  20.  
  21. .while TRUE
  22. mul esi
  23. mov esi, edx
  24. add esi, eax
  25. mov edx, 0
  26. mov eax, 2
  27. dec ecx
  28. .break .if (!ecx)
  29. .endw
  30.  
  31.  
  32.  
  33.  
  34. invoke crt__cprintf, addr formatstr, esi
  35.  
  36.  
  37. end start
  38.  
  39. xor edx,edx
  40. mov eax,2 ; now you have 2 in edx:eax
  41. mov ecx,38 ; 2^n, in this case 2^38 (any value x, 1 <= x <= 63, is valid).
  42.  
  43. x1: dec ecx ; decrease ecx by 1
  44. jz ready ; if it's 2^1, we are ready.
  45.  
  46. shl eax,1 ; shift eax left through carry flag (CF) (overflow makes edx:eax zero)
  47. rcl edx,1 ; rotate edx through carry flag (CF) left
  48. jmp x1
  49.  
  50. ready: ; edx:eax contains now 2^38.
  51.  
  52. mov ecx,38 ; input (exponent) in ecx. 2^n, in this case 2^38.
  53. ; (any value x, 0 <= x <= 63, is valid).
  54. ; the code begins here.
  55.  
  56. xor eax,eax
  57. xor edx,edx ; edx:eax is now prepared.
  58.  
  59. cmp cl,64 ; if (cl >= 64),
  60. setb al ; then set eax to 0, else set eax to 1.
  61. jae ready ; this is to handle cl >= 64.
  62.  
  63. ; now we have 0 <= cl <= 63
  64.  
  65. sub ecx,1
  66. setnc al ; if (count == 0) then eax = 0, else eax = 1.
  67. lea eax,[eax+1] ; eax = eax + 1. does not modify any flags.
  68. jna ready ; 2^0 is 1, 2^1 = 2, those are ready now.
  69. mov ebx,ecx ; copy ecx to ebx
  70. cmp cl,32 ; if (cl >= 32)
  71. jb low_5_bits
  72. mov cl,31 ; then shift first 31 bits to the left.
  73. shld edx,eax,cl
  74. shl eax,cl ; now shifted 31 bits to the left.
  75. lea ecx,[ebx-31] ; cl = bl - 31
  76.  
  77. low_5_bits:
  78. shld edx,eax,cl
  79. shl eax,cl
  80.  
  81. ready:
  82.  
  83. mul esi
  84. mov esi, edx
  85. add esi, eax
Add Comment
Please, Sign In to add comment