CS250 Homework Midterm Practice

Solve this homework and turnin your handwritten or printed answers on during  the midterm exam. You will find similar questions in the midterm exam.

=====================================================

1. Implement the boolean function

Using the following truth table answer these questions:

x
y
z
a
0
0
0
1
0
0
1
0
0
1
0
1
0
1
1
1
1
0
0
1
1
0
1
1
1
1
0
1
1
1
1
0

a) Write the boolean expression for a as a function of the inputs x, y, z using "Sum of Products". Do not simplify.


b) Write the boolean expression for a as a function of the inputs x, y, z using "Product of Sums". Do not Simplify.

c) Using the sum of products you obtained in a) simplify the expression using only boolean algebra (no Karnaugh maps).

d) Write the Karnaugh map for b and simplify. Obtain the Minimum expression.

e) Draw  the schematic that implements this expression using  AND/OR/NOT/ gates

f) Draw  the schematic that implements this expression using only NAND gates.

2. Draw a Flip Flop


a) Using NAND gates



b) Using NOR gates


3.  In each line write the name of the memory section where the variables are stored:

int a = 5;  // a is stored in _____________

int b[20];  // b is stored in _____________

int main() {  // main is stored in _____________
{
    int x;    // x is stored in _____________

    int *p = (int *)malloc(sizeof(int)); // p points to memory stored in ___________
}


4. Enumerate the steps needed to load a program.








5. What is a "Dynamic Linker" and a "Static Linker".








6. Perform the following multiplication in binary. Also, convert to decimal the operands and the result.


                                                  1001010 x 1101




               



7.  Perform the following division in binary, Also, convert to decimal the operands and the result.


                                               
                 1011 | 100101001







8.  Represent the number1.25 in binary using the IEEE 754 double representation. The formula is given:


Val in decimal = (-1)s x (1.m) x 2(e-bias) where:

bias = 1023
s = bit 63
e = bits 52 to 62
m= bits 0 to 51


Val in binary: ___________________________


9.  Explain what is a "Pipe Stall" and how can be avoided.

10. Obtain the representation of number -58 using 8 bits. Verify that 78 + (-58) is equal to 20 using binary addition and complements of 2.


11. Write a function "int isBigEndian()" that will return 1 if the computer is big endian or 0 if it is little endian.

12. What is the difference between Harvard Architecture and Von Newman Architecture



13. What do CISC and RISC stand for and enumerate the characteristics of each.


14. Reorder the following instructions to prevent a pipe stall:


ADD r1, r1, r4
SUB  r2, r1,r3
ADD r5, r6, r7
SUB  r8, r5, r9
ADD r10, r11, r12
SUB  r13, r10, r4


15. In ARM Assembly language write a program that prints "Hello CS250"

16. In ARM Assembly language implement a program "maxmin" that prompts two integer numbers fom stdin and then displays the maximum, minimum and average of both: numbers. Here is an example of the usage:


bash> maxmin
a=5
b=8
max=8
min=5
avg=6

17. In ARM Assembly language implement the function int addarray(int n, int * array) that add all the elements of the array passed as parameter. n is the length of the array.


18. Write the implementation of int strlen(char * s)  in ARM assembly language.

19. Complete the function memdump(char *p, int len) in the following program that dumps in hexadecimal byte by byte the memory starting at p len bytes. An example output is given at the end of the program.


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void memdump(char * p , int len) {
    // Add your code here.
   

   
}

Typical output:0xbeab36e0: 41 76 00 40 09 00 00 00 30 00 00 00 e4 36 ab be Av.@....0....6..
0xbeab36f0: 00 00 00 00 00 00 28 40 48 65 6c 6c 6f 20 77 6f ......(@Hello wo
0xbeab3700: 72 6c 64 0a 00 88 00 00 80 2b 2f 40 c0 87 00 00 rld......+/@....
0xbeab3710: fb ff ff ff 05 00 00 00 00 00 00 00 00 00 00 00 ................