Borland C ++ inline asm problem with WORD PTR and string

I am writing a small kernel for the 8086 processor (working in BC3.1, in Windows XP as the host operating system). The kernel is multi-threaded, so I have problems when I use printf or cout for debugging (somewhere in the code, printf sets the InterruptEnable flag to 1, and my timer interrupt routine causes dispatching, and my code aborts).

Because of this, I wrote a 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’ll name it somewhere, say PCB :: PCB () like this:
  _printf ("PCBa Advisor \ n");
and it works great. However, when I call it somewhere else, in some other file with a different line, it displays, for example, "tructor PCBa \ n".

, . .

+3
1

, , -, - , , - puts, printf. -, , , Borland cprintf, cputs .. - DOS, , .

, -, . - :

// warning: untested -- and it been a while since I wrote any code like this, 
// so it 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++);
    }
}            

, :

; 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        
+2
source

Source: https://habr.com/ru/post/1759779/


All Articles