Salta al contenuto
Note per Studenti Microcontrollers and DSP - Mock Exam 1 Report

Microcontrollers and DSP - Mock Exam 1

Questa pagina non ha ancora la versione ripasso: qui sotto c'è il testo completo.

In questa pagina 8

Official format (from the course description): a written test with some theoretical questions and some application exercises (programming of microcontrollers and peripherals, DSP); an additional oral exam may follow. The tests of this course are not public, so this mock exam is built only on the notes of the course; the questions and the data are new, and the distribution of the points is a proposal of this site: 4 theory questions of 3 points and 3 exercises of 6 points, for a total of 30 points, in 2 hours. The notes of the course do not yet cover the peripheral units of a microcontroller (timers, converters, serial modules) and the DSP part, so this mock covers the topics that the notes treat: processor, arithmetic circuits, control, number representations, ARM programming, memory and input-output.

How to use it: work with a timer, write the formulas in letters before the numbers, and look at the "Result" only when a question is finished. In the assembly code r0-r3 are registers, labels end with a colon and comments start with @.

Question 1 (points 3)

Describe the ripple-carry adder. (a) How are the NN full adders connected and what is the first carry in? (b) Give the formula of the worst-case delay as a function of the carry delay tct_c and of the sum delay tst_s of a full adder, and say when the worst case occurs. (c) Why can the delay for given operands be much shorter? Finally compute the worst-case delay for N=24N=24, tc=80t_c=80 ps and ts=120t_s=120 ps.

Show the result
  • Cascade of NN full adders, the carry out of stage ii is the carry in of stage i+1i+1, the first carry in is 00.
  • tadd=(N−1) tc+tst_{add}=(N-1)\,t_c+t_s, linear in NN; worst case: all stages propagate and the carry crosses all of them.
  • A generate or delete stage breaks the carry chain: delay =ts+tc×=t_s+t_c\times (longest chain of one generate or delete stage followed by propagate stages).
  • For N=24N=24: 23×80+120=196023\times 80+120=1960 ps.
Show the full solution

A ripple-carry adder is a cascade of NN full adders: the carry out of stage ii is the carry in of stage i+1i+1, and the first carry in is 00 (AddersHalf adder and full adder, generate-propagate-delete decomposition, the ripple-carry adder and its linear worst-case delay, the adder-subtractor, and the fast structures carry-lookahead, carry-bypass, carry-select and square-root carry-select with their delay formulas and optimal block sizes.Adders →). The worst case occurs when every stage is a propagate stage, so that the carry crosses all the stages; the last sum bit then waits N−1N-1 carry delays and one sum delay:

tadd=(N−1) tc+ts,t_{add}=(N-1)\,t_c+t_s,

linear in NN. For N=24N=24, tc=80t_c=80 ps and ts=120t_s=120 ps: 23×80+120=1840+120=196023\times 80+120=1840+120=1960 ps. For real operands the delay is shorter: a generate stage (ABA B) or a delete stage (A‾ B‾\overline A\,\overline B) produces its carry out after tct_c whatever its carry in, so it breaks the chain. The delay is tst_s plus tct_c times the longest chain made of a generate or delete stage followed by consecutive propagate stages.

Typical mistakes: writing N tcN\,t_c (19201920 ps here) or N(tc+ts)N(t_c+t_s) (48004800 ps) instead of (N−1) tc+ts(N-1)\,t_c+t_s, because the sum is computed only once, at the end; using the worst-case formula as if it held for every pair of operands; confusing propagate (A⊕BA\oplus B) with generate (ABA B).

Question 2 (points 3)

Define a RISC architecture. (a) List its main characteristics (at least five). (b) Explain how register windows and register allocation by graph colouring both aim at keeping the operands in registers, and say which of the two is a hardware solution. (c) Four variables ww, xx, yy, zz are such that the pairs ww-xx, xx-yy, ww-yy and yy-zz are live at the same time. How many registers does the colouring need? What does the compiler do if only 2 registers are available?

Show the result
  • RISC: one instruction per cycle in a pipeline, register-register operations with only load and store accessing memory, few simple addressing modes, fixed 32-bit format, many registers, hardwired control, optimization left to the compiler.
  • Register windows: hardware, overlapping windows, parameters passed without copying, oldest windows saved to memory; graph colouring: software, compiler, nodes are variables and edges join variables live together.
  • ww, xx, yy form a triangle: 3 registers are needed (for example w,z→R1w,z\to R_1, x→R2x\to R_2, y→R3y\to R_3).
  • With 2 registers one variable of the triangle is kept in memory (spill).
