Frage

We are supposed to be creating programs in LC3 assembly based on 'pseudo-code' that we are given.

How would I 'return' a value in assembly?

Any and all help is appreciated.

pseudo-code:

int brandonacci(int n) {
    if (n <= -16) {
        return -n/3 + 8;
    }
    else {
        int c1 = brandonacci(n - 2);
        int c2 = brandonacci(n - 7);
        return c1 / 2 - 2 * c2 - 3; }
     }
}
War es hilfreich?

Lösung

Generally, in LC3 assembly you would return a value using a register of your choice.

This means that you would perform a JSR or JSRR to call your subroutine/function, store the value in a register at the end, and RET. Since we know that these instructions only utilize the R7 register we can use the other registers however we wish.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top