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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:34:52+00:00 2026-05-16T06:34:52+00:00

I am writing small kernel for the 8086 processor (Working in BC3.1, on Windows

  • 0

I am writing small kernel for the 8086 processor (Working in BC3.1, on Windows XP as host operating system). Kernel is multithreaded, so I have problems when I use printf or cout for debugging (somewhere in code, printf sets InterruptEnable flag to 1, and my timer interrupt routine calls dispatch and my code breaks down).

Because of that, I wrote simple puts function in inline asm:

void _printf(char *c)
{
    //setup data
    asm{
        mov ch, 10
        mov cl, 0
        mov ah, 0x2
        mov bx, WORD PTR c
    }

    loop: asm{
              //\0?
              cmp [bx], cl
              je exit_prc
              mov dl, [bx]
              int 0x21
              inc bx
              //is there \n?
              cmp [bx], ch
              je newline

              jmp  loop
    }
    exit_prc: return;
    newline: asm{
                //insert cr char
                mov dl, 0xD
                int 21h
                jmp loop
    }


}

Now, I call it somewhere in, lets say PCB::PCB() like this:
_printf(“Counstructor PCBa\n”);
and it works fine. However, when I call it somewhere else, in some other file with other string it outputs for example “tructor PCBa\n”.

I don’t have a clue what is going on. Memory model is huge.

  • 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-16T06:34:52+00:00Added an answer on May 16, 2026 at 6:34 am

    First of all, at least in my opinion, you’ve chosen a rather poor name — what you have is pretty much a puts, not a printf. Second, for what you’re trying to accomplish, you might want to try using Borland’s cprintf, cputs, and such — they use the DOS console output routines, and there’s a pretty decent chance they don’t enable interrupts.

    If that won’t work, there still seems to be little reason to use inline assembly. I’d do something like this:

    // warning: untested -- and it's been a while since I wrote any code like this, 
    // so it's probably a little wrong.
    //
    void myputc(char ch) { 
        union REGS in, out;
    
        // set up registers here:
        in.h.ah = 2;
    
        in.h.dl = ch;
        intdos(&in, &out);
    }
    
    void myputs(char huge *s) { 
        while (*s) { 
            if (*s == '\n')
                myputc('\r');
            myputc(*s++);
        }
    }            
    

    If you really want to use assembly language, my advice would be to write it as a separate module of pure assembly language:

    ; Again: not tested and I haven't done this in a while, so use with care.
    ;
    .model large, c
    
    .code
    
    LF = 10
    CR = 13
    
    putc proc
        mov dl, al
        mov ah, 2
        int 21h
        ret
    putc endp
    
    puts proc string: ptr char
        mov si, string
        lodsb
    next:
        cmp al, LF
        jnz printit
        mov dl, CR
        mov ah, 2
        int 21h
    printit:
        mov dl, al
        mov ah, 2
        int 21h
        lodsb
        test al, al
        jnz next
        ret
    puts endp
        end        
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 492k
  • Answers 492k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You don't need to. There is both a 32 bit… May 16, 2026 at 10:28 am
  • Editorial Team
    Editorial Team added an answer A lot of the answer is wrapped up in whatever… May 16, 2026 at 10:28 am
  • Editorial Team
    Editorial Team added an answer In your controller: $this->view->myvar = $value In your subsequent view… May 16, 2026 at 10:28 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

when writing small functions I often have the case that some parameters are given
I'm writing small and very DRY framework, which heavily relies on metadata. I'd like
I have a variety of small C# winforms applications (though this should apply equally
I have a windows service writes its log in a text file in a
SOLVED see Edit 2 Hello, I've been writing a Perl program to handle automatic
I'm working on an embedded Linux project that interfaces an ARM9 to a hardware
I have a thread that needs to write data from an in-memory buffer to
I am currently writing a quick script in Ruby that goes through all the
I'm working on playing audio from an audio stream using VC++ with the QtMultimedia
I've been making use of InfoBox to draw custom overlays on my GoogleMap. 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.