Show the full solution

A RISC executes one instruction per cycle in a pipeline; only load and store access memory, the other operations work between registers; it has few simple addressing modes, a fixed 32-bit format, many registers and a hardwired control unit, and it leaves the optimization to the compiler (Instruction Set ArchitectureWhat an instruction set defines, the elements of an instruction, operand and operation types, 0-, 1-, 2- and 3-address machines on the same calculation, load/store architectures, and the RISC and CISC design philosophies with register windows and register allocation by graph coloring.Instruction Set Architecture →, Hardwired and Microprogrammed ControlWhat the control unit does, control signals of a single-cycle datapath with the table for each instruction class, hardwired control (combinational or finite-state machine), microprogrammed control (control memory, horizontal and vertical microinstructions, microsequencer), and a comparison.Hardwired and Microprogrammed Control →). Register windows are a hardware solution: many physical registers are divided into windows, each procedure sees one, and the windows of caller and callee overlap, so parameters pass without copying; when nested calls exhaust the windows the oldest are saved to memory. Graph colouring is a software solution: nodes are variables, an edge joins two variables live at the same time, and kk registers mean kk colours. Here w,x,yw,x,y form a triangle: 3 registers are needed; with 2, one variable is kept in memory (spill).

Colouring for 3 registers: w→R1w\to R_1, x→R2x\to R_2, y→R3y\to R_3; zz is adjacent only to yy, so it can take R1R_1 (or R2R_2).

Typical mistakes: saying that register windows are managed by the compiler, or that graph colouring needs special hardware; joining by an edge two variables that are not live at the same time; forgetting that a variable that cannot be coloured is kept in memory.

Question 3 (points 3)

A byte-addressed memory has 20-bit addresses and a direct-mapped cache of m=64m=64 lines with blocks of 8 bytes. (a) Explain where a block is placed and give the three address fields with their widths. (b) Explain how the cache decides between hit and miss and what the word field is used for. (c) The addresses 0x2A4C8 and 0x2A6C8 are used alternately: give their fields and say what happens. (d) At equal capacity, how does a larger block size change the number of lines and the misses?

Show the result
  • Line == (block address)  mod  m\bmod\, m; fields tag 1111 bits, line 66 bits, word 33 bits.
  • The line field selects the line: empty means miss; otherwise compare tags (equal hit, different miss and replacement); the word field only selects the word to send to the CPU.
  • 0x2A4C8: tag 338338, line 2525, word 00; 0x2A6C8: tag 339339, line 2525, word 00: same line, different tags, they evict each other (thrashing).
  • Larger blocks: better spatial locality but fewer lines, more conflicts, longer transfer per miss; an intermediate optimum exists.
Show the full solution

In a direct-mapped cache each block can go into one line only: line == (block address)  mod  m\bmod\, m. Here the fields, from the most significant, are tag 20−6−3=1120-6-3=11 bits, line 66 bits (m=26m=2^6), word 33 bits (blocks of 232^3 bytes) (Cache MemoryBlocks, lines and tags; address decomposition; direct, fully associative and set-associative mapping with field calculation; replacement policies (LRU, FIFO, random); write policies (write-through, write-back with dirty bit, write-allocate); block size; multilevel and split caches; reducing misses; typical address-field questions.Cache Memory →). The line field selects the line: empty means miss; otherwise the line tag is compared with the address tag, equal meaning hit, different meaning miss and replacement. The word field plays no role in this decision; it only selects the word to send to the CPU. 0x2A4C8 has tag 338338, line 2525, word 00; 0x2A6C8 has tag 339339, line 2525, word 00: same line, different tags, so used alternately they evict each other (thrashing). Larger blocks at equal capacity exploit spatial locality better, but there are fewer lines and more conflicts, and each miss takes longer.

Typical mistakes: using the word field to decide hit or miss; confusing the width of the word field (it depends on the number of bytes in the block) with the size of the word; thinking that blocks with different tags can never compete for the same line.

Question 4 (points 3)

