Question

Given the following code, determine the amount of memory required to store all of the variables...

Given the following code, determine the amount of memory required to store all of the variables after the program has been executed (Hint: sum the variables) show your work. Then, tabulate your results in the form of the table below (a separate table ffor each part) then add to your report.
Variable datatype    Memory for datatype (bits) # of elements Memory (bits) a logical 8 1 8*1 = 8 . . . . . . . . . . . . . . . sum (bytes)

(a)
clear all clc
a=2; b=[5 1];

c = ~(a > b);

d = uint16(c);

e = [ b b a a];

f=single(a);

(b)
clear all clc
d=[1 2 3; 4 5 6; 7 8 9]; s=0;
[nr,nc]=size(d);

for ir=1:nr

for ic=1:nc

s = s + d(ir,ic);

end

end

m = s/(nr*nc);

(c)

clear all

clc
c = uint8(0);

happy=true;

out=[];
while(happy)

c = c + uint8(1);

out = [out double(c) ];

if(c>4)

happy = false;

end

end
q =10:-2:0;

r = single(q(1:3));

s = rand(3,1);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

[Edited]

The amount of memory required to store each variable and the total amount of storage required to store all of the variables after the execution of the program is given below in Tabular Form.

Code a

Variable Name Datatype Dimension

Effective number of element

Bytes allocated per element Total Bytes allocated to the variable
a double 11 1 8 8
b double 12 2 8 16
c logical 12 2 1 2
d unit16 12 2 2 4
e double 16 6 8 48
f single 11 1 4 4
Total 78

Code b)

Variable Name Datatype Dimension

Effective number of element

Bytes allocated per element Total Bytes allocated to the variable
d double 33 9 8 9*8 = 72
ic double 11 1 8 8
it double 11 1 8 8
m double 11 1 8 8
nc double 11 1 8 8
nr double 11 1 8 8
s double 11 1 8 8
Total 15 8 15*8 = 120

Code c:

Variable Name Datatype Dimension

Effective number of element

Bytes allocated per element Total Bytes allocated to the variable
c unit8 11 1 1 1
happy logical 11 1 2 1
out double 15 5 8 40
q double 16 6 8 48
r single 13 3 4 12
s double 31 3 8 24
Total 126

Refer to the command "help double" to know how many bytes of memory is allocated when we assign a variable of datatype double.

Add a comment
Know the answer?
Add Answer to:
Given the following code, determine the amount of memory required to store all of the variables...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 8. Given the following code part, when methodA) is running, list ALL variables that are on...

    8. Given the following code part, when methodA) is running, list ALL variables that are on the current program Stack? (assume that the compiler only allocates memory space when it sees a variable declaration) (8 pts) static int 10 void methodA) inta -123 return a1; void methodB(int b) t b b/12 3 static int c 2 c methodAl) int d[5]-(1,2, 3,4, 5 2-4G int main0 inta1, a2; methodB(15 return 0

  • A. What is the output of the following C++ code fragment? (all variables are of type...

    A. What is the output of the following C++ code fragment? (all variables are of type int) int count-1; int y-100; while (count 3) y=y-1 ; count+t cout << y << endl; cout<< count <<endl What is the value of x after control leaves the following while loop? (all variables are of type int) B. int x0 while (x < 20) sum- sum+x cout << sum<< endl;

  • Write out the memory map for the following code, providing all values at the end of...

    Write out the memory map for the following code, providing all values at the end of execution. How many total bytes does this code declare for variables? double testd; struct frog h: int testi; double .xy: struct frog turtle, apple, tv[3] testi-2; apple-kturtle; apple->x-ktestd; *(turtle.x)-7.3; apple).y-3.6 turtle.y-1.5 for (testi-o ; te8tjc3 ; test i++) tv [testi] .x-a(tv [ (test1+1 )%3] . y) ;

  • 4. If the memory bus has 24 bits, and there are 8 words in a block...

    4. If the memory bus has 24 bits, and there are 8 words in a block in RAM, To design a 4 set-associative cache with 8K sets in cache, answer the following questions: (a). RAM size (b). How many blocks in RAM? (c). How many bits are w? (d). How many bits are d? (e). How many bits are s? (f). cache size in words? (g). How many lines in cache? (h). If we increase the cache size to 32K...

  • 3. (15 Pts.) In this problem you are given a microprocessor with 24-bit address bus and...

    3. (15 Pts.) In this problem you are given a microprocessor with 24-bit address bus and 8-bit data bus. a. What is the addressing space of this microprocessor? 113 16 MB b. how many bytes are contained in the sub-space starting at address C00 000h and ending at address DFF FFFH? Express your answer in KB and MB. DFFFEE CoO DOU - TFFFFF in ke 20 4SKe c. You would like to interface a single 4 MB memory IC to...

  • Hi, please help and write clearly. Thanks. uestion 2 (30 marks (a) A memory system of...

    Hi, please help and write clearly. Thanks. uestion 2 (30 marks (a) A memory system of 64 bit is arranged into 4096 rows and 128 columns Calculatee (i)The data length in bytes (ii)The number of bits stored in the memory (iii)The number of row and column addresse:s [2 marks] [4 marks] [4 marks] (b)A Programmable Read Only Memory (PROM) based Programmable logic device (PLD) has the following characteristics When C-0, output is A. When C-1, output is B (i)Determine the...

  • Problem #1 (25 points) Address Space, Memory Consider a hypothetical 18-bit processor called HYP18 with all...

    Problem #1 (25 points) Address Space, Memory Consider a hypothetical 18-bit processor called HYP18 with all registers, including PC and SP, being 18 bits long. The smallest addressable unit in memory is an 8-bit byte. A. (4 points) What is the size of HYP18's address space in bytes and KB? How many address lines does HYP18 require? Address space: Bytes Address space: KB (KiloBytes). Address bus lines: B. (6 points) Assume that first quarter of the address space is dedicated...

  • Question 4] All variables and headers properly defined for the C functional program. char st 80...

    Question 4] All variables and headers properly defined for the C functional program. char st 80 1: unsigned *ptri-s .a) What is the size of the array 's' in bytes? .b) ptr1 has a hex-decimal value of 28FE60 referring to the first element of st 1 array. What is the decimal value? c) Following this functional software; a Ans size- b Ans-- for (i 0; sl i0:+i) printf( "in %c: It %dVt",toupper(s[i] . (i.2), toupper( st i l . (i.2)));...

  • 1. Select all that are true for the following code. #include <stdio.h> #include <stdlib.h> void range(int...

    1. Select all that are true for the following code. #include <stdio.h> #include <stdlib.h> void range(int start, int end, int *results) { int length = end - start; results = malloc(sizeof(int) * length); for (int i=start; i<end; i++) { *results = i; results++; } } void printArray(int *arr, int length) { for (int i=0; i<length; i++) { printf("%d ", arr[i]); } } int main() { int *x; int s = 2; int e = 11; range(s, e, x); printArray(x, e...

  • For each part, do or answer the following: - Show how you would add the two...

    For each part, do or answer the following: - Show how you would add the two 8-bit binary numbers by filling in each of the blank boxes with a 0 or 1. NOTE1: Addition of 2's complement numbers is done just like the addition of unsigned whole numbers, so you only need to show each addition once. NOTE2: There are 9 blank boxes for the Carry bits and 8 blank boxes for the Sum bits. CAUTION: Every blank box should...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT