循环汇编语言 [英] Looping in assembly language
本文介绍了循环汇编语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用循环和/或跳转在汇编中转换此C#代码
how do I translate this C# code in assembly using loops and/or jumps
int sum = 0;
int count = 15;
while (count != 0)
{
if (count % 2 != 0)
sum = sum + count;
count--;
}
Console.WriteLine(sum);
推荐答案
通常是"while"
a "while" is usually
L_repeat:
compare while_condition
jumpIfFalse L_exit
... loop body ...
jump L_repeat
L_exit:
如果是,还必须反转条件:
also for an if, you have to invert the condition:
compare if_condition
jumpIfFalse L_skip
... inside if
L_skip:
然后您需要注册,一个要保存您的数量,一个要进行总和,然后显示以下内容:
then you need to Registers, one to hold your count, one for the sum, and come out with something like this:
mov Rsum,0
mov Rcount,15
L_repeat:
cmp Rcount,0
jz L_exit ; jump if not (Rcount != 0) gets jump if Rcount==0
mov Rtemp, Rcount
and Rtemp, 1
jz L_skip
add Rsum, Rcount
L_skip:
dec Rcount
jmp L_repeat
l_exit:
这篇关于循环汇编语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文