Several devices share one interrupt request line. (a) Name the techniques that identify the source of the interrupt. (b) Describe the daisy chain: how the acknowledge travels and what the module does. (c) Three modules M1M_1, M2M_2, M3M_3 are connected in a daisy chain in this order; M2M_2 and M3M_3 request an interrupt together, M1M_1 does not. Which module is served and what does it put on the bus? (d) What does the CPU do with the vector? Why is software polling slow?

Show the result
  • Multiple interrupt lines, software polling, daisy chain (hardware polling), bus arbitration.
  • Daisy chain: the acknowledge passes from module to module; the first with a pending request blocks it and puts its vector on the bus.
  • M2M_2 is served and puts its own vector on the bus; M3M_3 does not receive the acknowledge.
  • The vector selects the routine through the vector table in memory; polling is slow because one routine interrogates the status registers of all the modules.
Show the full solution

The source of an interrupt can be identified with multiple interrupt lines (one per device), with software polling, with a daisy chain, or with bus arbitration (the module must obtain the bus before requesting the interrupt) (Interrupts and ExceptionsClasses of interrupts; interrupt-driven I/O; hardware and software handling sequence with context saving on the stack; identifying the source (multiple lines, polling, daisy chain, vector); priorities and nested interrupts; exceptions and modes in ARM.Interrupts and Exceptions →). In software polling a single routine interrogates the status registers of all the modules, which is slow. In the daisy chain (hardware polling) the acknowledge signal passes from one module to the next; the first module with a pending request blocks it and puts its own vector, a number identifying the routine, on the bus. With M2M_2 and M3M_3 requesting, the acknowledge crosses M1M_1 and stops at M2M_2, which puts its vector on the bus; M3M_3 does not receive the acknowledge. With the vector the CPU jumps directly to the right routine through the vector table in memory.

Typical mistakes: thinking that polling is done by hardware or that all the modules answer the acknowledge together; confusing the vector (a number) with the routine itself; forgetting that the order in the chain decides which module is served first.

Exercise 1 (points 6)

An 8-bit register contains the pattern 1100 10111100\,1011.

a) Give the value of the pattern when it is read as an unsigned integer, in sign-magnitude, in one's complement, in two's complement and in excess 128 (2 points).

b) Write −90-90 on 8 bits in sign-magnitude, in one's complement, in two's complement (with the rule "invert and add 1", and check it with the shortcut of copying up to the first 1) and in excess 128. Then extend the two's complement pattern to 16 bits, and say which value would be obtained if the extension were made by mistake with zeros (2 points).

c) A 12-bit register uses two's complement: give the minimum and the maximum values, and the opposite of the pattern 1000 0000 00001000\,0000\,0000. In sign-magnitude on 12 bits, how many different values can be represented? Finally a 6-bit code uses excess 31: give the codes of −17-17, 00 and +20+20, decode the code 011011011011, and say whether the codes of −17-17 and +20+20 are in the same order as the values (2 points).

Show the result

a) Unsigned 203203; sign-magnitude −75-75; one's complement −52-52; two's complement −53-53; excess 128 +75+75.

b) Sign-magnitude 1101 10101101\,1010; one's complement 1010 01011010\,0101; two's complement 1010 01101010\,0110 (0xA6); excess 128 0010 01100010\,0110 (stored value 3838). Extension to 16 bits: 1111 1111 1010 01101111\,1111\,1010\,0110 (0xFFA6); with zeros: 0000 0000 1010 0110=+1660000\,0000\,1010\,0110=+166.

c) Two's complement on 12 bits: from −2048-2048 to +2047+2047; the opposite of 1000 0000 00001000\,0000\,0000 is 1000 0000 00001000\,0000\,0000 again (+2048+2048 is not representable). Sign-magnitude on 12 bits: 40954095 different values (from −2047-2047 to +2047+2047, with two zeros). Excess 31: −17→001110-17\to001110, 0→0111110\to011111, +20→110011+20\to110011; 011011011011 is −4-4; yes, the order is the same (14<5114<51 as unsigned).

Show the full solution

