Solved

8086 Assembly : Memcpy procedure for 80188 embedded system

Posted on 2003-10-30
3
952 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here's how to start interacting with our community through Post.
This article outlines some of the reasons why an email message gets flagged as spam on a recipient's end.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

729 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