1

I am using embedded C for motorola 68000 microprocessor. I want to store the pointer address in a uint16 variable and then, want to do the mod of the variable. My main reason for doing this is to check the sectors of EEPROM are correctly assigned.

Eg->

 uint16 a, c;
 uint16 *b;
 b=&a;
 c=b%4;

Something like this. Obviously, I cannot do it this way.

Thanks

2 Answers 2

2

Are you limited to a 16-bit address space, i.e. 64 KB of RAM? That's quite small for a 68k system.

Anyway, you need to convert the pointer to an integer type in order to arithmetic on it;

#include <stdint.h>

uint16 a, *b = &a;
intptr_t c = (intptr_t) b;

if( (c % 4) != 0 )
{
  /* bad address! */
}

Note that the above doesn't store the address in a 16-bit variable, since that's not the right way to do this. Instead, it uses intptr_t to hold the pointer as an integer.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry for the late reply, I had tried ths technique before posting the query. It seems my cross compiler was having some issues while compiling it.
1
b = (uint16*)(((uint16)(&a)) % 4);

1 Comment

b = (uint16*)( ((uint16) &a) % 4 ); is a bit easier to read.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.