Solved

8086 Assembly : Memcpy procedure for 80188 embedded system

Posted on 2003-10-30
3
937 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Buffer Overflow Bomb Assignment - Final Phase 3 1,558
assembly flow 3 559
Binary Bomb/GDB Questions 10 1,884
ia32 assembly to c 3 477
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Find out what the Office 365 disclaimer function is, why you would use it and its limited ability to create Office 365 signatures.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now