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.         ; Needs fixing though.
  25.     inc ecx
  26.     xor edx, edx
  27.    
  28.     cmp eax, 0
  29.     jne startLoop
  30.  
  31.     push ecx
  32.     imul ecx, 2
  33.  
  34.     mov edx, ecx
  35.  
  36.     mov eax, 4 ; Prints the string (from stack) to screen
  37.     mov ebx, 1
  38.     mov ecx, esp
  39.     add ecx, 4
  40.     int 80h
  41.  
  42.     mov eax, 4 ; Prints a new line
  43.     mov ebx, 1
  44.     mov ecx, _nl
  45.     mov edx, 2
  46.     int 80h
  47.  
  48.     pop eax ; returns the ammount of used characters
  49.  
  50.     leave
  51.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement