Link to home
Start Free TrialLog in
Avatar of Wtwh
Wtwh

asked on

8086 Assembly : Memcpy procedure for 80188 embedded system

Hi

I need to write a "memcpy" procedure in assembly for an embedded system running on an 80188 microprocessor. Memcpy() copies n bytes from memory area s2 to s1 and returns s1. It is called in C code as follows:

void *memcpy(void *s1, const void *s2, size_t n)

I am very new to assembly programming and is hoping for some advice how this can be done. Btw, is there a compiler which translate C code into assembly?

Any advice is very much appreciated. Thank you.

Regards
Wilson
ASKER CERTIFIED SOLUTION
Avatar of dimitry
dimitry

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MrT-RSI
MrT-RSI

To speed things up you might wanna replace movsb with movsw, especially for larger data blocks:

mov cx,[bp+12]
lds si,[bp+8]
les di,[bp+4]

shr cx,1   ;divide by 2
jnc cxeven
  movsb   ;move 1 byte if odd
cxeven:
rep movsw   ;move rest of bytes in words

Or was the 80188 the 16 bit processor with the 8 bit mem access ? then stick with the original.

You'd better do a "cld" beforehand!