Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6858535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:10:17+00:00 2026-05-27T02:10:17+00:00

First up, using NASM and the target is x86, and running in 16-bit Real

  • 0

First up, using NASM and the target is x86, and running in 16-bit Real Mode of x86.
I want to copy code at one memory location to another, and then do a call/jmp to the destination, so I can execute the code there. The code is initially at 0x1000:0x0 (segment:offset). Now, I want to copy it to, say 0x3000:0x0. And the code is 512 bytes in size, exactly. I’m trying to do this with following routine.

org 0x500

;The code to be copied is located at 0x1000:0x0. We want to copy it to 0x3000:0x0

copy:

  mov esi,0x1000  ; source address of the code in DS:SI
  mov edi,0x3000  ; destination address of the code in ES:DI
  mov ecx,0x200   ; size of the code, 512 bytes (0x200)
  rep movsb       ; copy bytes from address in SI to address in DI.

  jmp 0x3000:0x0  ; jump to the destination , and execute the code there.

The code being copied just prints a string. So if the above snippet works, I would see that string on screen. Also, I have verified that the copied code is working , and that it is indeed present at 0x1000:0x0, so no such obvious/silly mistakes made.
The above routine is failing for some reason. The possible points of failure, in my opinion, could be wrong addresses given. I’m not sure of what to put in SI and DI before the copying. Should these be offsets or the actual address? The documentation doesn’t make this clear. Also, should I be explicitly initializing ES and DS?

I have tried various combinations of things to try to make this work, but to no avail. One of them was this:

org 0x500

;The code to be copied is located at 0x1000:0x0. We want to copy it to 0x3000:0x0

copy:
  mov bx,0x1000
  mov ds,bx       ; set DS explicitly to 0x1000.
  mov esi,0x0     ; source address of the code in DS:SI (0x1000:0x0)
  mov bx,0x3000
  mov es,bx       ; set ES explicitly to 0x3000
  mov edi,0x0     ; destination address of the code in ES:DI (0x3000:0x0)
  mov ecx,0x200   ; size of the code, 512 bytes (0x200)
  rep movsb       ; copy bytes from address in SI to address in DI.

  jmp 0x3000:0x0  ; jump to the destination , and execute the code there.

So here I explicitly set ES:DI and DS:SI. This also did not work. I also tried giving the actual physical addresses to SI and DI, failed. Now, I’m out of options. I’m sure there’s some conceptual memory addressing mistake being made here, but I’m not able to catch it.
(And yeah, the code copied is 512 bytes in size, raw binary).

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:10:18+00:00Added an answer on May 27, 2026 at 2:10 am

    The problem got fixed in a weird way finally. Okay , the first few lines of the program had this:

    org 0x500
    mov ax,cs
    mov ds,ax
    mov es,ax
    

    This was followed by the copying routine. I edited the code to this: (and it worked)

    org 0x500  
    xor ax,ax  ;make ax 0, instead of copying CS to it
    mov ds,ax
    mov es,ax
    

    With this change the first copy routine I posted, also worked. I don’t know why though. I was just playing around with these segment values, and this clicked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using ASP.NET MVC and Entity Framework Code First using the repository
I'm using ubuntu 64-bit and trying to run a .asm file on NASM. But
I have some code that performs a deep copy using Object.clone, but I'm trying
Compare the following two pieces of code, the first using a reference to a
First time using Asp.net-mvc and originally followed the NerdDinner tutorial. My form submit button
This is my first experience using the Zend Framework. I am attempting to follow
When I first started using revision control systems like CVS and SVN , I
This is my first time using joomla. I don't know if I'm using the
this is my first time using StAX for parsing XML documents (still in the
Today is my first day using ASP.NET MVC, and I'm finding it very intriguing.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.