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

Microcontrollers and DSP - Mock Exam 2

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

In questa pagina 8

The written test of this course is not public: the official format, from the course description, is a written test with some theory questions and some application exercises (programming of microcontrollers and peripherals, DSP), and an additional oral exam is possible. This mock exam is a proposal of the site, built only on the course notes: the questions and the data are new and it is not a copy of any real test. The distribution of the points is a proposal too: 4 theory questions worth 3 points each and 3 exercises worth 6 points each, for a total of 30 points, in 2 hours.

How to use it: work with a timer, write the formula in letters before the numbers, and look at the "Result" only when a question is finished.

Question 1 (points 3)

Micro-operations of the fetch phase.

a) Write the micro-operations of the fetch phase of a processor with 4-byte instructions, one line per time step, with the register transfers.

b) Which two micro-operations share a time step, and why can they do it? How many cycles would the fetch take if they could not?

c) The clock frequency is 2 GHz2\ \text{GHz} and the PC contains 0x00400120. How long does the fetch last and what is the PC at the end of it?

Show the result
  • t1t_1: MAR←PC\text{MAR}\leftarrow\text{PC}; t2t_2: MBR←M[MAR]\text{MBR}\leftarrow M[\text{MAR}] and PC←PC+4\text{PC}\leftarrow\text{PC}+4; t3t_3: IR←MBR\text{IR}\leftarrow\text{MBR}.
  • The memory read and the PC increment share t2t_2: they use different resources, and micro-operations that do not conflict can share a cycle. Otherwise the fetch would take 44 cycles.
  • Period 0.5 ns0.5\ \text{ns}, fetch 3⋅0.5=1.5 ns3 \cdot 0.5 = 1.5\ \text{ns}; PC == 0x00400124.
Show the full solution

Each phase of the instruction cycle is a sequence of micro-operations, elementary register transfers that take one clock cycle (Fetch-Execute Cycle and DatapathThe registers PC, IR, MAR and MBR, the fetch and execute phases and the four kinds of action, the full instruction-cycle state diagram with interrupt check, a worked accumulator-machine example, and the datapath of a simple RISC core with single-cycle and multicycle timing.Fetch-Execute Cycle and Datapath →). For the fetch: at t1t_1 the address is transferred, MAR←PC\text{MAR}\leftarrow\text{PC}; at t2t_2 the memory is read, MBR←M[MAR]\text{MBR}\leftarrow M[\text{MAR}], and in the same cycle PC←PC+4\text{PC}\leftarrow\text{PC}+4; at t3t_3 the instruction goes to the instruction register, IR←MBR\text{IR}\leftarrow\text{MBR}. The memory read and the PC increment can share t2t_2 because micro-operations that do not conflict, that is, do not use the same resource, can share a cycle; without this the fetch would take 44 cycles instead of 33. At 2 GHz2\ \text{GHz} the period is 1/(2⋅109)=0.5 ns1/(2 \cdot 10^{9}) = 0.5\ \text{ns}, so the fetch lasts 3⋅0.5=1.5 ns3 \cdot 0.5 = 1.5\ \text{ns}, and the PC becomes 0x00400120 + 4=+\,4 = 0x00400124.

Typical mistakes: adding 1 to the PC instead of the length of the instruction (4 bytes); giving the PC increment a cycle of its own and counting 4 cycles; forgetting that the PC is already incremented at the end of the fetch.

Question 2 (points 3)

Normalization in floating point.

a) Explain what it means to normalize a binary number and why a floating-point representation covers very small and very large values with the same number of bits.

b) Normalize 110.01112110.0111_2 and 0.0001120.00011_2 and give, for each, the exponent field EE of the IEEE 754 single-precision format, in which EE is the exponent plus 127127 (excess 127).

c) A student writes E=2E = 2 for the first number. Which mistake was made, and what is the correct field in binary?