a) One pattern, five values. The weights of the bits are 128,64,32,16,8,4,2,1128,64,32,16,8,4,2,1, and the pattern has ones in the positions of weight 128,64,8,2,1128,64,8,2,1. The value depends on the convention used to read it (Signed Integer RepresentationsSigned integers on n bits: sign-magnitude, one's complement, two's complement and excess K, with representable ranges, computing the opposite, sign extension and a 4-bit comparison table.Signed Integer Representations →).

  • Unsigned: 128+64+8+2+1=203128+64+8+2+1=203.
  • Sign-magnitude: the most significant bit is the sign, and it is 11, so the number is negative; the magnitude is the other seven bits, 100 1011=64+8+2+1=75100\,1011=64+8+2+1=75. The value is −75-75.
  • One's complement: the most significant bit is 11, so the number is negative; its opposite is obtained by inverting all the bits: 1100 1011→0011 0100=32+16+4=521100\,1011\to0011\,0100=32+16+4=52. The value is −52-52.
  • Two's complement: the most significant bit has negative weight, so −128+64+8+2+1=−53-128+64+8+2+1=-53. Check: a negative −x-x is the unsigned number 28−x2^8-x, and 256−53=203256-53=203.
  • Excess 128: the stored number is x+128=203x+128=203, so x=203−128=+75x=203-128=+75.

b) The number −90-90 in four conventions. First write +90=64+16+8+2=0101 1010+90=64+16+8+2=0101\,1010.

  • Sign-magnitude: change the sign bit and keep the magnitude: 1101 10101101\,1010.
  • One's complement: invert all the bits of +90+90: 0101 1010→1010 01010101\,1010\to1010\,0101.
  • Two's complement: invert and add 11: 1010 0101+1=1010 01101010\,0101+1=1010\,0110. Check with the weights: −128+32+4+2=−90-128+32+4+2=-90. Check with the shortcut: from the right copy the bits up to and including the first 11 (they are 1010), and invert all the others (010110→101001010110\to101001): the result is 1010 01101010\,0110, the same.
  • Excess 128: −90+128=38=32+4+2=0010 0110-90+128=38=32+4+2=0010\,0110.

Sign extension. To pass from 8 to 16 bits the sign bit is replicated on the left, eight more copies of 11: 1111 1111 1010 01101111\,1111\,1010\,0110 (0xFFA6), still −90-90. If the extension is made with zeros the pattern is 0000 0000 1010 0110=128+32+4+2=1660000\,0000\,1010\,0110=128+32+4+2=166: a positive number, equal to 28−902^8-90, not −90-90.

c) Ranges and excess 31. In two's complement on n=12n=12 bits the range is [−2n−1, 2n−1−1]=[−2048, 2047][-2^{n-1},\,2^{n-1}-1]=[-2048,\,2047] (asymmetric). The opposite of 1000 0000 00001000\,0000\,0000: invert, 0111 1111 11110111\,1111\,1111, and add 11, 1000 0000 00001000\,0000\,0000: the same pattern, because +2048+2048 is not representable (edge case of the asymmetry).

In sign-magnitude on 12 bits the range is [−(211−1), 211−1]=[−2047, 2047][-(2^{11}-1),\,2^{11}-1]=[-2047,\,2047]. There are 212=40962^{12}=4096 patterns but two of them are zeros (0000 0000 00000000\,0000\,0000 and 1000 0000 00001000\,0000\,0000), so the different values are 4096−1=40954096-1=4095.

Excess KK stores x+Kx+K as an unsigned number; here n=6n=6 and K=31=25−1K=31=2^{5}-1, so the codes 0…630\dots63 stand for the values −31⋯+32-31\dots+32.

  • −17→−17+31=14=8+4+2=001110-17\to-17+31=14=8+4+2=001110.
  • 0→31=0111110\to31=011111.
  • +20→51=32+16+2+1=110011+20\to51=32+16+2+1=110011.
  • Decoding 011011=16+8+2+1=27011011=16+8+2+1=27, so x=27−31=−4x=27-31=-4.

The order of the codes equals the order of the values: as unsigned numbers 14<5114<51, as values −17<+20-17<+20. This is why the exponent of a floating-point number uses excess KK (Fixed-Point and Floating-Point NumbersFixed-point numbers as an integer divided by 2 to the F with resolution and a sensor example, floating point in base 2, the IEEE 754 single and double formats, conversions in both directions with worked examples, special values and denormals, range, precision, rounding and floating-point operations.Fixed-Point and Floating-Point Numbers →).

