I’m just leaving the answer for part (b) & (c) , if someone is confused ( like I was):
Part (b):
VA , is the address generated by the CPU , it is basically the address of the word of a program which is virtually addressed .
VAS ( Virtual address space ) = 16 bits . So, program size at max could be 2^16.
And , in part (b) it’s given that size of page = 512 Bytes.
Also , in the question it’s given that program is divided into equally 8 non-overlapping segments. So size of each segment = 2^16 / 8 = 2^13
Now , no. of pages in a segment = 2^13 / (page size) = 2^13 / 2^9 = 2^4
And no. of cache lines given are 16.
Also tying up with COA , where block numbers are used . Here page numbers will be used , as here no. of memory blocks are nothing but no. of total pages(because we are mapping pages to cache)
So , total no. of pages = No. of Segments * No. of pages in each segment. = 8 * 2^4 = 2^7
Directly Mapped Cache :
This means for every page there’s only one cache line to which it can go.
In case of directly mapped we can find tag bits two way :
1st Way :
No. of memory blocks / no . of cache lines (COA terms)
Here it’s like : No. of pages / no. of cache lines
Therefore , Tag bits = log(2^7 / 2^4) = 3
2nd Way :
We could’ve directly find by :
Tag bits = 16(Total bits) – 9 (page offset) – 4 (cache line 2^4) = 3
We’re subtracting cache addressing bits because in directly cached , each page has only one cache line to go.
Fully Associative :
In fully associative any block can go to any cache line. So , here any page can go to any cache line.
Hence , to differentiate between pages we need to save whole page number in tag .
Therefore , tag bits = log(Total number of pages) = log(2^7) = 7
2-Way Set associative:
No. of sets = No . of cache line / no. of set per cache line = 16/2 = 8
Now here each page can map to at most 2 cache lines .
Here also we can do it 2 ways like we did previously in directly mapped:
1st Way :
Tag bits =log( No. of block / No. of sets) [COA terms]
So , here : Tag bits : = log(No. of pages / no. of sets) = log(2^7 / 2^3 ) = 4 bits
2nd Way :
Bits used in set = 3
Therefore :
Tag bits = Total – offset – set bits = 16 – 9 – 3 = 4
For part c) :
They're asking the aging bits. And Page table entry(PTE) contains frame number and some additional bits.
So No. of frames = 2^16 / 2^9 = 2^7
Therefore aging bits = Total bits – frame number bits – additional bits = 16-7-1-3-1 = 4 bits.