This is the mail archive of the 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 ....

In a message dated 18-Sep-98 18:46:31
   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                                     */

1>       mov ax,[base_addr]
2>       mov es,ax
3>       mov al,[bp+0x0C]
4>       mov si,[bp+0x0A]
5>       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??

1) Read "base_addr" into ax-register (16 bits),
2) Copies ax to es-register (probably due to cpu not beeing capable to load
   it there directly from ram).
3) Reads al-register (8 bits) from the stack.
   The offset of 0x0c (12 bytes) must be compiler/cpu-dependent - I don't
   remember what info an intel cpu puts on the stack for return addresses.
4) Then does the same with si-register (16 bits)
5) Stores al-register contents at 20-bit adress given by es:[si]
   16 bits of es and si *overlapped* and added such that they form 20 bits:

     aaaa   <- es contents, 4 bits per char
    + bbbb  <- si contents, 4 bits per char
     zzzzz  <- 20-bit sum, to be used as physical address.

>Is there anybody M68K programmer know any C function to replace
>pokeb, peekb function in M68K??

 pokeb == use a pointer and write char into RAM.
 peekb == use a pointer and read char from RAM. 

/Hannu E K Nevalainen  _ // 1985+
 mr_Henk @ #AmigaSWE/IRCNet                          \X/Amiga user
Personal rc5-stats: 8,805 2^28-key blks, i.e. 2,363,574+ Mkeys, M68K Amiga.
TKGTTA: How to call a routine without knowing where it is