; Author: Aclan, Nelson D.
; August 17, 2007

%include "asm_io.inc"

segment .data
      prompt     db    "Find composite numbers up to: ", 0

segment .bss
      Limit    resd  1
      Guess    resd  1

segment .text
      global  asm_main

asm_main:
      enter    0,0
      pusha

      mov   eax, prompt
      call  print_string
      call  read_int
      mov   [Limit], eax
      mov   eax, 4
      call  print_int
      call  print_nl
      mov   eax, 6
      call  print_int
      call  print_nl

      mov   dword[Guess], 8

start:
      mov   eax, [Guess]
      cmp   eax, [Limit]
      jg    end

      mov   eax, [Guess]
      mov   ecx, 2
      cdq
      idiv  ecx
      cmp   edx, 0
      je    print

      mov   eax, [Guess]
      mov   ecx, 3
      cdq
      idiv  ecx
      cmp   edx, 0
      je    print

      mov   eax, [Guess]
      mov   ecx, 5
      cdq
      idiv  ecx
      cmp   edx, 0
      je    print

      mov   eax, [Guess]
      mov   ecx, 7
      cdq
      idiv  ecx
      cmp   edx, 0
      je    print
      jne   increment

print:
      mov   eax, [Guess]
      call  print_int
      call  print_nl
      jmp   increment

increment:
      inc   dword[Guess]
      jmp   start

end:
      popa
      mov   eax, 0
      leave
      ret