Show the result
  • Normalizing = moving the point until a single 1 remains on its left, so that the number is ±1.m⋅2E\pm 1.m \cdot 2^{E}.
  • The exponent records the position of the point: the same bits give tiny and huge values, with constant relative precision.
  • 110.01112=1.1001112⋅22110.0111_2 = 1.100111_2 \cdot 2^{2}, E=2+127=129=1000 00012E = 2 + 127 = 129 = 1000\,0001_2; 0.000112=1.12⋅2−40.00011_2 = 1.1_2 \cdot 2^{-4}, E=−4+127=123=0111 10112E = -4 + 127 = 123 = 0111\,1011_2.
  • Mistake: the bias 127 was forgotten; correct field 1000 000121000\,0001_2.
Show the full solution

Normalizing a binary number means moving the point until a single 1 remains on its left, so that it is written ±1.m⋅2E\pm 1.m \cdot 2^{E} (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 →). The exponent records the position of the point: with the same number of bits both very small and very large values can be written, with constant relative precision. First number: the point moves two places to the left, 110.01112=1.1001112⋅22110.0111_2 = 1.100111_2 \cdot 2^{2}, and with the excess 127 the field is E=2+127=129=1000 00012E = 2 + 127 = 129 = 1000\,0001_2. Second number: the point moves four places to the right, 0.000112=1.12⋅2−40.00011_2 = 1.1_2 \cdot 2^{-4}, and E=−4+127=123=0111 10112E = -4 + 127 = 123 = 0111\,1011_2. The student wrote the exponent itself, 0000 001020000\,0010_2, forgetting to add the bias.

Typical mistakes: writing the exponent without the bias, or applying the bias with the wrong sign when decoding; including the hidden 1 in the 23 bits of the mantissa.

Question 3 (points 3)

The magnetic disk.

a) Describe the physical structure of a magnetic disk: platters, surfaces, heads and arm, tracks and sectors.

b) What is a cylinder, and why can the data of a cylinder be read without moving the arm?

c) A disk has 3 platters, 2000 tracks per surface, 150 sectors per track and 4096 bytes per sector. Compute its capacity.

Show the result
  • Rotating platters coated with magnetic material, two surfaces each; one read/write head per surface, all mounted on the same arm and moving together; each surface is divided into concentric tracks, each track into sectors (the smallest unit that is read or written).
  • Cylinder = the set of tracks at the same position on all the surfaces; the heads are in parallel on those tracks, so no arm movement is needed.
  • 66 surfaces; capacity =6⋅2000⋅150⋅4096=7 372 800 000= 6 \cdot 2000 \cdot 150 \cdot 4096 = 7\,372\,800\,000 bytes, about 7.4⋅1097.4 \cdot 10^{9} bytes.
Show the full solution

A magnetic disk has rotating platters coated with magnetic material; each platter has two surfaces, and each surface has a read/write head, all mounted on the same arm (External Memory - Disks, RAID and Optical StorageMagnetic disk (platters, surfaces, tracks, sectors, cylinders); access time as the sum of seek, rotational latency and transfer, with formulas and an example; scheduling algorithms FCFS, SSTF and elevator; RAID levels 0 to 6; SSD; CD, DVD and tapes.External Memory - Disks, RAID and Optical Storage →). Each surface is divided into concentric tracks, and each track into sectors, the smallest unit that is read or written. A cylinder is the set of the tracks at the same position on all the surfaces: since the heads are in parallel on those tracks, the data of a cylinder can be read without moving the arm. The capacity is surfaces times tracks times sectors times bytes per sector. With 3 platters there are 3⋅2=63 \cdot 2 = 6 surfaces, so 6⋅2000⋅150⋅4096=7 372 800 0006 \cdot 2000 \cdot 150 \cdot 4096 = 7\,372\,800\,000 bytes.

Typical mistakes: using the number of platters instead of the number of surfaces in the capacity (the result would be half); confusing a cylinder with a single track; confusing a track with a sector.

Question 4 (points 3)

Interrupt priorities. A processor serves three devices by interrupts: a printer, a disk and a communication line that loses data if it is not served quickly.

a) Describe the two ways to handle a request that arrives while a service routine is running: disabling the interrupts and using priorities. Which are the advantages and the limits of each?

b) Which order of priority do you give to the three devices, and why?

c) The routine of the printer is running when the disk makes a request and, a little later, the communication line makes another one. In which order are the three routines completed (i) if the interrupts are disabled during the routines, (ii) if priorities are used with the order of part b?

