How to code a far absolute JMP/CALL instruction in MASM?

前端 未结 3 865
迷失自我
迷失自我 2020-12-02 02:05

How can I write a far absolute JMP or CALL instruction using MASM? Specifically how do I get it to emit these instruction using the EA and CA opcodes, without manually emitt

相关标签:
3条回答
  • 2020-12-02 02:44

    Have you considered using the __emit pseudoinstruction?

    https://msdn.microsoft.com/en-us/library/1b80826t.aspx

    I once had to use inline assembler to code a far jump. I can't remember the opcode for a far jump, but you could do something like this

    __emit      0eah
    __emit      0
    __emit      0
    __emit      0
    __emit      0
    __emit      8h
    __emit      0
    
    0 讨论(0)
  • 2020-12-02 02:53

    There's one way you can do it, but you need to use MASM's /omf switch so that it generates object files in the OMF format. This means the object files need to be linked with an OMF compatible linker, like Microsoft's old segmented linker (and not their current 32-bit linker.)

    To do it you need to use a rarely used and not well understood feature of MASM, the SEGMENT directive's AT address attribute. The AT attribute tells linker that the segment lives at a fixed paragraph address in memory, as given by address. It also tells the linker to discard the segment, meaning the contents of the segment aren't used, just its labels. This is also why the /omf switch has to be used. MASM's default object file format, PECOFF, doesn't support this.

    The AT attribute gives the you segment part of the address we want to jump to. To get the offset part all you need to do is use the LABEL directive inside the segment. Combined with the ORG directive, this lets you create a label at the specific offset in the specific segment. All you then need to do is use this label in the JMP or CALL instruction.

    For example if you want to jump to the BIOS reset routine you can do this:

    bios_reset_seg SEGMENT USE16 AT 0ffffh
    bios_reset LABEL FAR
    bios_reset_seg ENDS
    
    _TEXT SEGMENT USE16 'CODE'
        jmp bios_reset
    _TEXT ENDS
    

    Or if you want to call the second stage part of your boot loader whose entry point is at 0000:7E00:

    zero_seg SEGMENT USE16 AT 0
        ORG 7e00h
    second_stage LABEL FAR
    zero_seg ENDS
    
    _TEXT SEGMENT USE16 'CODE'
        call second_stage
    _TEXT ENDS
    
    0 讨论(0)
  • 2020-12-02 03:02

    i have been testing with MASM 6.15 this code, i think this can help you.

        .model small
        .386
        .stack 100h
    
        .DATA
         Message    DB  'hello','$'
         JMPPOS DB  78h,56h,34h,12h  ;the address to be jumped to  1234:5678
    
        .code
        .startup
    
         JMP  dword  ptr [JMPPOS]
    
        .exit
        END
    
    0 讨论(0)
提交回复
热议问题