Author Topic: Relocating a part of the program  (Read 8944 times)

Offline RuudB

  • Jr. Member
  • *
  • Posts: 40
  • Country: nl
    • Ruud's Commodore Site
Relocating a part of the program
« on: February 28, 2018, 12:02:54 PM »
Hello,

I'm writing a program that will be stored into EPROM and run on a XT. No DOS, just this program in EPROM. A part of this program has to be copied to another part of memory, 0000:0800h, and should be reached using a far call. I could program two separate BINs, combine the two in some way where the second BIN is stored at a fixed address and use this address in the first BIN. But what I want is to create just one BIN using one source file and tell NASM to assemble a part of the program with another ORG:

  org 0

.... program ....
  mov ax,0C800h
  mov ds,ax          ; segment source
  xor  ax,ax
  mov es,ax          ; segment destination
  mov si,Lab0800  ; offset source
  mov di,0800h     ; ofsett destination
  mov cx,<Length of BIN>
  rep movsb
.... rest of program ....

org 0800h

Lab0800:
.... part to be relocated ....

But I already found out two ORGs don't work. What could work? I'm sure it will be something simple but I haven't found it yet.
Thank you for any help!

Kind regards, Ruud Baltissen


Edit:
I bumped into ALIGN and that triggered a thought train. The 6502, the CPU I'm most familiar with, uses absolute addresses when doing a jump or calling a subroutine. The 8088 uses relative addresses. So I wrote a small test program using ALIGN and that does calls and jumps to parts that are more than 512 bytes away and it seems to work. Still I would like either conformation that this indeed works or comment that I'm overlooking something.
Thanks!
« Last Edit: February 28, 2018, 01:49:07 PM by RuudB »
With kind regards / met vriendelijke groet, Ruud Baltissen

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Relocating a part of the program
« Reply #1 on: February 28, 2018, 09:08:16 PM »
Hi RuudB,

Try "vstart". http://www.nasm.us/xdoc/2.13.03/html/nasmdoc7.html#section-7.1.3

You could also assemble a second program with its own "org" and "%incbin" it into your first program. But the multisection support was added for this purpose.

Best,
Frank


Offline RuudB

  • Jr. Member
  • *
  • Posts: 40
  • Country: nl
    • Ruud's Commodore Site
Re: Relocating a part of the program
« Reply #2 on: March 01, 2018, 06:24:09 AM »
Hallo Frank,

... Try "vstart". ...
Thank you!

Kind regards, Ruud
With kind regards / met vriendelijke groet, Ruud Baltissen