Show the result
  • Disabling the interrupts: requests stay pending and are served afterwards, in order; simple, but an urgent device waits.
  • Priorities: a routine can be interrupted by a request of higher priority (nested interrupts).
  • Order: printer lowest, disk medium, communication line highest (it loses data if it is not served quickly).
  • (i) printer, disk, communication line (the communication line waits for two routines). (ii) The disk interrupts the printer and the communication line interrupts the disk: communication line, disk, printer.
Show the full solution

A service routine can be protected from new requests in two ways (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 →). With the interrupts disabled during the routine, further requests stay pending and are served afterwards, in order: simple, but an urgent device must wait. With priorities, a routine can be interrupted by a request of higher priority (nested interrupts). The printer gets the lowest priority, the disk a medium one and the communication line the highest, because it loses data if it is not served quickly. (i) With the interrupts disabled the two requests stay pending and are served in order: printer, disk, communication line; the line waits for two routines and may lose data. (ii) With priorities the disk interrupts the printer, the communication line interrupts the disk: the routines are completed in the order communication line, disk, printer.

Typical mistakes: serving the pending requests by priority when the interrupts are disabled (they are served in order); giving the highest priority to the printer because it started first; thinking that a request of lower priority can interrupt a routine of higher priority.

Exercise 1 (points 6)

a) Multiply the unsigned numbers A=101112A = 10111_2 and B=110102B = 11010_2 with the method of the partial products: write the five partial products already shifted, add them, and check the result in decimal. How many bits has the product?

b) An array multiplier of NN bits is built with N2N^2 AND gates and N(N−1)N(N-1) full adders. With tcarry=80 pst_{carry} = 80\ \text{ps} and tsum=130 pst_{sum} = 130\ \text{ps}, compute the number of AND gates, the number of full adders and the delay of the critical path for N=6N = 6 and for N=12N = 12. By what factor do the area (AND gates) and the delay grow when NN doubles?

c) An 8-bit register contains 1011 010021011\,0100_2. Write the register after LSL by 2, LSR by 3, ASR by 3 and ROR by 3. Read the original content once as an unsigned number and once as a two's complement number, and say which of LSR by 3 and ASR by 3 is the correct division by 8 in each reading, and whether LSL by 2 gives the product by 4 in 8 bits. Then, for a barrel shifter of 16-bit words, give the number of levels, the number of 2→12\to1 multiplexers and the levels that are active for a shift of 11 positions.

Show the result

a) Partial products 00000000000000000000, 00001011100000101110, 00000000000000000000, 00101110000010111000, 01011100000101110000; sum 10010101102=598=23⋅261001010110_2 = 598 = 23 \cdot 26; the product has 1010 bits.

b) N=6N=6: 3636 AND gates, 3030 full adders, delay 930 ps930\ \text{ps}. N=12N=12: 144144 AND gates, 132132 full adders, delay 1890 ps1890\ \text{ps}. Doubling NN: AND gates ×4\times 4 (full adders about ×4.4\times 4.4), delay about ×2.03\times 2.03.

c) LSL 2: 1101 00001101\,0000; LSR 3: 0001 01100001\,0110; ASR 3: 1111 01101111\,0110; ROR 3: 1001 01101001\,0110. Unsigned (180180): LSR is correct (2222, the integer part of 22.522.5); signed (−76-76): ASR is correct (−10-10, rounded toward −∞-\infty); LSL 2 does not give the product by 4 (720720 and −304-304 do not fit in 8 bits). Barrel shifter: 44 levels, 6464 multiplexers, levels of 11, 22 and 88 positions active.

Show the full solution

a) Partial products. The two numbers are A=101112=16+4+2+1=23A = 10111_2 = 16+4+2+1 = 23 and B=110102=16+8+2=26B = 11010_2 = 16+8+2 = 26 (see Shift Registers, Shifters and MultipliersShift registers (serial-parallel conversion, hold constraint), combinational shifters and the barrel shifter with log2 N multiplexer levels, and multipliers: partial products, array multiplier with N squared AND gates and N(N-1) full adders, Wallace tree, Booth, sequential shift-and-add, and dedicated FPGA DSP blocks.Shift Registers, Shifters and Multipliers →). For every bit BjB_j of the multiplier the partial product is A⋅BjA \cdot B_j shifted by jj positions: it is AA if Bj=1B_j = 1 and zero if Bj=0B_j = 0. Since the product of two 5-bit numbers has 2N=102N = 10 bits, each row is written on 10 bits:

  0000000000   B0 = 0: zero
  0000101110   B1 = 1: A shifted by 1   (46)
  0000000000   B2 = 0: zero
  0010111000   B3 = 1: A shifted by 3   (184)
  0101110000   B4 = 1: A shifted by 4   (368)
  ----------
  1001010110   sum

Check in decimal: 46+184+368=59846 + 184 + 368 = 598 and 23⋅26=59823 \cdot 26 = 598. In binary 10010101102=512+64+16+4+2=5981001010110_2 = 512 + 64 + 16 + 4 + 2 = 598. The product has 2N=102N = 10 bits; it is smaller than 210=10242^{10} = 1024, so it fits. Typical mistake: giving the product only 5 bits.

b) Cost and delay of the array multiplier. With the formulas of the course the number of AND gates is N2N^2, the number of full adders is N(N−1)N(N-1) and the critical path crosses about 2N2N cells:

tmult≈(2N−2) tcarry+tsumt_{mult} \approx (2N-2)\,t_{carry} + t_{sum}

For N=6N = 6: AND gates 62=366^2 = 36; full adders 6⋅5=306 \cdot 5 = 30; delay (2⋅6−2)⋅80+130=10⋅80+130=930 ps(2 \cdot 6 - 2) \cdot 80 + 130 = 10 \cdot 80 + 130 = 930\ \text{ps}.

For N=12N = 12: AND gates 122=14412^2 = 144; full adders 12⋅11=13212 \cdot 11 = 132; delay (2⋅12−2)⋅80+130=22⋅80+130=1890 ps(2 \cdot 12 - 2) \cdot 80 + 130 = 22 \cdot 80 + 130 = 1890\ \text{ps}.

When NN doubles, the AND gates grow by 144/36=4144/36 = 4 (area O(N2)O(N^2)), the full adders by 132/30=4.4132/30 = 4.4, and the delay by 1890/930≅2.031890/930 \cong 2.03 (linear in NN: it is not exactly 22 because of the constant tsumt_{sum}). Typical mistake: saying that the array multiplier has a delay O(log⁡N)O(\log N): that is the Wallace tree, which reduces the partial products with 3:2 compressors and ends with a fast adder.

c) Shifts. The register is 1011 010021011\,0100_2: read as unsigned it is 128+32+16+4=180128 + 32 + 16 + 4 = 180; read as two's complement it is 180−256=−76180 - 256 = -76.

  • LSL by 2: the bits move toward the MSB and two zeros enter from the right: 1011 0100→1101 00001011\,0100 \to 1101\,0000 (208208). The two bits that leave on the left (1010) are lost.
  • LSR by 3: three zeros enter from the left: 0001 01100001\,0110 (2222).
  • ASR by 3: the sign bit 11 is replicated three times: 1111 01101111\,0110, which is −10-10.
  • ROR by 3: the three bits that leave on the right (100100) re-enter on the left: 100 10110=1001 0110100\,10110 = 1001\,0110 (150150).

Unsigned reading: the correct division by 8 is LSR, 180/8=22.5180/8 = 22.5 and the register gives 2222. Signed reading: the correct division is ASR, −76/8=−9.5-76/8 = -9.5 and the register gives −10-10, because the result is rounded toward −∞-\infty; LSR would give 2222, which is wrong for a negative number. LSL by 2 should give 4⋅180=7204 \cdot 180 = 720 (unsigned) or 4⋅(−76)=−3044 \cdot (-76) = -304 (signed): neither fits in 8 bits (maximum 255255, minimum −128-128), so the 8-bit result 208208 is not the product. Typical mistake: using LSR on a signed number.

Barrel shifter with N=16N = 16: the number of levels is log⁡216=4\log_2 16 = 4, each level has 1616 multiplexers 2→12 \to 1, so the total is Nlog⁡2N=16⋅4=64N \log_2 N = 16 \cdot 4 = 64. Level jj shifts by 2j2^j positions (1, 2, 4, 8) if bit jj of the shift amount is 1. For s=11=10112s = 11 = 1011_2 the bits 0, 1 and 3 are 1: the levels of 11, 22 and 88 positions are active (1+2+8=111 + 2 + 8 = 11) and the level of 44 positions is bypassed. The delay is that of 44 multiplexers, whatever the shift amount.

Exercise 2 (points 6)

In this exercise the variables a, b, c, d of a C program are in the registers r0, r1, r2, r3; r5 and r6 can be used as temporary registers. All values are 32-bit.

a) Translate into ARM assembly, without the instruction MUL and with four instructions, the C statement a = 9*b + ((c & 0xF0) >> 4) - d; for unsigned variables. Give the contents of r5, r6 and r0 at the end for b = 12, c = 0xB7 and d = 5.

b) The register r0 contains 0x5A. Write three instructions that, in this order, set bits 0 and 2, clear bits 4 and 6, and invert bits 1 and 7, and give r0 in hexadecimal after each one. Then extract byte 1 (bits 15 to 8) of r1 = 0x1F2E3D4C into r2 with two instructions.

c) Say which of the constants #0x3FC, #0x1FE, #0xFF000000, #0x101 can be used directly as the immediate operand of a data-processing instruction, and how to load in r7 those that cannot. Then give the flags N, Z, C, V after ADDS r2, r0, r1 with r0 = 0xFFFFFFF0 and r1 = 0x10, after ADDS r4, r3, #0x200 with r3 = 0x7FFFFF00, and the flags N and Z after TST r0, #8 with r0 = 0xFFFFFFF0.

Show the result

a)

armasm
ADD r5, r1, r1, LSL #3
AND r6, r2, #0xF0
ADD r5, r5, r6, LSR #4
SUB r0, r5, r3

Final values: r6 = 0xB0 (176), r5 = 119, r0 = 114.

b) ORR r0, r0, #5 gives 0x5F; BIC r0, r0, #0x50 gives 0x0F; EOR r0, r0, #0x82 gives 0x8D. Byte 1: AND r2, r1, #0xFF00 gives 0x3D00, then MOV r2, r2, LSR #8 gives 0x3D.

c) Immediates: #0x3FC yes, #0x1FE no, #0xFF000000 yes, #0x101 no; the last two cases are loaded with LDR r7, =0x1FE (or with MOVW). Flags: first ADDS: result 0, N = 0, Z = 1, C = 1, V = 0. Second ADDS: result 0x80000100, N = 1, Z = 0, C = 0, V = 1. TST: N = 0, Z = 1.

Show the full solution

a) Translation. The register r1 holds b, so 9b=b+8b=b+(b≪3)9b = b + 8b = b + (b \ll 3): the scaled second operand makes it a single instruction, because the shift is free in the barrel shifter and no MUL is needed (ARM Data-Processing InstructionsAdd, subtract, logical, move and multiply instructions of ARM, the immediate and shifted-register second operand, flag updates with S, CMP and TST, and translation of C expressions into ARM code.ARM Data-Processing Instructions →). The shift of the second term is also scaled:

armasm
ADD r5, r1, r1, LSL #3      @ r5 = b + 8*b = 9*b
AND r6, r2, #0xF0           @ r6 = c & 0xF0
ADD r5, r5, r6, LSR #4      @ r5 = 9*b + (r6 >> 4)
SUB r0, r5, r3              @ a = r5 - d

Values: 9⋅12=1089 \cdot 12 = 108; 0xB7 AND 0xF0 =1011 0111 AND 1111 0000=1011 0000== 1011\,0111 \,\text{AND}\, 1111\,0000 = 1011\,0000 = 0xB0 =176= 176; 176≫4=10112=11176 \gg 4 = 1011_2 = 11, so r5 =108+11=119= 108 + 11 = 119; finally 119−5=114119 - 5 = 114. Logical shift right is correct because the variables are unsigned. Typical mistake: writing MUL r5, r1, #9: multiplication needs registers, not constants.

b) Bit operations. In binary, 0x5A =0101 1010= 0101\,1010.

  • Set bits 0 and 2: mask 0000 0101=0000\,0101 = 0x05, ORR r0, r0, #5: 0101 1010 OR 0000 0101=0101 1111=0101\,1010 \,\text{OR}\, 0000\,0101 = 0101\,1111 = 0x5F.
  • Clear bits 4 and 6: mask 0101 0000=0101\,0000 = 0x50; BIC computes Rn AND NOT Op2Rn \,\text{AND NOT}\, Op2, so BIC r0, r0, #0x50: 0101 11110101\,1111 with bits 6 and 4 cleared gives 0000 1111=0000\,1111 = 0x0F.
  • Invert bits 1 and 7: mask 1000 0010=1000\,0010 = 0x82, EOR r0, r0, #0x82: 0000 1111 XOR 1000 0010=1000 1101=0000\,1111 \,\text{XOR}\, 1000\,0010 = 1000\,1101 = 0x8D.

Byte 1 of 0x1F2E3D4C is 0x3D: AND r2, r1, #0xFF00 keeps only bits 15 to 8 and gives 0x3D00; MOV r2, r2, LSR #8 brings them down to bits 7 to 0 and gives 0x3D. Typical mistake: using ORR to clear a bit (it can only set), or forgetting the final shift and keeping 0x3D00.

c) Immediates and flags. An immediate is an 8-bit value rotated by an even number of positions. Checking each constant:

  • 0x3FC =11 1111 1100== 11\,1111\,1100 = 0xFF shifted left by 2 (rotation by 30 to the right): valid.
  • 0x1FE =1 1111 1110== 1\,1111\,1110 = 0xFF shifted left by 1: odd number of positions, and the 8 ones cannot be placed otherwise: not valid.
  • 0xFF000000 == 0xFF rotated right by 8: valid.
  • 0x101 =1 0000 0001= 1\,0000\,0001: the ones are 9 positions apart, they do not fit in 8 bits: not valid.

The constants that are not valid are loaded with the pseudo-instruction LDR r7, =0x1FE (the assembler places them in a constant table), or with MOVW r7, #0x1FE for a 16-bit constant; for 0x101 the same instructions apply.

Flags (see also Binary ArithmeticBinary addition and two's complement subtraction, overflow for unsigned (carry) and signed (sign change) numbers, the N Z C V flags, multiplication by shifts and additions, Booth's algorithm with a worked example, division, and logical, arithmetic and rotate shifts.Binary Arithmetic →). First ADDS: 0xFFFFFFF0 + 0x10 = 0x1 00000000 (33 bits), so r2 = 0 with a carry out of the MSB: N = 0, Z = 1, C = 1. The operands have different signs (one negative, one positive), so there is no signed overflow: V = 0. Second ADDS: 0x7FFFFF00 + 0x200 = 0x80000100: the MSB is 1, so N = 1, Z = 0; no carry out of the 32 bits, so C = 0; two positive numbers give a negative one, so V = 1 (as in the example of 0x7FFFFFFF plus 1, now with a different pattern). TST computes the AND without saving it: 0xFFFFFFF0 AND 8 = 0 (bit 3 of 0xF0 is 0), so Z = 1 and N = 0. Typical mistake: reading the carry as signed overflow: in the first ADDS C = 1 but V = 0.

Exercise 3 (points 6)

A system has byte-addressed memory and 14-bit addresses. A cache of 32 bytes has blocks of 8 bytes, uses write-back and write-allocate, and is initially empty. Dirty blocks that are replaced are written back to memory as whole blocks.

a) The cache is fully associative. Compute the number of lines and the fields of the address (tag, word), and say how many tags are compared in one access. Decompose the address 0x2A15 in binary. For each of the ten accesses of the sequence of part b give the block address and the word field; how many different blocks are accessed?

b) The cache is fully associative with LRU replacement. Trace the following sequence of accesses (R = read, W = write, addresses in hexadecimal) and give for each access the block address, hit or miss, and the write-back if any. Give the number of hits and the final content of the cache with the dirty bits.

# 1 2 3 4 5 6 7 8 9 10
op R W R R R W R R W R
address 0A48 1130 0F7C 2A10 0A4C 3318 0A4D 1134 2A15 0F78

c) Repeat part b with FIFO replacement. Explain why the two policies behave differently at access 7, and compare the bytes exchanged with the memory (blocks loaded plus blocks written back) in the two cases.

Show the result

a) 44 lines; word 33 bits, tag 1111 bits; 44 tags compared. 0x2A15 =10 1010 0001 01012= 10\,1010\,0001\,0101_2: tag 0x542 (10101000010210101000010_2), word 55. Blocks of the ten accesses: 0x149, 0x226, 0x1EF, 0x542, 0x149, 0x663, 0x149, 0x226, 0x542, 0x1EF; words 0,0,4,0,4,0,5,4,5,00, 0, 4, 0, 4, 0, 5, 4, 5, 0. Five different blocks.

b) LRU: M, M, M, M, H, M, H, M, H, M; 33 hits, 77 misses; write-backs at access 66 (block 0x226) and access 1010 (block 0x663). Final content: 0x149 clean, 0x226 clean, 0x542 dirty, 0x1EF clean.

c) FIFO: M, M, M, M, H, M, M, M, H, M; 22 hits, 88 misses; write-backs at access 77 (block 0x226) and access 1010 (block 0x542). Final content: 0x663 dirty, 0x149, 0x226, 0x1EF clean. Bytes exchanged: LRU 7⋅8+2⋅8=727 \cdot 8 + 2 \cdot 8 = 72; FIFO 8⋅8+2⋅8=808 \cdot 8 + 2 \cdot 8 = 80.

Show the full solution

a) Fields and blocks. The memory has 214=163842^{14} = 16384 bytes. A block of 8 bytes gives a word field of log⁡28=3\log_2 8 = 3 bits, and the number of lines is 32/8=432/8 = 4 (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 →). In a fully associative cache a block can go into any line, so there is no line or set field: the fields are the word, 33 bits, and the tag, 14−3=1114 - 3 = 11 bits, which is the whole block address. The tag of the address is compared with the tags of all the 44 lines in parallel.

The address 0x2A15 is 10 1010 0001 0101210\,1010\,0001\,0101_2 on 14 bits. The word field is the last 33 bits, 1012=5101_2 = 5; the block address is the other 1111 bits, 101010000102=10101000010_2 = 0x542, which is the tag.

For the sequence, the block address is the address divided by 8 (without the last 3 bits) and the word field is the address modulo 8 (the last 3 bits):

# address block (tag) word
1 0A48 0x149 0
2 1130 0x226 0
3 0F7C 0x1EF 4
4 2A10 0x542 0
5 0A4C 0x149 4
6 3318 0x663 0
7 0A4D 0x149 5
8 1134 0x226 4
9 2A15 0x542 5
10 0F78 0x1EF 0

The different blocks are 55: 0x149, 0x226, 0x1EF, 0x542, 0x663; more than the 44 lines of the cache, so some block will have to be replaced. Typical mistake: using the word field to decide whether the access is a hit: two addresses with different word fields but the same tag belong to the same block (accesses 1, 5 and 7).

b) Trace with LRU. Four lines, so the first four different blocks fill the empty cache. The list shows the cache from the least recently used to the most recently used block; ∗* marks a dirty block.

# access block result cache after (LRU first) write-back
1 R 0A48 149 miss 149 no
2 W 1130 226 miss 149, 226* no
3 R 0F7C 1EF miss 149, 226*, 1EF no
4 R 2A10 542 miss 149, 226*, 1EF, 542 no
5 R 0A4C 149 hit 226*, 1EF, 542, 149 no
6 W 3318 663 miss 1EF, 542, 149, 663* yes: 226
7 R 0A4D 149 hit 1EF, 542, 663*, 149 no
8 R 1134 226 miss 542, 663*, 149, 226 no
9 W 2A15 542 hit 663*, 149, 226, 542* no
10 R 0F78 1EF miss 149, 226, 542*, 1EF yes: 663

