Mix 32-bit and 16-bit code with nasm

This is a low level system issue.

I need to mix 32-bit and 16-bit code, because I'm trying to return to real mode from protected mode. As a bit of background information, my code does this right after loading GRUB, so I don’t have any annoying operating system to tell me what I can and cannot do.

Anyway, I use [BITS 32] and [BITS 16] with my build to tell nasm what types of operations it should use, but when I test my code use bochs, it looks like for some bochs the code that I wrote is not executed. Assembler seems to be sticking with extra functions 0x66and 0x67that mix bochs.

So, how do I get nasm to successfully build the code, where I mix 32-bit and 16-bit code in the same file? Is there any trick?

+5
source share
4 answers

The problem turned out to be that I set up descriptor tables incorrectly. I had a few bits, so instead of switching to 16-bit mode, I switched to 32-bit mode (with segments that had a limit of 1 megabyte).

Thanks for the suggestions!

Terry

+6
source

0x66 and 0x67 are operation codes that are used to indicate that the following operation code should be interpreted as non-standard bit. More specifically (and in accordance with this link ),

" NASM BITS 16, , 32- , 0x66, , 32- , 0x67. BITS 32 : 32 - , 16- 0x66, 16- 0x67."

, .

+3

!

/, , nasm BITS? , - , nasm .

nasm, , bochs. , 16- 32- .

0

, 16 , BITS 16. , 32- , 0x66, 32- 0x67.

Intel IA-32, 3, 16 (MIXING 16-BIT AND 32-BIT CODE, ):

, 8086 SMM 16- .

BITS 32 , .

0

All Articles