NASM:远端呼叫,段和偏移量存储在寄存器中 [英] NASM: Far Call with Segment and Offset Stored in Registers

查看:72
本文介绍了NASM:远端呼叫,段和偏移量存储在寄存器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将代码段和偏移值存储在两个寄存器中,分别说AXBX.在NASM中,如何编码对AX:BX的远端调用?我尝试了call AX:BX,但出现了错误invalid combination of opcode and operands.我该如何编码此指令?

I've got the code segment and the offset values stored in two registers, say AX and BX respectively. In NASM how can I encode a far call to AX:BX? I tried call AX:BX, but I got the error invalid combination of opcode and operands. How do I encode this instruction?

推荐答案

在段和/或偏移量位于寄存器中的情况下,无法对远距离调用指令进行编码.远端调用指令要求将目的地指定为既提供目的地的段和偏移量的立即操作数,又提供提供此操作的内存操作数.因此,仅以下示例中的说明有效:

There isn't a way to encode a far call instruction where the segment and/or offset are in registers. The far call instruction requires that the destination either be given as an immediate operand that supplies both the segment and offset of the destination or a memory operand that does. So example only instructions like the following are valid:

    call 0x1234:0x5678   ; immediate operand
    call FAR far_func    ; immediate operand
    call FAR [far_fnptr] ; memory operand
    call FAR [bp - 8]    ; memory operand

因此,如果在AX和BX寄存器中有目标段和偏移量,则需要先将值存储在内存中的某个位置,然后才能调用寄存器所指向的函数.因此,例如,您可以执行以下操作:

So if you have the destination segment and offset in the AX and BX registers you'll need to store the value in memory some place before you can call the function the registers point to. So for example you could do something like the following:

    push ax
    push bx
    mov  bp, sp
    call FAR [bp]
    add  sp, 4

通常是在使用RETF指令的那一天:

Often back in the day the RETF instruction was used to do this:

    push cs
    push .return_here
    push ax
    push bx
    retf   
.return_here:

但是,在现代CPU上,这会严重影响性能,因为它将导致CPU的返回堆栈缓冲区生成不正确的分支预测.

However on modern CPUs this has a significant performance penalty as it will cause the CPU's return stack buffer to generate incorrect branch predictions.

这篇关于NASM:远端呼叫,段和偏移量存储在寄存器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