Typical mistakes: inverting the bits without adding 11 (that gives one's complement); extending a negative number with zeros; forgetting the asymmetry of two's complement (−2048-2048 has no opposite); reading an excess code as if it were two's complement.

Exercise 2 (points 6)

A routine receives in r0 a signed 32-bit integer aa and in r1 a signed 32-bit integer bb. It must leave in r2 the sum of the absolute values of i=a, a+3, a+6,…i=a,\ a+3,\ a+6,\dots for all the values with i<bi<b. In C:

c
s = 0;  i = a;
while (i < b) {
    t = i;
    if (t < 0) t = -t;
    s = s + t;
    i = i + 3;
}

The variables ii, bb, ss, tt are in r0, r1, r2, r3. The assembly translation has three missing parts, marked with underscores:

armasm
        MOV    r2, #0
loop:   CMP    r0, r1
        ______ out              @ (1) exit when i >= b
        MOV    r3, r0
        CMP    r3, #0
        ______ r3, r3, #0       @ (2) t = |t|, without branches
        ADD    r2, r2, r3
        ADD    r0, r0, #3
        ______ loop             @ (3) repeat
out:

a) Write the three missing parts (2 points).

b) Run the code with a=−7a=-7 and b=9b=9 (the registers hold −7-7 and 99 on entry): give, for each iteration, the value of r0 at the start, of r3 and of r2 at the end. Then give the final values of r0 and r2, the number of iterations, in how many of them the instruction (2) changes r3, and the flags N, Z, C, V produced by the last CMP r0, r1 (2 points).

c) A programmer, thinking of addresses, replaces the instruction (1) with BHS out and runs the code again with r0 =−7==-7= 0xFFFFFFF9 and r1 =9=9. Give the result and the flags N, Z, C, V of the first CMP r0, r1, say what the code does and the final value of r2, and say which family of conditions must be used for signed data (2 points).

Show the result

a) (1) BGE; (2) RSBLT; (3) B.

b) Iterations: r0 =−7,−4,−1,2,5,8=-7,-4,-1,2,5,8; r3 =7,4,1,2,5,8=7,4,1,2,5,8; r2 =7,11,12,14,19,27=7,11,12,14,19,27. Final r0 =11=11, r2 =27=27; 66 iterations; the instruction (2) changes r3 in 33 of them; last CMP r0, r1 (11−9=211-9=2): N=0N=0, Z=0Z=0, C=1C=1, V=0V=0.

c) First CMP: 0xFFFFFFF9−9=0xFFFFFFF00\text{xFFFFFFF9}-9=0\text{xFFFFFFF0} with N=1N=1, Z=0Z=0, C=1C=1, V=0V=0. BHS is taken because C=1C=1: the loop never runs, r2 =0=0 and r0 stays 0xFFFFFFF9. For signed data the signed conditions (GE, GT, LT, LE) must be used.

Show the full solution

a) The missing parts. The while loop goes on as long as i<bi<b, so the exit test is the negated condition i≥bi\ge b, and the numbers are signed: the instruction (1) is BGE out (it tests N=VN=V after the CMP r0, r1; see Control Structures in ARM AssemblyBranch B and conditional branches, signed and unsigned condition codes; translation of if, if-else, while, for and do-while from C to ARM; conditional execution to remove short branches; switch with a jump table.Control Structures in ARM Assembly →). The absolute value is computed as in the note: CMP r3, #0 sets the flags on the sign of tt, and RSBLT r3, r3, #0 computes 0−r30-r3 only if t<0t<0: the instruction (2) is RSBLT, which also avoids a branch and a pipeline flush. At the end of the body the loop starts again with the unconditional branch: the instruction (3) is B.

armasm
        MOV    r2, #0
loop:   CMP    r0, r1
        BGE    out
        MOV    r3, r0
        CMP    r3, #0
        RSBLT  r3, r3, #0
        ADD    r2, r2, r3
        ADD    r0, r0, #3
        B      loop
out:

b) Trace with a=−7a=-7, b=9b=9. At each iteration CMP r0, r1 finds i<9i<9 and BGE is not taken; MOV copies ii into r3; CMP r3, #0 sets the flags on tt; RSBLT changes r3 only if tt is negative; then r2 grows by tt and r0 by 33.

iteration r0 at the start r3 after RSBLT RSBLT changes r3? r2 at the end
1 −7-7 77 yes 77
2 −4-4 44 yes 1111
3 −1-1 11 yes 1212
4 22 22 no 1414
5 55 55 no 1919
6 88 88 no 2727

