0

I have tried this code:

int main()
{
    __asm ("mov %dl, 0"); // Cursor X Position
    __asm ("mov %dh, 0"); // Cursor Y Position
    __asm ("mov %ah, 2"); // Set Cursor
    __asm ("mov %bh, 0"); // Page Number
    __asm ("int $0x10"); // Interrupt

    return 0;
}

But I get this output:

Process returned -1073741819 (0xC0000005)

I'm using "Code::Blocks" with "GNU GCC Compiler".

1999xCoder
  • 13
  • 3
  • Which OS and CPU architecture are you trying to run this on? – Michael Feb 04 '22 at 09:18
  • Windows 10 - Intel i7 64-bit. – 1999xCoder Feb 04 '22 at 09:20
  • 2
    It seems you're attempting to do some DOS programming in a Windows environment. That won't work very well. What resource are you using to learn about "cursor" position? – Some programmer dude Feb 04 '22 at 09:21
  • Then you should probably use the appropriate Windows API function instead: https://learn.microsoft.com/en-us/windows/console/setconsolecursorposition – Michael Feb 04 '22 at 09:21
  • Is there any other ways to set cursor position in C/C++ before it gets to Windows? – 1999xCoder Feb 04 '22 at 09:23
  • No, ISO C++ doesn't have a cursor. That's a feature of the Windows terminal you're running in. (Or for a different OS, a feature of the terminal there.) Also, even for DOS this GNU C inline asm would be unsafe: you modify registers without telling the compiler about it. (But never mind that because inline asm isn't going to be useful for this in a Windows program.) – Peter Cordes Feb 04 '22 at 09:30
  • 2
    @1999xCoder -- If you got that code from a book, that book probably is dog-eared, with yellowing pages. The point is that this type of coding was for an OS that had long since passed on. – PaulMcKenzie Feb 04 '22 at 09:33

0 Answers0