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 8653599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:34:59+00:00 2026-06-12T14:34:59+00:00

I am practicing to write a bootstrap using assembly (in AT&T syntax, and gnu/gas).

  • 0

I am practicing to write a bootstrap using assembly (in AT&T syntax, and gnu/gas). The small program is assembled and linked, then copied to the first sector of a virtual disk. BIOS will load it into 0000:7c00, and here comes the problem. The call hello will be translated from call 0010 to call 7c10 during running. But the movw $message, %as doesn’t get relocated. The ax is still 0026, not 7c26. The result is that I can’t make the Hello World on the screen. Instead, some random data at 0000:0026 will be displayed on the screen.

How can I make it correct during booting? Should I change the asm source code using some directives? Or should I change my link script?

Thank you!

.text
.global     _start
.code16

_start:
movw    %cs, %ax
movw    %ax, %ds
movw    %ax, %es
call    hello
jmp     .

.org    0x10

hello:
movw    $message, %ax
movw    %ax, %bp
movw    $13, %cx
movw    $0x1301, %ax
movw    $0x000c, %bx
movb    $0, %dl
int     $0x10
ret

message:    
.ascii  "Hello, World!"

.org    0x01fe
.byte   0x55
.byte   0xaa

I use the following assemble and link scripts

as -o boot.o boot.s  
    //generate object code

ld -Ttext 0x0 -e _start -s -o boot.out boot.o  
    //relocate .text to 0x0
    //entry is _start

objcopy -O binary -j .text boot.out boot
    //copy .text section to boot

vboxmanage convertfromraw boot boot.vdi --format VDI
    //create vdi for virtual box
  • 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-06-12T14:35:00+00:00Added an answer on June 12, 2026 at 2:35 pm

    I see that the main problem is in the way you are compiling your code.

    The correct steps to get your code working should be:

    as boot.s -c -o boot.o
    ld --oformat binary --Ttext 0x7C00 -o boot.bin boot.o
    

    Please note, as others have said, that I’m passing the --Ttext 0x7C00 parameter to ld, to force it relocating your code at that address.

    As an additional suggestion, try to structure your code like this:

    .text
    .global     _start
    .code16
    
    _start:
    jmp stage1_start
    
    ...
    
    stage1_start:
    
    <your bootloader here>
    

    Note that this is compiant with how BIOS code looks at hard drives, since after 2 bytes (the length of the first jump instruction) you should place the Disk Description Table.

    Additionally, you can refactor your last instructions in a more as-like syntax like this:

    . = _start + 0x0200 - 2
    .short 0x0AA55
    

    Where the . variable is the location counter. Look at this page for further information on how this counter works (in the context of ld, not as).

    Hope this helps!

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

Sidebar

Related Questions

I am practicing using pointers and stumbled upon something I don't understand. The program
Being new to c++ I've been practicing with questions. One program I wrote includes
I am practicing with Python using Pyramid framework. I created a py, myfuncs.py ,
I was practicing regular expressions and attempted to write a regex which will detect
I am practicing slicing, and I want to run a program that prints a
Alright I am practicing using cURL to login to different webservices. For this pariticular
I'm practicing programming in Assembly, making code C. I don't understand the conversion of
I'm practicing learning how to write classes and creating is relationships between objects. In
Hi I'm writing a simple Program for practicing to work with texture memory. I
i'm practicing c and looking to use visual studio. but can I write console

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.