Advertisement
Guest User

Untitled

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