0

I am writing 16-bit real mode assembly code that uses BIOS routines to dump a memory buffer to disk. I can't seem to figure out the syntax to get the segment register set correctly when setting up the pointer to the data buffer to be dumped. (I'm using gcc as my assembler and linker.)

.text

# mov Doesn't work when $data_buffer_section ends up in a different segment.
mov $data_buffer_section, %bx 

# Enough code here to put the .data section in a different segment

.section .data

data_buffer_section:  .ascii "<Generated data overwrites this.>"

mov works, as long as the .text section is small enough that the .data section is in the same segment. Once the code is large enough, then I get this linker error: (.stage2+0x22f): relocation truncated to fit: R_386_16 against .data

This means that I need to specifically load %sp as well as %bx, correct? I tried les $data_buffer_section, %si and les $data_buffer_section, %bx; but, get this syntax error: Error: operand type mismatch for les

I also tried les data_buffer_section, %si (without the $). The syntax error goes away, but the linker error does not. (Plus, I don't think that will load the correct values, will it?)

Zack
  • 6,232
  • 8
  • 38
  • 68
  • 3
    The GNU assembler does not really support segmentation. And that's not how you use `les`. Try using a different assembler. – fuz Jun 12 '17 at 13:27
  • 1
    You're also going to run into the problem that the "binary" format doesn't support segmentation either. You'll have to do all your own segment calculations unless you're using segmented executable format like MS-DOS's EXE format. – Ross Ridge Jun 12 '17 at 14:53

0 Answers0