Solved

8086 Assembly : Memcpy procedure for 80188 embedded system

Posted on 2003-10-30
3
946 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:Wtwh
3 Comments
 
LVL 11

Accepted Solution

by:
dimitry earned 50 total points
ID: 9650933
Any C-compiler should have an option to produce Asm-output.

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

_memcpy proc      near
      push      bp
      mov      bp,sp
      push      si
      push      di
      push      ds

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

      rep      movsb

      pop      ds
      pop      di
      pop      si
      pop      bp
      ret
_memcpy endp
0
 
LVL 2

Expert Comment

by:MrT-RSI
ID: 9659291
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.
0
 
LVL 22

Expert Comment

by:grg99
ID: 9665740

You'd better do a "cld" beforehand!

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASM problem 2 31 346
How to change a program name  in the header? 1 366
help with ram spec on M4N68T V2 Motherboard 11 575
FSM's, Flow Charts or Something else 5 370
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will giveā€¦
Read about the ways of improving workplace communication.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question