You are not logged in.
Hey,
This year I started at university and one of my current courses require me to program some simple applications in Assembly (IA-32 variant). As a bonus exercise, my partner and I are redoing all the exercises in a different architecture. We chose to do it on ARMv6 (Raspberry Pi).
Because this is a bonus exercise, we have to figure everything out by ourselves. We read some guides/how-to's and some simple Hello World applications and from there on, set out to do it. The first two assignments are working, but now we are stuck in assignment three that requires us to implement the following:
Write a program called “power” which contains an implementation of your pow subroutine.
The main routine should ask the user for a positive base and exponent. The program should
then calculate the resulting power using the pow subroutine and print the return value.
We can correctly get the user's input, the subroutine is called correctly and the loop is also working - but the output is always 1. We've been looking at it for hours, asked classmates et cetera but we can not figure it out. Since I always get excellent help here, I thought I'd try my luck here.
Here is the code:
EDIT: Apparantly, my professor thinks that what I'm doing is fraud so before I get caught, I have removed the code so I won't get in trouble. Thanks for all the input, but I'm going to have find another way to solve this...
Last edited by Unia (2013-10-16 15:04:05)
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
I don't speak RISC, but how do you transfer control back at in line line labeled 'end'. Like I said, I don't speak RISC, but that looks like a load operation.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Whoops, that section looked badly (had to format the code on here, overlooked this one).
It is supposed to look like this:
end: ldr lr, [sp], #+4
bx lr
Does that answer your question?
Last edited by Unia (2013-10-15 16:09:36)
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Yes, but I was hoping it was a case of your program running off in to rough someplace. It looks like it is not the case
I'll poke around some more later. I am out of time right now,
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Oke, thank you very much in advance
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
According to http://infocenter.arm.com/help/index.js … IHGGJ.html, the first two registers to mul cannot be the same. You have mul r0, r0, r2, try mul r0, r2, r0?
Offline
You're right - but this doesn't fix our issue. Strange enough, in the next assignment (in which you need to calculate the factorial of the input) the very same mul instruction is working correctly.
We have now verified that it just reprints whatever we initially place in register 0, so for some reason the multiplication is not placing the result in r0 correctly. EDIT2: If we don't put an initial value in r0, it does again print a value of 1.
However, as this is mostly the same as the factorial application, we just don't see what is failing. For reference, here is the factorial code: EDIT: The mul instruction is changed here already, according to the manual linked to.
EDIT: Code has been removed for the same reason as in the opening post. My apologies, I know the forum doesn't like this.
Last edited by Unia (2013-10-16 15:03:14)
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
For those that did see the code and just for completion's sake, the solution I came up with was using completely different registers. Instead of r0, r1 and r2 we are now using r3, r4 and r5. The reason behind this is still unclear to me, especially because in the other assignment (the factorial one) I'm using exactly the same instructions with the r0, r1 and r2 registers and there it works without problems.
But hey, it works...
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline