views:

33

answers:

1

I have some OAM code here, and I've looked up all the instructions, what they do how they act, and I've re written it all pseudo, but I'm having a problem locating (so I can count how many) loops are in the program. I feel like it should be staring me in the eyes, and I've done a thousand factorial programs in C/Java etc.. but I can't see it here.

alt text

So it takes in user entry if == 0 it breaks to done [brz] if > 0 break to skip [brp] neg used to negate value for abs value

Skip routine does the multiplication and decrememnts, followed by more conditions to see if it needs to be called again or if the program is done.

I need essentially to find the loops in this program. Like I said, it's probably staring me in the face but it's a loosely asked question on the assigner's part..

EDIT to clarify: The program doesn't take the factorial of one number, but rather multplies the factorial of each number entered.

So I could put in 3, -4, 2, 0 and the result will be 288. (3*2*1)(4*3*2*1)(2*1)

EDIT for BRI:

read: noop
      lda stdin
      brp return
      neg

return: bri read
+1  A: 

Well, it's not just a factorial.. This would be the C version:

    int result = 1, value;
    while(value = get_int()) {
next_loop:
        value = abs(c);
        do {
skip_loop:
            result *= value;
            value--;
        } while (value > 0);
    };
    printf("%d\n", result);

So it's the product of the factorials, and there are exactly two loops.

ruslik
Does anyone know the instruction 'BRI'? I've found BR, BRP, and BRZ but not I..
John Redyns
@John do you have it in context? post it. Could mean `BRanch Inequal` if there is no BRNZ opcode.
ruslik
I'm trying to analyze this snippet..Edited in above..
John Redyns
Break indirectly.
John Redyns