OK, I looked over the test, and got a 10%, so that's embarrassing. I did a thorough walk-through afterwards, and could get the answers expected for all but the format string question eventually.
OTOH, I'm not sure if I understand the reasoning in questions 3, 5, 6, and 9:
3 - Heapsort? For an embedded system? Seriously? Setting aside the fact that we aren't really given enough information to draw a meaningful conclusion at all, I would think that you would want to avoid doing a lot of memory allocation and freeing operations, and while it is possible to avoid that by pre-allocating the nodes, the algorithm also has a larger memory footprint than any of the others listed. TBH, without knowing more about the specifics (the size of the expected datasets, the memory and speed of the system, the expected dynamic layouts of the datasets) I would probably choose gnome sort (or, if stuck with one that's on the list, bubble sort - yeah, I went there) despite it's weak performance with large datasets, because it has a tiny algorithmic footprint and the datasets in a real-time system are usually small enough that algorithmic efficiency concerns gets lost in the underflow - the code may well be larger than the data it operates on. What am I missing?
EDIT: OK, I see where I misunderstood now; the "add esp, 12" is the cleanup after the function return. I'm keeping the original comment below for reference, however.
5 - aside from the fact that it assumes a specific C calling convention - there are several - the answer given is wrong. it either should be only the argument pushes followed by the call - on the basis that you are showing the caller's side but not the callee's - or else should be
Code: Select all
push ecx
push ebx
push eax
call foo
foo:
push ebp
mov ebp, esp
add esp, <the total size of the locals the function uses>
Since there is no way of telling from the question how many locals are used, the question should be limited to the caller's side, right?[/i]
6 - While the operation is on memory in the stack, that doesn't mean that the stack segment register suddenly replaces the data segment register as the default segment accessor for that one operation, at least not to the best of my knowledge. The whole reason why almost everyone uses a flat memory model in protected mode (aside from just the sheer cussedness of dealing with segments) is because it sets DS and SS to the same segment base, allowing these operations to work without an explicit segment modifier - the memory access is still through DS, it just happens to be the same as if it were through SS. Or am I misunderstanding this?
9 - While I can see why 2 and 3 are wrong (the lack of #include'ing <stdio.h> and the 'void main()', respectively), why is line 5 wrong? The only thing I can think is that the file is getting terminated incorrectly (i.e., there ought to be a newline after the close brace and an empty line 6), but that has to do with the compiler rather than the program itself, and while the fact that GCC warns of a possibly truncated file is a Good Thing (or at least was back when random line disconnections were a common occurrence), it isn't actually a
C Thing.
I await your explanations of why you were right and I am wrong; I am actually hoping I
am wrong, because learning is usually a good thing.