primes/primes.x86.s

110 lines
1.3 KiB
ArmAsm

/* x86 Assembly (AT&T style) version of a Prime Number Finder
haplo@mindstab.net */
.data
numstr: .asciz "%d\n"
max = 100000
scanformat : .asciz "%d"
int = 0
.text
.extern printf
.extern scanf
.extern exit
.global main
printnum:
pushl %ebx
pushl $numstr
call printf
pop %eax
pop %ecx
ret
main:
# scanf code from http://www.linuxgazette.com/issue71/joshi.html
pushl %ebp # save EBP on stack
movl %esp,%ebp # EBP = ESP
subl $4,%esp # create space for x on the stack
leal -4(%ebp),%eax
pushl %eax
pushl $scanformat
call scanf
addl $12, %esp
movl -4(%ebp),%eax
movl %eax, -12(%ebp)
# END scanf code
# The rest is all my code
pushl %eax
movl $3, %ebx
movl $2, %ecx
movl $4, %edx
toploop:
popl %eax
cmp %eax, %ebx
jg end
pushl %eax
pushl %edx
pushl %ecx
pushl %ebx
movl $3, %ecx
checkloop:
popl %ebx
popl %edx
cmp %edx, %ecx
pushl %edx
pushl %ebx
jge showprime
movl $0, %edx
movl %ebx, %eax
divl %ecx
addl $2, %ecx
cmp $0, %edx
je doneloop
jmp checkloop
showprime:
call printnum
doneloop:
popl %ebx
popl %ecx
popl %edx
addl $2, %ebx
cmp %edx, %ebx
jl toploop
addl $1, %ecx
movl %ecx, %eax
mull %eax
movl %eax, %edx
jmp toploop
end:
pushl $0
call exit