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] |
Art Berggreen 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?? > > I don't know the 80x86 machine architecture or 80x86 C calling > interface, but I'll make a few guesses. > > It looks like pokeb() takes a variable holding a segment number, > an offset into that segment, and data to write into memory ("poke"). > > > mov ax,[base_addr] > > mov es,ax > > Loads the content of the "base_address" variable into register es. > > > mov al,[bp+0x0C] > > Loads the value of "data" which is being passed on the stack at a stack > offset of 0x0c into register al. > > > mov si,[bp+0x0A] > > Loads the value of "offset" which is being passed on the stack at a stack > offset of 0x0a into register si. > > > mov es:[si],al > > Stores the data in register al into memory at the location pointed to > by the segment in register es and the offset in register si. > > Since the m68k is not a segmented memory machine, the pokeb() function > wouldn't need a base and offset, but in the interest of following the > same model, an m68k routine could look like: > > /* pokeb(char *base_addr, int offset, char data) */ > .global pokeb > pokeb: > move.l 4(%sp),%a0 /* get base_addr */ > add.l 8(%sp),%a0 /* add offset */ > move.b 15(%sp),(%a0) /* move data byte */ > rts > > Art Hii, Can anybody tell me how the argument will be passed into stack for function pokeb(char *base_addr, int offset, char data)?? Is it like below?? data highest byte (3rd arg, 4th byte) -> sp+15 data high byte (3rd arg, 3rd byte) -> sp+14 data low byte (3rd arg, 2nd byte) -> sp+13 data lowest byte (3rd arg, 1st byte) -> sp+12 offset highest byte (2nd arg, 4th byte) -> sp+11 offset high byte (2nd arg, 3rd byte) -> sp+10 offset low byte (2nd arg, 2nd byte) -> sp+9 offset lowest byte (2nd arg, 1 byte) -> sp+8 base_addr highest byte (1st arg, 4th byte) -> sp+7 base_addr high byte (1st arg, 3rd byte) -> sp+6 base_addr low byte (1st arg, 2nd byte) -> sp+5 base_addr lowest byte (1st arg, 1st byte) -> sp+4 sp highest byte -> sp+3 sp high byte -> sp+2 sp low byte -> sp+1 sp lowest byte -> sp+0 If it is the case, the assembler pokeb suppose to be like this : move.l 4(%sp),%a0 /* get base_addr */ swap %a0 /* exchange 16 bit halves, so that later on */ /* address will be base_addr+offset */ add.l 8(%sp),%a0 /* add offset */ move.b 15(%sp),(%a0) /* move data byte */ rts -- Dony Email : dony@willowglen.com.sg