Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
96
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.     newLine: .ascii "\n"
  9.     star: .ascii "*"
  10.     space: .ascii " "
  11.     height: .long 0
  12.     counter1: .long 0
  13.     counter2: .long 1
  14. .text
  15. .global _start
  16. _start:
  17.     movl $READ, %eax
  18.     movl $STDIN, %ebx
  19.     movl $height, %ecx
  20.     movl $1, %edx
  21.     int $0x80
  22.  
  23.     movl height, %esi
  24.     sub $48, %esi
  25.     movl %esi, height
  26.     movl %esi, counter1
  27.  
  28. main_loop:
  29.     cmpl $0, counter1
  30.     je printTrunk
  31.  
  32.     pushl counter1
  33.     pushl $space
  34.     decl counter1
  35.     call print 
  36.  
  37.     pushl counter2
  38.     pushl $star
  39.     add $2, counter2
  40.     call print
  41.     call printNewLine
  42.     jmp main_loop  
  43.  
  44. printTrunk:
  45.     pushl height
  46.     pushl $space
  47.     call print
  48.     pushl $1
  49.     pushl $star
  50.     call print 
  51.     call printNewLine
  52.  
  53.     movl $EXIT, %eax
  54.     int $0x80
  55.  
  56. .type print, @function
  57. print:
  58.     movl 8(%esp), %esi
  59.  
  60. print_loop:
  61.     cmpl $0, %esi
  62.     je end_loop
  63.     decl %esi
  64.     movl $WRITE, %eax
  65.     movl $STDOUT, %ebx
  66.     movl 4(%esp), %ecx
  67.     movl $1, %edx
  68.     int $0x80
  69.     jmp print_loop
  70.    
  71. end_loop:
  72.     ret
  73.  
  74. .type printNewLine, @function
  75. printNewLine:
  76.     movl $WRITE, %eax
  77.     movl $STDOUT, %ebx
  78.     movl $newLine, %ecx
  79.     movl $1, %edx
  80.     int $0x80
  81.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement