The exam will be open-book, so that you don't have to memorize the ASCII table or the details of the Pep/7 architecture.
int a, b, limit; int main() { a = 0; b = 1; cin >> limit; while (b < limit) { b += a; a = b - a; } cout << a << endl; }
BR main n: .BLOCK d#2 fact: .WORD d#1 main: LOADA d#7, i STOREA n, d L1: COMPA d#0, i BREQ L2 JSR mul LOADA n, d SUBA d#1, i STOREA n, d BR L1 L2: DECO fact, d CHARO h#0a, i STOP i: .EQUATE d#0 p: .EQUATE d#2 mul: ADDSP d#-4, i LOADA d#0, i STOREA p, s STOREA i, s L3: COMPA n, d BREQ L4 LOADA p, s ADDA fact, d STOREA p, s LOADA i, s ADDA d#1, i STOREA i, s BR L3 L4: LOADA p, s STOREA fact, d ADDSP d#4, i RTS .END
mul
doesn't
use the global variables n
and fact
; instead, it should
take the values of n
and fact
as parameters, and produce
the new value of fact
as a return value. Show both the
modifications necessary to mul
and to main
.