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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:50:23+00:00 2026-06-01T02:50:23+00:00

I’ve been working on a real mode OS, writing in assembly and compiling to

  • 0

I’ve been working on a real mode OS, writing in assembly and compiling to flat .bin executables with NASM.
I would like to write some of the OS in C, and so wrote an experiment program (ctest.c) which I would like to access a string and print the first character:

void test();

int main() { test(); return 0; }

char msg [] = "Hello World!";

void test() {
    _asm
    {
        mov si, word ptr [msg]
        mov al, [si]
        mov ah, 0eh
        int 10h
    }
    for(;;);
}

I compiled this with Open Watcom v1.9 using wcl ctest.c -lr -l=COM . This creates ctest.com. The kernel, which I wrote in NASM assembly, loads this program to 0x2010:0x0000, sets DS and ES to 0x2000:0x0000 and then jumps to 0x2010:0x0000. This is how I have been calling .COM programs written in assembly and compiled with nasm -f bin test.asm -o test.com.
When I test the OS (using Bochs), it successfully loads ctest.com, but prints out a meaningless character that is not part of msg[].
Does anyone have any suggestions about this? I think the string is just being initialized in the wrong place. I would like to keep this as a 16-bit OS.
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-06-01T02:50:24+00:00Added an answer on June 1, 2026 at 2:50 am

    You are using wrong addresses.

    You either load at 0x2000:0x0100 and jump to 0x2000:0x0100 (don’t forget setting DS=ES=SS=0x2000 and SP=0 prior to that) OR you load at 0x2000:0x0000 (equivalent to 0x1FF0:0x0100 because 0x2000*0x10+0x0000 = 0x1FF0*0x10+0x0100 = 0x20000 = physical memory address in real mode) and jump to 0x1FF0:0x0100 (don’t forget setting DS=ES=SS=0x1FF0 and SP=0 prior to that).

    The reason for all of this is that compiled x86 code is generally not position-independent and if you move it, you have to adjust some data offsets inside of the code. Obviously, you weren’t making these adjustments. In simple cases there was nothing to adjust and you got away with wrong addresses.

    EDIT:

    Actually, there’re more problems here:

    1. mov si, word ptr [msg] must change to lea si, byte ptr [msg] because you don’t want to load si with what’s inside the string, you want to load it with the string’s address.
    2. The startup code that’s linked to your program by OW is dependent on DOS and calls DOS functions, which you don’t have when you boot your program. See how to work around this here.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in

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.