Advertisement
Guest User

asm

a guest
Oct 12th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. section .text
  2.     global _start       ;must be declared for using gcc
  3.  
  4. _start:
  5.         mov edx, 1      ; flag to be used later
  6.         push edx        
  7.         mov ecx, 9      ; loop counter - 10 numbers to print for the 1st set
  8.         mov eax, `01\n\0`; load the starting string
  9. l1:
  10.         push ecx        ; save the loop counter
  11.        
  12.         mov [num], eax  ; save the updated string to num
  13.         mov eax, 4      ; prepare to write
  14.         mov ebx, 1      ; to stdout
  15.        
  16.         mov ecx, num    ; from num's address
  17.         add ecx, edx    ;   +1 if we're in the first set of loops
  18.                         ;   to skip the 1st byte (the 10s digit)
  19.        
  20.         push edx        
  21.         mov edx, 3      ; total 3 bytes
  22.         int 0x80        ; do the write
  23.         pop edx
  24.        
  25.         mov eax, [num]  ; load num so we can update it
  26.         add eax, 0x100  ; increment 2nd byte (i.e. 1s digit)
  27.        
  28.         pop ecx         ; restore the loop counter
  29.         loop l1
  30.        
  31.         ; after loops are done
  32.         cmp edx, 0      ; did we just finish the 2nd set?
  33.         je  done        ; done if we did
  34.  
  35.         mov ecx, 3      ; if not, set it up - 4 numbers to print this time
  36.         mov edx, 0      ; update the flag & stop skipping the 1st byte when writing
  37.        
  38.         mov eax, `10\n\0`; new string - 1s place starts at '0', 10s place is '1'
  39.         jmp l1          ; start the 2nd set
  40.        
  41. done:
  42.         mov eax,1       ; exit
  43.         int 0x80
  44.  
  45. section .bss
  46.         num resb 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement