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

  • Home
  • SEARCH
  • 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 7622177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:23:13+00:00 2026-05-31T04:23:13+00:00

In my efforts to understand how to use the GNU binutils to build a

  • 0

In my efforts to understand how to use the GNU binutils to build a simple boot loader using
gas I have come across the question, how do you tell the linker where to put your data, in a file that uses .org to advance the location counter while keeping the file size at 512 bytes. I can’t seem to find a way to do this.

The assembly program that tries to do this is:

# Author: Matthew Hoggan
# Date Created: Tuesday, Mar 6, 2012

.code16                      # Tell assembler to work in 16 bit mode
.section .data
msg:                         # Message to be printed to the screen
  .asciz "hello, world"

.section .text
.globl _start                # Help linker find start of program
_start:
  xor  %ax,  %ax             # Zero out ax register (ah used to specify bios function to Video Services) 
  movw %ax,  %ds             # Since ax is 0x00 0x00 use it to set data segment to 0
  mov  $msg, %si             # Use source index as pointer to string

loop:
  movb %ds:(%si), %al        # Pass data to BIOS function in low nibble of ax
  inc  %si                   # Advance the pointer
  or   %al, %al              # If byte stored in al is equal to zero then...
  jz   _hang                 # Zero signifies end of string
  call print_char            # Print current char in al
  jmp loop                   # Repeat

#
# Function that uses bios function calls
# to print char to screen
#
print_char:
  movb $0x0e, %ah             # Function to print a character to the screen
  movb $0x07, %bl             # color/style to use for the character
  int  $0x10                  # Video Service Request to Bios
  ret

#
# Function used as infinite loop
#
_hang:
  jmp  _hang

.org 510
.byte 0x55, 0xAA

.end

UPDATE
Using the following commands I get the following error:

mehoggan@mehoggan-laptop:~/Code/svn_scripts/assembly/bootloader/gas$ ld --oformat binary -o string string.o 
string.o: In function `_start':
(.text+0x5): relocation truncated to fit: R_X86_64_16 against `.data'
  • 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-31T04:23:14+00:00Added an answer on May 31, 2026 at 4:23 am

    For this kind of work you should write your own linker script. Just pass it to the linker with the -T option.

    My script for an almost identical problem was:

    SECTIONS
    {
        . = 0x1000;
        bootsec :
        {
            *(.text)
            *(.data)
            *(.rodata)
            *(.bss)
            endbootsec = .;
            . = 0x1FE;
            SHORT(0xAA55)
        }
        endbootsecw = endbootsec / 2;
        image = 0x1200;
    }
    

    With that trick you don’t event need to put the 0x55 0xAA in the assembler!

    The 0x1000 at the beginning: Actually all the jumps are relative, so that is not used, but it is needed later for the jump into protected mode…

    endbootsecw, endbootsec and image are symbols used elsewhere in the code.

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

Sidebar

Related Questions

I am trying to build some simulation software using makefile provided by them after
I've been tinkering with some code in a effort to understand OOP using c.
I can understand wanting to avoid having to use a cursor due to the
Noob question. I have been programming at basic level for quite a while but
Surprisingly can't find a match for my question. I have one table that I
In my efforts to resolve Python issue 1578269 , I've been working on trying
I've exhausted all efforts at what appears to be a trivial problem, but gotten
With lots of efforts and tutorials I got xdebug/wincachegrind up and running but most
I know Microsoft has made efforts in the direction of semantic and cross-browser compliant
This is similar to my previous efforts ( wordEnds and repeatEnd ): as a

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.