Skip to content
Advertisement

Translating Java while loop into ARM Assembly?

I want to translate some Java code that calculates the sum from the below loop to ARM assembly, and I am wondering: how I can fix what I have so far?

Here is the Java code I am translating:

JavaScript

And here is the code in ARM Assembly:

JavaScript

Advertisement

Answer

You don’t have to initialize r2 since you can use the immediate value of 100 with cmp:

JavaScript

You can remove the cmp instruction altogether by constructing the loop with decreasing, zero-terminating counter:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement