如何执行这段汇编代码
做欧拉计划中的题目时,发现有一些人使用汇编来写的程序,就是不知道他们这个汇编程序是怎么运行的,一般的是不是显示结果的时候都要调用int 10中断吧,但是在他们的程序中没有发现调用中断,这个原理是怎样的呢?
欧拉计划中的第一题:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
Answer:
233168
题意是找到1000以下即可以被3整除,或可以被5整除的所有数的和,在题目的论坛中第一楼的答案是这样的
; for each integer from 1 to 1000 mov ecx, 3 mov esi, 3 mov edi, 5 xor ebx, ebx ; sum_0: mov eax, ecx xor edx, edx div esi test edx, edx je _yes mov eax, ecx xor edx, edx div edi test edx, edx jne _no_yes: add ebx, ecx_no: inc ecx cmp ecx, 1000 jne _0
start: xor edx,edx ;sum mov eax,3 .while eax < 1000 add edx,eax add eax,3 .endw mov eax,5 .while eax < 1000 add edx,eax add eax,15 .endw mov eax,10 .while eax < 1000 add edx,eax add eax,15 .endw