assembly 错误:上下文中不允许内存操作数

rjee0c15  于 2023-05-07  发布在  其他
关注(0)|答案(1)|浏览(143)
.code
orderTotal db 0.0

Burger:
    fadd dword ptr [orderTotal], 10
    jmp Food

Pizza:
    fadd dword ptr [orderTotal], 16
    jmp Food

ChickenRice:
    fadd dword ptr [orderTotal], 8
    jmp Food

它应该将值添加到orderTotal中,但我最终得到了memory operand not allowed in context错误。

snz8szmq

snz8szmq1#

orderTotal db 0.0

这不是你如何定义一个真实的。用途:

  • REAL4用于单精度浮点值(4字节)
  • REAL8用于双精度浮点值(8字节)
  • REAL10用于扩展精度浮点值(10字节)

FPU(浮点单元)所做的算术运算都发生在FPU内部。你需要将操作数从/ store结果加载到内存中:

orderTotal      REAL4 0.0
costBurger      SWORD 10
costPizza       SWORD 16
costChickenRice SWORD 10

...

Burger:
    mov  bx, OFFSET costBurger
    jmp  AddIt
Pizza:
    mov  bx, OFFSET costPizza
    jmp  AddIt
ChickenRice:
    mov  bx, OFFSET costChickenRice
AddIt:
    fld  orderTotal       ; Load ST0 from the short real in memory
    fiadd SWORD PTR [bx]  ; Raise ST0 by a signed word in memory
    fstp orderTotal       ; Store ST0 to the short real in memory
                          ; - because of the 'p', ST0 is freed on the FPU stack
    jmp  Food

相关问题