Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. EXIT = 1
  2. READ = 3
  3. WRITE = 4
  4. STDIN = 0
  5. STDOUT = 1
  6.  
  7. .data
  8.     star: .ascii "*"
  9.     space: .ascii " "
  10.     new_line: .ascii "\n"
  11.     start_height: .long 0
  12.     height: .long 0
  13.     star_countner: .long 1
  14.  
  15. .text
  16. .global _start
  17. _start:
  18.     movl $READ, %eax        # GETTING USER INPUT
  19.     movl $STDIN, %ebx
  20.     movl $height, %ecx
  21.     movl $1, %edx
  22.     int $0x80  
  23.     movl height, %esi      
  24.     subl $48, %esi          # ASCII -> LONG XD
  25.     movl %esi, height
  26.     movl %esi, start_height
  27.  
  28. space_loop:                 # PRINTING SPACES
  29.     movl height, %esi
  30.     cmpl $0, %esi
  31.     je print_trunk          # END OF TREE -> PRINT TRUNK
  32.     pushl %esi              # 2ND ARGUMENT - NUMBER OF SIGNS TO PRINT
  33.     movl $space, %ecx  
  34.     pushl %ecx              # 1ST ARGUMENT - SIGN TO PRINT
  35.     decl %esi
  36.     movl %esi, height
  37.     call print
  38.                            
  39. star_loop:                  # PRINTING STARS
  40.     movl star_countner, %esi
  41.     pushl %esi
  42.     movl $star, %ecx
  43.     pushl %ecx
  44.     add $2, %esi
  45.     movl %esi, star_countner
  46.     call print
  47.     call print_new_line
  48.     jmp space_loop
  49.  
  50. print_trunk:
  51.     movl start_height, %esi
  52.     pushl %esi
  53.     movl $space, %ecx
  54.     pushl %ecx
  55.     call print
  56.     pushl $1
  57.     movl $star, %ecx
  58.     pushl %ecx
  59.     call print
  60.     call print_new_line
  61.    
  62. quit:
  63.     movl $EXIT, %eax
  64.     int $0x80
  65.  
  66. .type print, @function
  67. print:
  68.     pushl %ebp
  69.     movl %esp, %ebp
  70.     movl 12(%ebp), %esi
  71.  
  72. print_loop:
  73.     cmpl $0, %esi
  74.     je end_loop
  75.     decl %esi
  76.     movl $WRITE, %eax
  77.     movl $STDOUT, %ebx
  78.     movl 8(%ebp), %ecx
  79.     movl $1, %edx
  80.     int $0x80
  81.     jmp print_loop
  82.  
  83. end_loop:
  84.     movl %ebp, %esp
  85.     popl %ebp
  86.     ret
  87.  
  88. .type print_new_line, @function
  89. print_new_line:
  90.     movl $WRITE, %eax
  91.     movl $STDOUT, %ebx
  92.     movl $new_line, %ecx
  93.     movl $1, %edx
  94.     int $0x80
  95.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement