Friday, June 26, 2009

Firmware Questions

1. Driver questions
- bitrate, specific register, interrupt, polling
Interrupt vs polling: http://everything2.com/title/Polling%2520vs.%2520interrupt

2. MCU/Processor
- Architecture
- Specs (Speed, Bus, Mem)
- Endian-ness

3. memory type
NOR, NAND
Cache
NAND vs NOR: http://www.toshiba.com/taec/components/Generic/Memory_Resources/NANDvsNOR.pdf

4. Peripheral
UART
Serial

5. OS
- Real time
- VxWork vs Linux
- Preemptive
Some real-time operating systems feature preemptive kernels, which means that a process running in Kernel Mode can be interrupted after any instruction, just as it can in User Mode. The Linux kernel is not preemptive, which means that a process can be preempted only while running in User Mode; nonpreemptive kernel design is much simpler, since most synchronization problems involving the kernel data structures are easily avoided (see the section "Nonpreemptability of Processes in Kernel Mode" in Chapter 11, Kernel Synchronization).
http://oreilly.com/catalog/linuxkernel/chapter/ch10.html (pre 2.4)

http://www.linuxjournal.com/article/7477
http://www.linuxjournal.com/article/6530


6. Multithread
Semaphore
Mutex

7. Board bring up
CPU boot up sequence
http://en.wikipedia.org/wiki/Booting

uboot:
http://www.linuxfordevices.com/c/a/Linux-For-Devices-Articles/Introduction-to-Das-UBoot-the-universal-open-source-bootloader/
http://sourceforge.net/projects/u-boot/

8. language
volatile
http://en.wikipedia.org/wiki/Volatile_variable

register
http://www.devx.com/tips/Tip/12477

(not really abt firmware but general C/C++)
double pointer: http://www.daniweb.com/forums/thread69966.html#

1. draw a hw architecture of the board I worked on, explain where the software/firmware I developed resides, the functionality, what hw are involved and how does the firmware interact with main controller or other components on the board
2. Processor architecture like MIPS, ARM (I am not familar with this. The spelling might be wrong). For this one, it is good enough if you know some basic concepts. But better knows the processor models used in your projects to impress them. Also some basic characteristics of the processors, like cpu speed and RAM size.
3. What kind of OS is running on the processors and DSPs? Embedded OS knowledge, especially the scheduling and ISR handling. They asked a lot about the preempt and task priority implementation in your projects
4. Boot sequence after the board is power up (something like how does the main processor boot up and how are the DSPs loaded).

Tuesday, June 23, 2009

More ooBasic Quirkiness

Using textbox (OEditModel) for database input

1. oTxtDesc.setString
This will append text to existing string
Using .Text to set.

2. So the database will never get updated even the text field is modified.
Data is only "committed" when user switch between controls. (Maybe, seems to be)
To commit the data immediately after setting with .Text, use .commit()
oTxtDesc.Txt = "Sample"
oTxtDesc.commit()

Sunday, June 21, 2009

Wii - Error #002 and BootMii

Some newer Wii games give error #002 when load through WiiGator Backup Launcher 0.3 gamma.
Solution:
Update Waninkoko cIOS to 13b (as of 21 Jun 2009)
http://gbatemp.net/index.php?download=6127

Or using 0.3gamma with 002 fix:
http://www.mediafire.com/?uubxjbmomc0 (Not tested)

Discussed here: http://gbatemp.net/index.php?showtopic=123341&st=0&p=1640124&#entry1640124

21 Jun 2009 - HBC prompt upgrade to 1.0.3, which includes BootMii installation.
http://www.bootmii.org/

Wednesday, June 10, 2009

Reflection of the day

Even though hiring in the name of a MNC after getting acquired, in reallity it's still a small startup with no or little process.
Was really a bad/ineffective interview. Spent 1 hour answring and another hour getting grill for each answers. No even introduction, background talk, personality check.
And stress too much on complexity...
(For god sack, I'm not applying for a computer scientist position...)
At the end, the company didn't find out much about me, and I didn't understand more about the company.

Some of the questions.

1. Write a function to reserve the order of words in a string
A fool like donkey --> donkey like fool A
void reverse_str(char *src)
{
char *dst[10]; // note: i must be < 10
char *tmp_word = 0;
char *nextptr;
int i = 0;

tmp_word = strtok_s(src, " ", &nextptr);
while (tmp_word != NULL)
{
dst[i++] = tmp_word;
//printf("%s\n", tmp_word);
tmp_word = strtok_s(NULL, " ", &nextptr);
}

#if 1
for (i=i-1; i >= 0; i--)
{
printf("%s\n", dst[i]);
}
#endif
}


2. Write a function that take int[] arr and output int[] r where r[i] = product of all elements of arr[] exception arr[i]

void function(int[] arr, int[] r, int len)
{
int tmp = arr[0];
for (int i=1; i
{
tmp = tmp * arr[i];
}

for (int i=0; i
{
if (arr[i] = 0)
r[i] = tmp/arr[i];
else
r[i] = 0;
}
}


Original answer was for (i) { for (j) } type.
The interviewer was not happy with the N^2 complexity answer... The above answer should work better.

3. What does not cause a deadlock?
Process ProcA, ProcB
resource a, resource b

Deadlock:
ProcA acquired a, ProcB acquired b
ProcA sem_wait(b), ProcB sem_wait(a)

4. Write a function with (int[] a, int x) to find if x is equal to a summary of any 2 elements in a.

5. Write a function that produce the following output:
1 2 3 4 .... 12
2 4 6 8 .... 24
.
.
.
12 24 36 48 .... 144

6. Write a SQL query to find out the name of student(s) that get highest score in subject name "Math"

student
student_id student_name

subject
subject_id subject_name

grade
student_id subject_id score

Sample database file: link
Can be done this way, but if I answered this during the interview, I would probably asked from "more efficient solution"...
Query1 = SELECT "student_id", "score" FROM "grade" WHERE "subject_id" = ( SELECT "subject"."subject_id" FROM "subject" WHERE "subject"."subject_name" = 'Math' )

Query2 = SELECT "student_id" FROM "Query1" WHERE "score" = ( SELECT MAX( "score" ) FROM "Query1" )

Query3 = SELECT "student_name" FROM "student" WHERE "student_id" IN ( SELECT "Query2"."student_id" FROM "Query2" )


Another approach:
Query1 =
SELECT grade.score FROM grade, subject WHERE grade.subject_id=subject.subject_id AND subject.subject_name='Math')

Query2 =
SELECT student.student_name, subject.subject_name, grade.score FROM student, subject, grade WHERE student.student_id=grade.student_id AND subject.subject_id=grade.subject_id

SELECT student_name, score FROM (Query2) WHERE subject_name='Math' AND score IN (SELECT MAX(score) FROM (Query1)

7. What data structure is best for mapping of NRIC to Name?

Memory crashed... Forget some questions

11. Have a singly link-list, given a pointer to a random element in the link-list.
Use diagram to describe how to delete the element.

Correct answer:
(HEAD)--->()--->()--->(x)--->()--->null

x contains { data, *next }
tmp = x->next (copy the data and *next of x->next)
delete x->next

12. Find mistakes in 3 programs
(a)

class Rational {

private:
int a, b;
friend Rational& operator*(const Rational& lh, const Rational& rh);
}

inline Rational& operator*(const Rational& lh, const Rational& rh)
{
Rational result(lh.a * rh.a, lh.b * rh.b);
return result;
}

-> Correct should be Rational operator*(...)
result is local in operator*, returning reference is invalid.

(b)
Something to do with virtual bool destroy()

class Base {
virtual bool destroy();

private:
static size_t numOfBase;
}

class Derived: public Base
{
....
}


I think the mistake is Drived didn't implement destroy().

(c)
Some function that copy the domain part of the fqdn, if the . is not found, append the default_domain to it.
abc@ibm.com --> return string as ibm.com
abc@encentuate (default_domain = .ibm.com) --> return string as encenture.ibm.com
char* function(char* fqdn, char *default_domain)
{
....
basic checking

get the string after '@'
allocate mem for result

if (size checking failed)
{
return NULL; // here memory allocated was not freed.
}

if (result contains not '.')
strcat(result, default_domain); // here the reminding space of result might not fit default_domain)
...
}

Tuesday, June 09, 2009

Some for technical interview questions

1.

char *f(char *a)
{
char s[100];
strcpy(s, a);
return s;
}

char *f(char *a)
{
static char s[100];
strcpy(s, a);
return s;
}

char *f(char *a)
{
char *s = (char *)malloc(strlen(a));
if (s)
strcpy(s, a);
return s;
}


Which is correct implementation?
All functions have issue of not validate the source (a) before cop.
- first function does not work due to s declared as local variable (stack)
- 2nd function works. static variables are stored in data segment of memory and initialized only once
- 3rd function works. malloc from heap. Length should be strlen(a)+1 to reserve for null terminator.

2.

class A {
...
private:
char * m_myString;
};

implement assignment operator for A.

A& operator=(const A& a);

A& A::operator=(const A& a)
{
// check a is not this
// check m_myString is allocated
// copy a.m_myString to m_myString
return *this;
}

read this super-duper operator overloading tutorial -> link.

3. What event does selection on combobox trigger?

4. Explain Document View architecture of MFC.

5. What are the differences between stl:vector and stl:map

6. What is std::auto_ptr?

7. Multi-thread protection

8. How do you open a dialogbox?

Saturday, June 06, 2009

Some test questions - that I still can remember

1. Single inheritance - link

2. Static member function - link

The differences between a static member function and non-static member functions are as follows.
  • A static member function can access only static member data, static member functions and data and functions outside the class. A non-static member function can access all of the above including the static data member.
  • A static member function can be called, even when a class is not instantiated, a non-static member function can be called only after instantiating the class as an object.
  • A static member function cannot be declared virtual, whereas a non-static member functions can be declared as virtual
  • A static member function cannot have access to the 'this' pointer of the class.
3. std::auto_ptr - link
A smart pointer that deletes the instance it points to when going out of scope. It is supplied in the STL, in the header file memory.h.

4. Exception in destructor? - link
[17.3] How can I handle a destructor that fails?

Write a message to a log-file. Or call Aunt Tilda. But do not throw an exception!

5. Copy constructor is called when? - link

  • Automatically called: A copy constructor is called in the following circumstances.
        A x(y);  // Where y is of type A.
    f(x); // A copy constructor is called for value parameters.
    x = g(); // A copy constructor is called for value returns.

6. Map - local example

How to access the string?

for(mapType::const_iterator it = data.begin(); it != data.end(); ++it)
{
cout << "Who(key = first): " <<>first;
cout << " Score(value = second): " <<>second <<>

Not theMap[it] or theMap[i]

7. Prefix and postfix operator++() - link

 class Date {
//...
public:
Date& operator++(); //prefix
Date& operator--(); //prefix
Date& operator++(int unused); //postfix
Date& operator--(int unused); //postfix
};
Postfix operators are declared with a dummy int argument (which is ignored) in order to distinguish them from the prefix operators, which take no arguments:

8. const member function - link

int  capacity() const;  // max size before reallocation

Member functions should be declared with the const keyword after them if they can operate on a const (this) object. If the function is not declared const, in can not be applied to a const object, and the compiler will give an error message. A const function can be applied to a non-const object

A function can only be declared const if it doesn't modify any of its fields.

** Note

mutable

This keyword can only be applied to non-static and non-const data members of a class. If a data member is declared mutable, then it is legal to assign a value to this data member from a const member function.

9. std:find(x, y, i) - link
    #include 
iterator find( iterator start, iterator end, const TYPE& val );

The find() algorithm looks for an element matching val between start and end. If an element matching val is found, the return value is an iterator that points to that element. Otherwise, the return value is an iterator that points to end.

10. command to start bash shell
= bash or sh
(bsh is wrong!)

11. Access - link
We can summarize the different access types according to who can access them in the following way:

Accesspublicprotectedprivate
members of the same classyesyesyes
members of derived classesyesyesno
not membersyesnono

friend yes yes yes

12. Pointer vs reference - link

Friday, June 05, 2009

ooBasic Silliness

1. Use of User Defined type

Type a
x as String
End Type

Dim aList() as New a

Sub func1()
Fill up aList()
End Sub

Sub func2(idx%)
Get aList(idx)
End Sub

Call func1() then func2() [I call from another module]
aList is mysteriously emptied.

The above only work when aList is dim without specifying the type.

2. Control object
Populate the textbox, listbox, formattedfield and datetimefield control with value from database.
Switch to another sheet.
Switch back to the control sheet. Somehow the value in formattedfield and datetimefield disappeared, but not the textbox and listbox.
If the value (text) in formattedfield is entered by user, then it will not disappear...

3. Formatting
http://docs.sun.com/app/docs/doc/819-0439/6n2s7rhvm?l=en&a=view#indexterm-112
http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=3069
http://docs.sun.com/app/docs/doc/819-0439/faalo?l=en&a=view