Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. section .text
  2. [GLOBAL printnum:]
  3.  
  4.  _nl    db  0x0A
  5.  
  6. printnum:
  7.     enter 0,0
  8.  
  9.     mov eax, [ebp+8]
  10.  
  11.     xor ebx, ebx
  12.     xor ecx, ecx
  13.     xor edx, edx
  14.     push ebx
  15.     mov ebx, 10
  16.  
  17. startLoop:
  18.  
  19.     idiv ebx
  20.     add edx, 0x30
  21.  
  22.     push dx ; With an odd number of digits this will screw up the stack, but that's ok
  23.         ; because we'll reset the stack at the end of this function anyway
  24.     inc ecx
  25.     xor edx, edx
  26.    
  27.     cmp eax, 0
  28.     jne startLoop
  29.  
  30.     push ecx
  31.     imul ecx, 2
  32.  
  33.     mov edx, ecx
  34.  
  35.     mov eax, 4
  36.     mov ebx, 1
  37.     mov ecx, esp
  38.     add ecx, 4
  39.     int 80h
  40.  
  41.     mov eax, 4
  42.     mov ebx, 1
  43.     mov ecx, _nl
  44.     mov edx, 2
  45.     int 80h
  46.  
  47.     pop eax
  48.  
  49.     leave
  50.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement