Given the following declarations, write a formula to locate any random record (e
ID: 668898 • Letter: G
Question
Given the following declarations, write a formula to locate any random record (e.g., base + offset) in the array evaluating all constants, i.e., calculate the actual physical memory address of the location of X(J) in memory for any -30 <= J <= 20. Assume the first unit of memory assigned by the translator is at location Lo (base address). You need not do the actual arithmetic as long as you explicitly show/state all values/numbers required for the calculation and the formulas constituting your answer.
type MyType is record
xAxis: array(-5..4) of character;
yAxis: array(-5..4) of character;
temperature: integer;
airSpeed: character;
chillFactor: float;
locationt: Arrary(1..10) of character;
label: Array(0..9) of character;
end record;
X: array(-30 .. 20) of MyType;
Explanation / Answer
Solution:
Given Base Address=Lo, -30 <= J <= 20.
To calculate the memory allocated to one MyType Record:
xAxis will take 10 bytes ,(10 locations to store characters)
yAxis will take 10 bytes , (10 locations to store characters)
temperature will take two bytes,(to store integer)
airSpeed will take 1 byte , (to store character)
chillFactor: will take four bytes,(to store float)
locationt: will take 10 bytes ,(10 locations to store characters)
label: will take 10 bytes ,(10 locations to store characters)
Therefore one MyType Record will take 10+10+2+1+4+10+10 =47 bytes
X can store 51 records where each record size is 47bytes
To Access a record from X randomly, the formula will be
Physical Address=Lo +( ( ( J - 1) * 47) + 1) , where J =1,2..<= 20.
Physical Address=Lo + ( ( (J - 1)* 47) - 1) , where J>=-30 ,-29,28…,-1 , 0
For Example, to read 4th record J=4:
Physical Address = Lo + ((4-1)*47 +1)
= Lo + (3*47 +1)
=Lo +(141+1)
Since 3 records can take 3*47 bytes =141 bytes, the 4th record will starts at 142 +Lo
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.