1

I'm using 16-bit TASM compiler with DOSBox and would like to know how to include the dosbox printing function in my assembly code. What I'm trying to do is similar to the following (however that is with NASM and I need TASM. i.e. something that would work with an 8086):

global _main
extern _printf     ;What would be its equivalent in TASM?
section .data
msg db "Hello World!", 0Dh, 0Ah, 0
section .bss
section .text

_main:
push ebp
mov ebp, esp

push msg         ;How do we do
call _printf     ;this with TASM?

add esp, 4
mov esp, ebp
pop ebp
ret
  • 1
    NASM or TASM don't affect this too much except different directives to search for external symbol. This NASM example does use `printf` implementation from clib, which is added during linking final executable. So the first question is, do you have 16b C library to link against? Then just use the correct TASM directives to search for its functions, and use the appropriate calling convention of that 16b clib to call it (I can't recall any 16b real mode clib, even in DOS age toward end of it everything was 32b protected mode running under wrapper like DOS4GW, maybe something from early DOS age...) – Ped7g Nov 10 '17 at 06:48
  • 1
    It's more likely you will find some simpler IO 16b library (wasn't there one from Borland included with TASM itself?), fully fledged `printf` is "mass destruction weaponry" capable of many things, and just its implementation would probably take several kilobytes of machine code, do you really need `printf`, or are you trying just to output static string and some integer values? – Ped7g Nov 10 '17 at 06:53
  • 1
    Just trying to output integer values, and I know you can do it with interrupt 21 but that's not the way I want to do it. I want to include an external function. – OutOfABoxIntoAnother Nov 10 '17 at 07:20
  • take a look at this: [What is the best way to move an object on the screen?](https://stackoverflow.com/a/29579522/2521214) and look for `text.inc` file there is my lib for text printing using direct EGA/VGA VRAM access in 80x25 text mode. to print a number you just create string from the value first (doing hex print is easiest as you can convert the nibbles directly to chars. BCD is similar but need to augment the arithmetics code a bit and for decadic you need to divide by 10 and print the remainders in reverse order) . If you want to include external function than link it and use it ,,, – Spektre Nov 10 '17 at 07:36
  • 1
    Then you need first to posses that external function (library). If you don't have any, check your TASM distribution, I have about 20% confidence Borland did bundle simple IO library with it. I think (50% chance) there is also 16b real mode Irvine-lib (obsolete now, if it exists, as Irvine university moved to teach 32b protected mode under windows platform). Or check here x86 tag info page, about multi-digit value output, there are several SO questions+answers with simple "integer to string" code, some of them are directly for TASM+DOS target (and add that as internal function in your source). – Ped7g Nov 10 '17 at 08:06
  • 1
    And finally I think there may be something included with emu8086, but that's actually not free SW, so probably least attractive option, if you already bought the TASM... *"dosbox printing function"* - DOS or dosbox don't contain such function of course, all DOS provides is in `int 21h` and BIOS in `int 10h` (mostly, maybe some output service is even in other interrupt, but no integer output for sure). And for reasonable speed you should write directly to video memory skipping BIOS/DOS completely, but that's not needed for texts (although I find it still more convenient than DOS services). – Ped7g Nov 10 '17 at 08:08
  • 1
    @Ped7g : TASM won't come with any such library but 16-bit versions of TurboC/C++ will. The _C_ libraries will be the files `c?.lib` and the _C_ startup library code will be `c0?.lib` where `?` is the the letter denoting the memory model. – Michael Petch Nov 11 '17 at 01:57

1 Answers1

0

you can use the int 21h interrupt to print a msg. you can do this by first in the msg in the end you need the character '$' to signal the end of the msg, second moving the offset of the msg to the register dx then mov ah,9 and calling the interrupt.

it should look like this: msg db 'hello wrold!$'

mov dx,offset msg mov ah,9 int 21h