Practice problems, do not submit for the lab report



Download 0.89 Mb.
Page3/3
Date23.11.2022
Size0.89 Mb.
#60016
1   2   3
Lab 11 SMS factorial RECURSIVE, ITERATIVE, LRU-cache-replacement
To do for the lab report
3] Solve task #24 from the SMS documentation:
24) Write a procedure that works out Factorial N. This example
shows one method for working out factorial N.
Factorial 5 is 5 * 4 * 3 * 2 * 1 = 120. Your procedure
should work properly for factorial 1, 2, 3, 4 or 5.
Factorial 6 would cause an overflow. Use the stack to pass
parameters and return the result. Calculate the result.
Using a look up table is cheating!
Use this starter code:
; ----- Main program for iterative factorial is the same as for recursive------
MOV AL,5 ; Do not try n>5, it overflows
PUSH AL ; Parameter is passed on the stack. Assume >= 0.
CALL 60
POP AL ; Factorial is here
OUT 01 ; Output the result to port 01 (traffic lights)
HALT


; ----- Procedure for iterative factorial--------------------
ORG 60 ; Code starts at address [60]


POP DL ; Return address
POP AL ; Only parameter


;Your code here - initialize the loop!
Loop:
MOV CL, 0
CMP AL, CL
JZ Done


;Your code here - body of loop!


Done:
;Your code here - what needs to be done before returning?
RET
; --------------------------------------------------------------
END

4] Continuing from the state of the cache at the end of #2 (after block 17 was requested), the CPU is requesting the following sequence of blocks:


(13, 1, 2, 1, 2, 42, 43, 17,) 12, 3, 4, 42, 5, 6, 42, 43
Show in the sequence of cache diagrams (handout) how the state of the cache evolves.

12

Download 0.89 Mb.

Share with your friends:
1   2   3




The database is protected by copyright ©ininet.org 2024
send message

    Main page