This is the mail archive of the crossgcc@cygnus.com mailing list for the crossgcc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: poke function ....



	Hi,

A quite good implementation for pokeb, peekb might be like this:

unsigned char peekb (unsigned long addr)
{
	return *((volatile unsigned char *)addr);
}

void pokeb (unsigned char data, unsigned long addr)
{
	*((volatile unsigned char *)addr) = data;
}

Let's your compiler inline this code for better performance. And you
really doesn't need an assembler :)

Actually, you can have some difficulties due to different nature of cpus.
M68k doesn't have 'segments'. Address space is linear. So for portability
you need to make address yourself:

void pokeb (unsigned base_addr, unsigned offset, unsigned char data)
{
	/* in the Intel CPU do this */
	unsigned addr = base_addr << 4 + offset;

	*((volatile unsigned char *)addr) = data;
}

Hope, this helps

------------------------------
Sergey Uvarov
E-mail: uvarovsl@fnal.gov

On Fri, 18 Sep 1998, Dony wrote:

> Hii all,
> Right now, I'm trying to porting 80x86 code to M68K.
> In Intel, there is a function: pokeb(base_addr,offset,data)
> and using Borland C Compiler will translated like this :
> 
> 	/* Assembly Routine to do a pokeb                */
> 	/* bp points at stack                            */
> 	/* stack + 0xc = data                            */
> 	/* stack + 0xa = register offset from base addr. */
> 	/* es - set to be segment value (CS)             */
> 	/* si - set to be register offset                */
> 	/* al - data                                     */
> 
> 	mov ax,[base_addr]
> 	mov es,ax
> 	mov al,[bp+0x0C]
> 	mov si,[bp+0x0A]
> 	mov es:[si],al
> 
> I'm a high level programmer, and I don't really understand 
> where this 0x0c and 0x0a come from, and how could in 0x0c
> is data, and in 0x0a is register offset??
> Can somebody explain step by step what the assembler
> trying to do??
> Is there anybody M68K programmer know any C function to replace
> pokeb, peekb function in M68K??
> 
> 
> -- 
> Dony
> Email : dony@willowglen.com.sg
>