After the sixth iteration r0 =8+3=11=8+3=11. The next CMP r0, r1 computes 11−9=211-9=2: the result is positive (N=0N=0), non zero (Z=0Z=0), there is no overflow (V=0V=0), and C=1C=1 because 11≥911\ge9 also as unsigned numbers. BGE tests N=VN=V, that is 0=00=0: true, so the branch to out is taken. Final values: r0 =11=11, r2 =7+4+1+2+5+8=27=7+4+1+2+5+8=27, after 66 iterations; the instruction (2) changes r3 in 33 iterations (those with i=−7,−4,−1i=-7,-4,-1). In the other three it is still fetched and executed, but its condition is false and it does nothing.

c) Signed and unsigned conditions. With r0 =0xFFFFFFF9=0\text{xFFFFFFF9} and r1 =9=9, CMP r0, r1 computes 0xFFFFFFF9−9=0xFFFFFFF00\text{xFFFFFFF9}-9=0\text{xFFFFFFF0}, which is negative as a signed number (−16-16), so N=1N=1; it is not zero, Z=0Z=0; the signed result −7−9=−16-7-9=-16 is representable, so V=0V=0. Read as an unsigned number 0xFFFFFFF9 is 4 294 967 2894\,294\,967\,289, which is greater than 99, so the condition HS (C=1C=1, unsigned "greater or equal") is true: C=1C=1. BHS out is therefore taken at the first test: the body never runs, r2 stays 00 (instead of 2727) and r0 stays 0xFFFFFFF9. With BGE the test is N=VN=V, that is 1=01=0, false, and the loop goes on correctly. This is the reason why two families of conditions exist (Control Structures in ARM AssemblyBranch B and conditional branches, signed and unsigned condition codes; translation of if, if-else, while, for and do-while from C to ARM; conditional execution to remove short branches; switch with a jump table.Control Structures in ARM Assembly →): for signed data GE, GT, LT, LE; for unsigned data and addresses HS, HI, LO, LS.

Typical mistakes: using BHS/BHI (unsigned) for signed numbers, or BGT/BLT for addresses; omitting CMP r3, #0 before RSBLT, so that the flags still come from the comparison of ii with bb and not from the sign of tt; putting an instruction with the suffix S between a CMP and the branch that uses its flags.

Exercise 3 (points 6)

A system has 32-bit virtual addresses, 28-bit physical addresses and pages of 8 KB; every page-table entry takes 4 bytes.

a) Compute the number of bits of the offset, of the virtual page number and of the frame number, the number of pages and of frames, and the size of the page table of one process (2 points).

b) The entry of virtual page 0x051EA is valid and contains frame 0x1B5C. Translate the virtual address 0x0A3D5E7C into a physical address. The virtual address 0x0A3D7123 belongs to a page whose entry is not valid: say what happens (2 points).

c) A memory access takes 9090 ns, the TLB access takes 22 ns and the TLB hit rate is 9696 per cent; there are no page faults. Compute the average time of an access with the TLB and without it, and the ratio between the two (2 points).

Show the result

a) Offset 1313 bits; virtual page number 1919 bits, so 219=524 2882^{19}=524\,288 pages; frame number 1515 bits, so 215=32 7682^{15}=32\,768 frames; page table 219×4=2 097 1522^{19}\times4=2\,097\,152 bytes =2=2 MB.

b) Page 0x051EA, offset 0x1E7C; physical address 0x36B9E7C. For 0x0A3D7123 (page 0x051EB, offset 0x1123) the entry is not valid: page fault, an exception; the operating system loads the page from disk into a free or freed frame, updates the table and restarts the instruction.

c) With the TLB 95.695.6 ns; without 180180 ns; ratio about 1.881.88.

Show the full solution

a) Fields and sizes (Virtual MemoryVirtual and physical addresses, pages and frames; translation with the page table and field calculation; page fault and page replacement; TLB and effective access time; protection and sharing; comparison with the cache.Virtual Memory →). The offset has log⁡2(page size)\log_2(\text{page size}) bits: 8 KB=2138\ \text{KB}=2^{13} bytes, so the offset has 1313 bits and it does not change in the translation. The virtual page number has 32−13=1932-13=19 bits, so there are 219=524 2882^{19}=524\,288 pages. The frame number has 28−13=1528-13=15 bits, so there are 215=32 7682^{15}=32\,768 frames; check: 2152^{15} frames of 2132^{13} bytes make 2282^{28} bytes =256=256 MB, the whole physical memory. The page table has one entry for each virtual page: 219×4=2 097 1522^{19}\times4=2\,097\,152 bytes =2=2 MB for each process. It depends on the virtual space, not on the physical memory; this is why multi-level tables are used.

