July 31, 2013

Common interview examination(evaluation) for FW engineer (CS/EE)

1. Please show the C code for the result of adding up 1 to 100.

Sol. 1: for(int i = 1; i <= 100; i++) printf("The result of adding up 1 to 100 is: %d\n", i);
Sol. 2: printf("The result of adding up 1 to 100 is: %d\n", ((1+100)*100)/2);

Note: reference below Question 11.

2. Code review. Note: run it under the 8-bit MCU.
int main()
{
     char a, b, *ptra, *ptrb;

     a = 255, b = 128;
     printf("The value a is %d, b is %d\n", a, b);
     ptra = b, ptrb = &a;
     printf("The value ptra is %d, ptrb is %d\n", *ptra, *ptrb);

     return -1;
}

Sol.: a = 255, b = 128; *ptra = undefined memory, *ptrb = 255.

3. Please describe ISR (Interrupt service routine).

Sol.: reference Google.

4. To explain RISC and CISC.

Sol. of RISC(Reduced Instruction Set Computer):
     Advantage: Less power consumption, easy enhance the performance by pipelining due to simple CPU architecture. 
     Disadvantage: Code size will be larger than CISC architecture.
     Example: ARM, ARC, Atom, and so on. (much popular)

Sol. of CISC(Complex Instruction Set Computer):
     Advantage: Reduce the amount of instructions required to operate.
     Disadvantage: Instruction behavior is much complex and hard to debug for programmers.
     Example: Intel x86.

5. Please describe the differences between "global", "local", and "static(in function)" variables in C?

Sol. of Global: A variable that is accessible in every scope(unless shadowed).
Sol. of Local: A variable that is given local scope.
Sol. of Static: A special type of local variable is available in many mainstream languages which allows a value to be retained from one call of the function to another

6. With 2 cubes, please fill in numbers from 0 to 9 on the total 12 surfaces, therefore, the 2 cubes can show the combination of number 01~31.

Sol. 1 (riddle)
     Cube 1: 0, 1, 2, 3, 4, 5
     Cube 2: 0, 1, 2, 6, 7, 8

Sol. 2 (base on computer science knowledge)
     Show target number 01 to 31 with binary type, i.e., 00001 to 11111. Due to the question asks us to fill ten numbers on 2 cubes total 12 surfaces we then adding one bit to the target numbers, i.e., 000001 to 011111. Therefore, we could divided the number into two parts. Here shows the number of 0 to 9 from decimal to binary, i.e., 000 to 111. We hence combine two surface number to fill the question demand.
     Cube 1: 000, 001, 010, 011, 100, 101, i.e., 0, 1, 2, 3, 4, 5 in decimal
     Cube 1: 000, 001, 010, 011, 110, 111, i.e., 0, 1, 2, 3, 6, 7 in decimal

7. What is script file (batch file) and its purpose? Is it a compiler or interpreter in general?

Sol.: reference Google, and it is much similar to interpreter.

8. With an binary number "010101010101010", after what action with a seed number twice can it still be the same number?

Sol.: XOR

9. What's the difference after executing call "Function" & "ISR"?

Sol.: ISR may record the executing program address and flag register information before interrupt occurred.

10. Please describe the difference between "Stack" and "Heap".

Sol. of Stack: FILO, descend address allocation, store "auto" variables(i.e., recycled automatic by system)
Sol. of Heap: FIFO, ascend address allocation, store "dynamic" variables(i.e., recycled manually by user)

Note: Here we only mentioned "default heap" in C/C++. However, there is still plenty branch in heap, such as fixed and movable heap in default heap and the other type "dynamic heap". Please reference Google by yourself for detail.

11. Please show an example about Brute-Force, Greedy method, and Heuristic mechanism in algorithm topic.

Sol. of Brute-Force:
      Advantage: Get the global optimal solution.
      Disadvantage: Non-efficiently, large time complexity.

Sol. of Greedy:
      Advantage: Save much time by getting the locally optimal solution.
      Disadvantage: does not in general produce an optimal solution

Sol. of Heuristic mechanism: ranks alternatives in various choice int order to make a decision.
      Advantage: Improve the efficiency of algorithm by reducing the branch factor.
      Disadvantage: Potentially exponential effort may be generated.

Note 1: Nonetheless a greedy heuristic may yield locally optimal solutions that approximate a global optimal solution in a reasonable time.
Note 2: "Traveler Question" could apply above algorithms to get its corresponding results.

12. What are the ALU, CU, Memory Mapping I/O, Data bus and PMU in CPU architecture or show the relation diagram?

Sol.: Arithmetic Logic Unit, Control Unit, Memory Mapping I/O, Data Bus, and Power Manage Unit, reference Google for detail.

13. Describe the Code data, Internal data, External data, Bit data in 8051 architecture.

Sol.: reference Google.

14. What are the differences between compiler time and run time in system programming, show and example?

Sol.: For error recognition, compiler error means that compiler will help programmer to find syntax error. The run time error means that compiler had accepted your code(i.e., syntax error free), but when program is running, OS may find unexpected error like memory address error due to our code meaning error.

15. What's the UI and shows an example?

Sol.: User Interface, e.g., Word.

16. What's the embedded system?

Sol.: Embedded system means that the system has its own CPU, memory, buffer, and so on to finish certain requirement.

17. What are the reentrance code and its purpose?

Sol.: Reentrant functions can be called recursively and can be called simultaneously by two or more processes. Reentrant functions are often required in real-time applications or in situations where interrupt code and non-interrupt code must share a function.


18. What's the recursive program and show an example without program?

Sol.: A recursive function is a special function that calls to itself. Example: N! = N*(N-1)*(N-2)…2*1, We can use recursive function to calculate the factorial of a positive integer N.

19. Show an example(story) about using the hash table in your life?

Sol.: The BMI rate of the studetns in a class, we can insert the weight and the height of each student  in class, and the weight and the height will output a rate by the BMI equation. So the BMI table of the students can be considered as a hash table .

20. Please describe the major difference between Harvard and Von neumann architecture briefly.

Sol.: The main difference is instruction and data are using separated bus.
      Advantage: Two buses are used to both data transfer and instruction fetches simultaneously.
      Disadvantage: Difficult to implement.

21. As benary 10101010101000011111111010101010101111 mode 3?

Sol. 1: 
      2^0 mod 3 = 1 
      2^1 mod 3 = 2
      2^2 mod 3 = 1
      2^3 mod 3 = 2
      2^4 mod 3 = 1
      2^5 mod 3 = 2 and so on

      so we can find out the regular feature as follow:
      binary : 10 1010 1010 1000 0111 1111 1010 1010 1010 1111
      remainder : 21 2121 2121 2121 2121 2121 2121 2121 2121 2121
      The answer we can simplify as: (2+4+4+2+4+6+4+4+4+6) mod 3 = 1

Sol. 2:
     unsigned MOD3_1(unsigned input)
     {
          unsigned result;
          do {
               result = 0;
               while(input) {
                    result += input & 0x3;
                    input >>= 2;
               }
               input = result;
          } while( result > 3 )
          return ( number == 3 ) ? 0 : number;
     }

Sol. 3:
     unsigned MOD3_2(unsigned input)
     {
          unsigned result = input, temp;
          while( result > 3 ) {
               temp = result >> 2;
               result -= ( temp << 2 ) + temp;
          }
          return ( result == 3 ) ? 0 :result ;
     }

Sol. 4:
     Setp 1. Set num_A as the sum of bit is equal to 1 of odd number.
     Setp 2. Set num_B as the sum of bit is equal to 1 of even number.
     Setp 3. Set result = num_A + 2 * num_B
     Setp 4. when result >= 3 then back to Step 1.

Note: this method is using "Multiplicative Inverse" to inductive solution.

22. Explain void (*signal(int sig, void (*func)(int)))(int) in C syntax.

Sol.: Here I use the main idea within interpreter to enable any programmer to parse C declaration. (Note: signal is inside parenthesis, we hence resolve it first.)
                      +-----------------------------+
                      |                  +---+      |
                      |  +---+           |+-+|      |
                      |  ^   |           |^ ||      |
                void (*signal(int, void (*fp)(int)))(int);
                 ^    ^      |      ^    ^  ||      |
                 |    +------+      |    +--+|      |
                 |                  +--------+      |
                 +----------------------------------+
     → signal is a function passing an int(i.e., sig) and
     → fp is a pointer to
     → fp is a pointer to a function passing int returning
     → fp is a pointer to a function passing int returning nothing(i.e., void)
     → signal is a function passing an int and a pointer(i.e., fp) to a function passing int returning nothing(i.e., void) returning
     → signal is a function passing an int and a pointer(i.e., fp) to a function passing int returning nothing(i.e., void) returning a pointer to
     → signal is a function passing an int and a pointer(i.e., fp) to a function passing int returning nothing(i.e., void) returning a pointer to a function passing an int returning
     → signal is a function passing an int and a pointer(i.e., fp) to a function passing int returning nothing(i.e., void) returning a pointer to a function passing an int returning nothing(i.e., void)

No comments:

Post a Comment

三個逗號俱樂部

《免責聲明》 本部落格不針對任何金融商品進行買賣建議, 內容來自公開資訊觀測站之分享與各大媒體之評論為主, 投資人應審慎評估並獨立判斷,切勿以本部落格資訊作為投資依據。 靜候 時機來臨;瞬間掌握重壓;享受 獲利奔馳。 -------------------------...