LLMs and BIOS INT 10h
Not a very fair test, but whatever. Just for fun I asked an LLM about some good old x86 assembler code. This is the prompt:
/no_think Find the bug: mov ax, 0x3 ; switch into mcga graphics mode (320x200) int 0x10
the bug being of course that the MCGA 320x200 graphics mode has
number 0x13, not 0x3. Not so obvious to the
LLM, which manages to produce this gem:
The code you've provided is a simple x86 assembly snippet that attempts to switch into MC68420 mode (a variant of the Motorola 68000) and call the BIOS interrupt
0x10with the operand0x3. However, there are several issues with this code:1. Invalid Mode Switching:
- The value
0x3is not a valid mode for the MC68420. The correct mode for MC68420 is0x03(or0x03in some implementations), which is used to switch into 320x200 mode.- The instruction
mov ax, 0x3sets the mode register, but the actual mode switch is done using themov ax, 0x03instruction, not0x3.2. Incorrect Interrupt Usage:
- The BIOS interrupt
0x10is used for system calls, but it is not the correct one for switching to MC68420 mode. The correct interrupt for mode switching is0x10with the operand0x03(or0x03depending on the system).- The instruction
int 0x10is not the correct way to switch to MC68420 mode; it should beint 0x10with the operand0x03.3. Corrected Code:
The correct code to switch into MC68420 mode and call the BIOS interrupt would be:
mov ax, 0x03 ; Set mode to 0x03 (MC68420) int 0x10 ; Call BIOS interrupt4. Additional Notes:
- The
int 0x10instruction is used for system calls, but in this context, it's being used to switch to a specific mode. The exact behavior may vary depending on the specific system and BIOS implementation.- If you're trying to use this in a real system, you may need to refer to the specific documentation for your hardware and BIOS.
In short, the bug is in the mode setting and the interrupt call. The correct mode is
0x03, and the interrupt should be called with that value.
An earlier attempt without the /no_think failed
because the program kept getting into an infinite loop.