Solved

8086 Assembly : Memcpy procedure for 80188 embedded system

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

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

Suggested Solutions

Title # Comments Views Activity
Convert from C to MIPS 14 1,398
Mainframe Assembler 9 743
help with ram spec on M4N68T V2 Motherboard 11 581
Learning ARM system and assembly language with a Raspberry pi 2 88
IT certifications are a concrete representation of continual learning on the part of the candidate.  Continual learning is necessary for the long term success of an IT professional, but are IT certifications the right path for you?
Many businesses neglect disaster recovery and treat it as an after-thought. I can tell you first hand that data will be lost, hard drives die, servers will be hacked, and careless (or malicious) employees can ruin your data.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

789 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