简体   繁体   中英

How would one 'return' a value in Assembly/LC-3?

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; }
     }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM