Factors of an integer: Difference between revisions
Content added Content deleted
(Added Factors of an integer for EDSAC) |
No edit summary |
||
Line 4,687: | Line 4,687: | ||
[1 2 3 4 5 6 8 9 10 12 15 16 18 20 24 30 36 40 45 48 60 72 80 90 120 144 180 240 360 720] |
[1 2 3 4 5 6 8 9 10 12 15 16 18 20 24 30 36 40 45 48 60 72 80 90 120 144 180 240 360 720] |
||
]</pre> |
]</pre> |
||
=={{header|X86 Assembly}}== |
|||
{{works with|nasm}} |
|||
<lang asm> |
|||
section .text |
|||
global _main |
|||
_main: |
|||
mov ebp, esp;program puts all factors on the local stack surrounded by 0xffffffff (-1) |
|||
mov eax, 12345 ;number of which we want to know the factors |
|||
mov ebx, eax ;save eax |
|||
mov ecx, 1 ;n, factor we test for |
|||
push -1; boundary |
|||
looping: |
|||
mov eax, ebx ;restore eax |
|||
xor edx, edx ;clear edx |
|||
div ecx ;divide eax by ecx (our number by our current factor) |
|||
cmp edx, 0 ;edx stores remainder, if it is 0 we have a factor |
|||
jne next |
|||
push ecx ; we store the found factor on the stack |
|||
next: |
|||
mov eax, ecx |
|||
cmp eax, ebx ;compare the factor we test for with the actual number, if the factor is greater we jump to end |
|||
jg end |
|||
inc ecx ;add 1 to the factor |
|||
jmp looping ;do it again |
|||
end: |
|||
push -1 ;another -1 to mark the boundary on the other side |
|||
mov eax, ebp ;eax now contains highest address of the stack -> maybe call output with that |
|||
mov esp, ebp |
|||
ret |
|||
</lang> |
|||
=={{header|XPL0}}== |
=={{header|XPL0}}== |