b) Translation. The address 0x0A3D5E7C in binary is 0000 1010 0011 1101 0101 1110 0111 11000000\,1010\,0011\,1101\,0101\,1110\,0111\,1100. The last 1313 bits are 1 1110 0111 11001\,1110\,0111\,1100, that is the offset 0x1E7C; the first 1919 bits are 000 0101 0001 1110 1010000\,0101\,0001\,1110\,1010, that is the page number 0x051EA, the page of the given entry. The entry gives the frame 0x1B5C, which on 1515 bits is 001 1011 0101 1100001\,1011\,0101\,1100. The physical address is the frame number followed by the same offset:

001 1011 0101 1100  1 1110 0111 1100=0011 0110 1011 1001 1110 0111 1100=0x36B9E7C,001\,1011\,0101\,1100\ \,1\,1110\,0111\,1100=0011\,0110\,1011\,1001\,1110\,0111\,1100=\text{0x36B9E7C},

which has 2828 bits, as required.

The address 0x0A3D7123 has page number 0x051EB and offset 0x1123. The entry is not valid: the MMU raises an exception (page fault) and the operating system chooses a free frame, or a page to replace (an approximation of LRU with the reference bit; if the replaced page is dirty it is first written to disk); reads the page from disk, which takes millions of cycles while another process runs; updates the table and restarts the instruction that caused the fault.

c) Average access time. With the TLB a hit costs the TLB access plus the memory access; a miss also needs the access to the page table in memory:

T=0.96 (2+90)+0.04 (2+90+90)=88.32+7.28=95.6 ns.T=0.96\,(2+90)+0.04\,(2+90+90)=88.32+7.28=95.6\ \text{ns}.

Without the TLB every access needs two memory accesses (table and datum): 2×90=1802\times90=180 ns. The ratio is 180/95.6≈1.88180/95.6\approx1.88: the TLB almost halves the time.

Typical mistakes: translating the offset too (only the page number changes); computing the table size from the physical memory instead of the virtual space; forgetting the TLB access in the miss case, or counting only one memory access in the hit case.

Self-assessment grid
Question or exercise Points What is needed for full marks Typical mistakes
Question 1 3 cascade of full adders and first carry in 00 (0.5); (N−1) tc+ts(N-1)\,t_c+t_s and worst case (1); generate or delete breaks the chain (1); 19601960 ps (0.5) N tcN\,t_c or N(tc+ts)N(t_c+t_s); worst case taken as general
Question 2 3 at least five RISC characteristics (1); windows as hardware and colouring as software, with the mechanism (1); 3 registers and spill with 2 (1) windows and colouring exchanged; edge between variables not live together
Question 3 3 placement and fields 11/6/311/6/3 (1); hit or miss decision and role of the word field (0.75); the two addresses in line 2525 and thrashing (0.75); block-size trade-off (0.5) word field used for hit or miss; tags confused
Question 4 3 the four techniques (0.75); daisy chain mechanism (0.75); M2M_2 and its vector (0.75); vector table and polling cost (0.75) polling seen as hardware; vector confused with the routine
Exercise 1 6 five values of the pattern (2); four codes of −90-90 and the extension (2); ranges, opposite of the minimum, 40954095 values, excess 31 (2) inverting without +1+1; zero extension; reading excess as two's complement
Exercise 2 6 BGE, RSBLT, B (2); the table, r0=11r0=11, r2=27r2=27, 66 and 33, the flags (2); flags, BHS taken, r2=0r2=0, signed conditions (2) unsigned conditions for signed data; missing CMP r3, #0
Exercise 3 6 13/19/1513/19/15 bits, 2192^{19}, 2152^{15}, 2 MB (2); 0x36B9E7C and the page-fault steps (2); 95.695.6 ns, 180180 ns, 1.881.88 (2) offset translated; table size from physical memory
Total 30