ASM code and C++

Hallo, cplusplus.


i am trying to get a bios interrupt call to the bios in c++.
but compiling it i get a error..

kernel.c:27:9: warning: implicit declaration of function ‘int32’ [-Wimplicit-function-declaration]
27 | int32(0x10, &regs);
| ^~~~~


1
2
3
4
5
6
 void vga_init() {
	// Set video mode 320x200 256 color graphics (VGA) by calling BIOS int 10h
	regs16_t regs;
	regs.ax = 0x0013;
	int32(0x10, &regs);
}
You can not just write assembler instructions into C/C++ code! 😏

If you want to code in the assembler language, then you need to use separate assembly code files (typically with a .s or .asm file extension) that will be processed by an assembler such as MASM or NASM, not by a C/C++ compiler! Or, if your goal is to embed assembler code directly into C/C++ source code files, then you need to look into the topic of "inline assembler".

See also:
https://cs.lmu.edu/~ray/notes/nasmtutorial/
https://en.wikipedia.org/wiki/Inline_assembler

Inline Assembler with MSVC/GCC:
https://learn.microsoft.com/en-us/cpp/assembler/inline/inline-assembler-overview?view=msvc-170
https://www.felixcloutier.com/documents/gcc-asm.html

____

Having said that, if you create a "normal" executable that is going to run as a user-space process, then, on any modern operating system, you can not do any "low level" hardware stuff – such as setting the video mode – neither with assembler code or in another way! That is something you would do when writing a device driver (kernel module) or when writing your own operating system...

On modern operating systems, you'd invoke some sort of graphics API to tell the graphics driver to set the video mode for you!
Last edited on
and in case you overlook it, as its probably buried if said in the links,
visual studio does not support inline assembler in 64 bit compiles, or it did not last time I tried. So you are stuck in a 32 bit program if you want to play with it, though I believe you can embed 32 bit into 64 bit with some epic hand waving after you get it working, eg in a dll, but that is also not trivial -- there are instructions for it online though.

setting the video mode: the mode has to be supported by your card. I have no idea if modern cards support these ancient modes still. They may all support 640x480 as a common least setting for text dump in crash screen mode, but the other old ones, I do not know. You can probably get away with this junk in a dos VM.
Last edited on
OP is clearly not messing with programming on modern systems. Hints:

  • File name is “kernel.c
  • “int32()” is an old function for invoking a hardware interrupt (INT 32h) in DOS-mode programs

It continues to exist in various forms among libraries for programming operating systems.


@nvthielen
The error message means you did not #include the necessary header to use the int32() function. (Or that you in some way mis-spelled the function name. IDK exactly what you are looking to use.)

When the compiler discovers that you are trying to use a function it knows nothing about, ancient C protocol is to assume that it is declared as:

    int int32(...)

Which is very likely wrong, so your modern compiler (GCC, I presume?) is being very nice to you to point it out.


Questions about doing this kind of stuff (writing OSes) are typically better to ask over at https://wiki.osdev.org/

If you are using the (ancient) Borland C++ 4.0 compiler (or something like that) under DosBox, then some of us here may be able to help, but honestly, it has been at least 20 years since I last even looked at code that old.

Good luck!
Registered users can post here. Sign in or register to post.