Comments: at access 5 the block 0x149 is a hit (word 44 of the block already loaded) and becomes the most recently used; at access 6 the cache is full and the LRU block is 0x226, which is dirty, so the whole block is written to memory before 0x663 is loaded (write-allocate: the block is brought in first, then written, and its dirty bit is set). At access 8 the block 0x226 is loaded again, clean, because memory was updated at access 6. At access 10 the LRU block is 0x663, dirty: second write-back. Result: 33 hits (55, 77, 99) and 77 misses; final content 0x149, 0x226, 0x1EF clean and 0x542 dirty. The dirty block that remains in the cache is not written back at the end of the sequence.

c) Trace with FIFO. The victim is the block loaded first, regardless of the accesses made after: a hit does not change the order. Accesses 1 to 5 are as before (the hit at access 5 does not move 0x149, which stays the oldest). At access 6 the victim is 0x149, which is clean, so there is no write-back; the queue (oldest first) becomes 226*, 1EF, 542, 663*. Access 7 (R 0A4D, block 0x149) is now a miss, while with LRU it was a hit: LRU kept 0x149 because it had been used recently at access 5, FIFO evicted it because it was the oldest loaded. At access 7 the victim is 0x226, dirty: write-back. Then: access 8 (0x226) miss, victim 0x1EF; access 9 (0x542) hit, which sets its dirty bit; access 10 (0x1EF) miss, victim 0x542, now dirty: write-back. Result: 22 hits (55, 99) and 88 misses; final content 0x663 dirty, and 0x149, 0x226, 0x1EF clean.

Bytes exchanged: each miss loads one block of 8 bytes and each write-back writes one block of 8 bytes. LRU: 77 loads and 22 write-backs, 9⋅8=729 \cdot 8 = 72 bytes. FIFO: 88 loads and 22 write-backs, 10⋅8=8010 \cdot 8 = 80 bytes. In this sequence LRU is better because the block used at access 5 is used again at access 7. Typical mistakes: updating the order of the queue on a hit in FIFO; forgetting the write-back of a dirty block that is replaced, or writing back only the modified word instead of the whole block.

Self-assessment grid
Item Points What must be there for full points Typical mistakes
Question 1 3 the three micro-operations of fetch with their time steps; the shared step and the reason, 4 cycles otherwise; 1.5 ns1.5\ \text{ns} and 0x00400124 PC increased by 1; increment in a separate cycle
Question 2 3 normalization as ±1.m⋅2E\pm 1.m \cdot 2^{E} and constant relative precision; E=129E = 129 and E=123E = 123 with the binary fields; the bias identified exponent without bias; hidden bit counted in the mantissa
Question 3 3 platters, surfaces, heads on one arm, tracks, sectors; cylinder and why no arm movement; 6 surfaces and 7 372 800 0007\,372\,800\,000 bytes platters used instead of surfaces; cylinder confused with a track
Question 4 3 disabling against priorities with limits; printer lowest, disk medium, communication line highest; completion orders (i) and (ii) pending requests served by priority; wrong priority order
Exercise 1 6 a) 2 points: five partial products, sum 598598, 10 bits; b) 2 points: 36, 30, 930 ps and 144, 132, 1890 ps, factors; c) 2 points: four shifted registers, LSR/ASR choice, 4 levels, 64 multiplexers, levels 1+2+81+2+8 product on 5 bits; array multiplier O(log⁡N)O(\log N); LSR on a signed number
Exercise 2 6 a) 2 points: four instructions without MUL, values 176176, 119119, 114114; b) 2 points: 0x5F, 0x0F, 0x8D, 0x3D00, 0x3D; c) 2 points: valid immediates, loading, flags of the two ADDS and of TST MUL with a constant; ORR to clear a bit; carry read as overflow
Exercise 3 6 a) 2 points: fields, tags compared, decomposition of 0x2A15, block and word of the ten accesses, five different blocks; b) 2 points: LRU trace with 3 hits and 2 write-backs, final content; c) 2 points: FIFO trace with 2 hits, explanation of access 7, 72 and 80 bytes word field used to decide a hit; FIFO order updated on a hit; missing write-back
Total 30