Inline Assembly Jump Error

后端 未结 3 424
渐次进展
渐次进展 2021-01-17 06:38

Why does this fail, once Masm reaches jmp?

struct gdt_entry
{
    unsigned short limit_low;
    unsigned short base_low;
    unsigned char base_middle;
    u         


        
3条回答
  •  伪装坚强ぢ
    2021-01-17 07:14

    Try to put the following pragma before and after the structure definitions:

    #pragma pack(push,1)
    
    struct gdt_entry
    {
        unsigned short limit_low;
        unsigned short base_low;
        unsigned char base_middle;
        unsigned char access;
        unsigned char granularity;
        unsigned char base_high;
    };
    
    struct gdt_ptr
    {
        unsigned short limit;
        unsigned int base;
    };
    
    #pragma pack(pop)
    

    Although it has no effect on gdt_entry, these instructions change the memory layout of the gdt_ptr structure. The default behavior of the compiler is to align structures elements on 32 bits. Hence, the previous definition would be equivalent to :

    struct gdt_ptr
    {
        unsigned short limit;
        unsigned short unused;
        unsigned int base;
    };
    

    which is invalid from the processor point of view.

提交回复
热议问题