Hi
I'm just trying to get my timer interrupt to call a C function to, at the moment, just increment the second charachter in video memory (don't worry about the numbers).
isr_wrapper_32:
pushad
call exception_31
mov al, 0x20
out 0x20, al
popad
IRET
This asm works fine and I can increment from here If I wanted to.
void exception_31(void)
{
unsigned char *vid_ptr = 0;
vid_ptr = 0xb8002;
*vid_ptr++;
}
But here, nothing seems to happen. What is happening to the stack when I'm in an ISR as using this local variable doesn't seem to work. Or am I not supposed to use local vars in ISRs??
Or have I missed something when calling the C function?
Thanks
srg
Calling a C ISR Handler from a wrapper
Re:Calling a C ISR Handler from a wrapper
You might want to put that in brackets.srg wrote: *vid_ptr++;
Code: Select all
(*vid_ptr)++;
The compiler should complain about you assigning an int to a pointer. Try:
Code: Select all
unsigned char *vid_ptr = (char *)0xB8002;
(*vid_ptr)++;
-
srg
Re:Calling a C ISR Handler from a wrapper
Blimey, I didn't know that made such a difference!
Anyway now that's sorted. I noticed that with initalising the pointer you did:
unsigned char *vid_ptr = (char *)0xB8002;
You made a type cast. Now I know this is trictly off topic but, when assigning values to pointers (where they point to), why does GCC give a warning when you don't use a cast?
Before GCC I used Borland C++ 3 for DOS, it never gave any warnings when it came to assigning addresses to pointers without casts?
It seems odd to me that you should give a char cast to a char pointer when the addresses it holds (in GCC's case) a 32-bits.
Thanks
srg
Re:Calling a C ISR Handler from a wrapper
Because it isn't valid. You mean either:srg wrote: Anyway now that's sorted. I noticed that with initalising the pointer you did:
unsigned char *vid_ptr = (char *)0xB8002;
You made a type cast. Now I know this is trictly off topic but, when assigning values to pointers (where they point to), why does GCC give a warning when you don't use a cast?
Code: Select all
bla = (char *)0x1234;
Code: Select all
*bla = 0x1234;
Code: Select all
bla = 0x1234;
It's safer this way. It at least warns when you make an ambiguous statement or something that could cause an error. Try to learn to code in such a way that when you compile withBefore GCC I used Borland C++ 3 for DOS, it never gave any warnings when it came to assigning addresses to pointers without casts?
It seems odd to me that you should give a char cast to a char pointer when the addresses it holds (in GCC's case) a 32-bits.
Code: Select all
-Wall -W -Werror -pedantic -pedantic-error
-
proxy
Re:Calling a C ISR Handler from a wrapper
just to let you know, there is a very good reason why *vid_ptr++; didn't work and (*vid_ptr)++; did.
the reason is that the ++ operator always has precidence over the derefence operator, however (this is more notable in C++, than C) because of the way it is defined (returns value it had before incrementing) it tends to act like it has lower precidence in many cases.
for example: *ptr++ = x; acts like "assign x to what ptr points to and increment ptr" but this is not what is actually happening as far as the language definition goes. what is really happening is "copy ptr to a temp value, increment ptr, assign x to what temp points to"
fortunately though, modern compilers are smart enough to know the intent here, so it actually will emit code which decrements after the dereference when it can to save a temp variable.
proxy
the reason is that the ++ operator always has precidence over the derefence operator, however (this is more notable in C++, than C) because of the way it is defined (returns value it had before incrementing) it tends to act like it has lower precidence in many cases.
for example: *ptr++ = x; acts like "assign x to what ptr points to and increment ptr" but this is not what is actually happening as far as the language definition goes. what is really happening is "copy ptr to a temp value, increment ptr, assign x to what temp points to"
fortunately though, modern compilers are smart enough to know the intent here, so it actually will emit code which decrements after the dereference when it can to save a temp variable.
proxy
