Advertisement
agmike

Lab5 NASM

Oct 18th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %include "io.inc"
  2.  
  3. section .data
  4. digits: times 10 dd 0
  5. fmt: db "Digit %d: %d", 10, 0
  6.  
  7. section .text
  8. global CMAIN
  9. extern printf
  10.  
  11. CMAIN:
  12.     mov ebp, esp; for correct debugging
  13.     GET_DEC 4, eax
  14.    
  15. cnt_loop:
  16.     xor edx, edx
  17.     mov ecx, 10
  18.     div ecx
  19.     mov ecx, dword[digits+4*edx]
  20.     inc ecx
  21.     mov dword[digits+4*edx], ecx
  22.     cmp eax, 0
  23.     jg cnt_loop
  24.    
  25.     xor eax, eax
  26. print_loop:
  27.     mov ebx, dword[digits+4*eax]
  28.     cmp ebx, 0
  29.     je print_skip
  30.     push ebx
  31.     push eax
  32.     push dword fmt
  33.     call printf
  34.     pop eax           ; pop format argument
  35.     pop eax
  36.     pop ebx
  37. print_skip:
  38.     add eax, 1
  39.     cmp eax, 10
  40.     jl print_loop
  41.    
  42.     xor eax, eax
  43.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement