Reputation:
I am required to write a program in ARM assembly language that takes an integer as input and returns the integer value of that integer times 6.985. For example, if 36 is entered as input then the result will be 251.
I can only use the built in function add (which adds two integers), mul (which multiplies two integers), divide (which divides two integers), getnum (which gets an integer as input from user), and printnum (which prints the output into the screen). My approach is to first multiply by 6985 and then divide by 1000.
Here's my code for the mul function:
bl getnum
mul r0, r0, #6985
bl printnum
Here's my code for the divide function:
bl getnum
mov r1, #1000
bl divide
mov r4, r0
mov r5, r1
bl printnum
mov r0, r5
bl printnum
My question is how can I combine the two method so that it performs multiplication and division at once? I am still new to this language so I don't know how to get rid of the getnum in the divide function and combine it with the mul function.
Upvotes: 1
Views: 10577
Reputation: 28474
To get a whole picture you need to post entire code, including actual definitions of getnum
, divide
, and printnum
.
Let's assume:
getnum
gets an integer from somewhere (console?) and stores it in r0
divide
function that is referenced in your code divides r0
by r1
, and saves the result in the same registers (not sure what r1
is, perhaps division reminder).printnum
just prints out the value of r0
.If my assumption is correct, just combine your code together:
bl getnum
mul r0, r0, #6985
mov r1, #1000
bl divide
bl printnum
Bonus
AFAIK you cannot use the same register for mul
command. Not sure if it's applicable to all ARM's or not.
Upvotes: 1