Jeff C.

asked • 08/16/21

Introduction to Branching in ARM Assembly

Open the factorial.s file, and open it up in a text editor of your choice. Note that word processors (e.g., Microsoft Word, Pages, Google Docs) will probably not work for this purpose, as you must save your file as plain text. You must write ARM assembly code that will compute the factorial of an input number, along with showing intermediate values along the way. Psuedocode showing what you need to implement is shown below:

n = <<first integer read from "one_int.txt">>
accum = 1
while (n != 0) {
accum = accum * n
print accum
print "\n"
n = n - 1
}
print accum
print "\n"

A sample run of the program with the given one_int.txt file is shown below:

5
20
60
120
120
120

The code you write will likely look similar to the ARM assembly code in while_loop.s, which is a translation of the Java code in WhileLoop.java.

Your code must be able to work with more than just 5. With this in mind, be sure to test your solution! At the very least, you should test values between 1 and 10. You may assume that no negative inputs will be given as inputs.


1 Expert Answer

By:

Patrick B. answered • 08/16/21

Tutor
4.7 (31)

Math and computer tutor/teacher

David W.

It is CLEARLY the case that books and professors TEACH students to build programs from the ground up -- NOT to TRANSLATE high-level programs into assembler. That is unfortunate because translation is a great way to learn (because the code usually works rather than requiring endless debugging). If there were many, many TRANSLATIONS of high level code, students could better prepare for initial work assignments -- nearly all junior-level programming jobs involve modifications of existing code rather than generation of new code. Further, this assignment misses an excellent opportunity to use WHILE ( >=0 ) instead of WHILE ( !=0 ) -- if you don't know why, you have years of frustration ahead of you !
Report

08/16/21

Patrick B.

Students need to do both: be able to create from scratch AND translate
Report

08/16/21

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.