Advertisement
Guest User

Untitled

a guest
Apr 15th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global main
  2.  
  3. extern printf
  4. extern scanf
  5.  
  6. section .text
  7.  
  8. read:
  9.     mov ebx, esp
  10.     sub ebx, 4
  11.     push ebx
  12.     push fmt_scanf
  13.     call scanf
  14.     pop eax
  15.     pop eax
  16.     ret
  17.  
  18. main:
  19.     call read
  20.     mov edx, eax        ; put number N to edx
  21.  
  22.     xor eax, eax
  23.     mov ecx, edx
  24.  
  25. loop:
  26.     dec ecx
  27.     push edx
  28.     push ecx
  29.     call read
  30.     pop ecx
  31.     pop edx
  32.     push eax
  33.     cmp ecx, 0
  34.     jne loop
  35.  
  36.     mov ecx, edx
  37. L1:
  38.     dec ecx
  39.  
  40.     pop eax             ; number that i want to print now
  41.     push ecx            ; to save the counter
  42.     push eax
  43.     push fmt_printf
  44.     call printf
  45.     pop eax
  46.     pop eax
  47.     pop ecx
  48.     xor eax,eax
  49.     cmp ecx, 0
  50.     jne L1
  51.  
  52.     xor eax, eax
  53.     ret
  54.  
  55. section .data
  56.     here:       db "here", 0x0A, 0
  57.     fmt_scanf:  db "%ld", 0
  58.     fmt_printf: db "%ld ", 0
  59.     fmt_printf_n: db "%ld", 0x0A, 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement