I learned x86-16 assembly and i want to learn to x86-32 assembly. I maked a simple 32-bit program but this code not work When program makes a far jump console displays 'JMP illegal descriptor 0' I use fasm and DOS Please show me what i'm doing bad
Here's my code
format MZ
push cs
pop ds
mov eax,cs
shl eax,4
mov [AdresSegmentuProgramu_32],eax ;Calculating real mode segment
add eax,gdt_table
mov [gdtr+2],eax
use32
lgdt [gdtr]
mov eax,[AdresSegmentuProgramu_32]
add eax,pmode_entry
mov [AdresSegmentu_PMODE_entry],eax
mov eax,cr0
or eax,1 ;Switch to PMODE
mov cr0,eax
mov eax,[AdresSegmentu_PMODE_entry] ;Far jump to reset CS and jump to simple code
mov [far_jump],eax
jmp far [ds:far_jump]
far_jump:
dd 0
dw 08h ; Selector 0x08
gdtr: dw 128
dd 0
AdresSegmentuProgramu_32 dd 0
AdresSegmentu_PMODE_entry dd 0
use32
gdt_table:
dq 0
code_descriptor:
dw 0ffffh
dw 0
db 0
db 09ah
db 11001111b
db 0
data_descriptor:
dw 0ffffh
dw 0
db 0
db 092h
db 11001111b
db 0
dq 0
dq 0
pmode_entry:
mov esi,0b8000h
mov byte [esi],'a'
fword
modifier rather than adb 66h
– Zaleause32
does the same that.code32
does in the GNU assembler. In this case the location of the firstuse32
is wrong: The CPU will execute all code inuse16
mode up to thejmp far
instruction. It will begin executing code inuse32
mode AFTER thejmp far
instruction. By usinguse32
before an instruction that is executed inuse16
mode, the assembler will generate wrong code. – Wheezyuse32
for 16-bit encoding present, and the FWORD modifier. also notable was thejmp $
in protected mode so the processor doesn't keep running non-code. Lastly the DS selectorwasn't set once in protected mode before accessing memory with an implicit DS. – Zalea