You might want to use
this GCC Inline Assembly HOWTO as reference for Ianjack's question.
While you are at it, please explain that loop conditional, and specifically a) what the effect of the
while() loop as given is (or, if it is just a delay loop, why it requires any inline assembly at all); b) why you aren't using a
for() loop; c) why you are testing for an exact match (
!=) on the loop condition rather than a range of less than (
<); d) why you increment the same index twice on successive lines (and what the effect of doing it between the test and the body of the loop will be, especially in light of that last question); and e) if you are
intending to increment by two (which I doubt is the case), why you couldn't use the sum operator (
+=) thusly:
Code: Select all
// I am assuming you are using GCC with a version of the
// C standard later than C99, and thus can use inline
// declarations. Now, ask yourself, why would I be
// making this point, when the original didn't use
// inline declarations at all?
for (uint8_t i = 0; i < 255; i += 2) {
__asm__ volatile( "mov 0x00, %0" : "b" (i));
}
You might want to reconsider the way you are using AT&T syntax on one line and Intel (specifically the NASM dialect, with square brackets for indirection) on another (or, conversely, why you are moving what I can only assume you meant to be a register variable into a constant value). I suggest that you try to relate this to Ianjack's question, too.
Code: Select all
__asm__ volatile( "mov 0x00, %0"
: "b" (i)
); // 29
if this is Intel syntax, then it should be
"mov %0, 0x00", that is to say,
destination, source order; conversely, if it is meant to use AT&T syntax (as would usually be the case in GCC), it should be written as
"movl 0x00, %0", with the operand size marker to show that it is supposed to be a double-word (32-bit) value (if you mean to use a quad-word - 64-bit - value, then it would be
"movq 0x00, %0"). Of course, that's assuming that you have the correct operands in the first place...
Code: Select all
__asm__ volatile( "lidt [%0]" // 31
: "b" (idtp) // 32
); // 33
Intel syntax uses square brackets for indirection, but AT&T syntax uses parentheses, which would be
Code: Select all
__asm__ volatile( "lidt (%0)" // 31
: "b" (idtp) // 32
); // 33
For that matter, why can't you link a C program object file with an assembly one (something which is certainly possible, and which you seem to have managed in the past)? Once the source is compiled or assembled, the object format is
exactly the same. If you can link two object files from two C source files, or two from assembly source, you certainly can link one from each to each other.
I want you to understand that we aren't teasing you or trolling you by not giving the answers directly. We often use the Socratic approach here (in general, not just with you) because, in many ways, understanding why you got something wrong is more important than fixing it is - if we just answer the question directly, without driving home the reason the previous code was flawed, you are likely to make the same mistake again.