Error: Memory operand not allowed in context

62 Views Asked by At
.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

It is supposed to add value into orderTotal, but I end up with memory operand not allowed in context error.

1

There are 1 best solutions below

0
Sep Roland On
orderTotal db 0.0

This is not how you define a real number. Use:

  • REAL4 for single precision floating point values (4 bytes)
  • REAL8 for double precision floating point values (8 bytes)
  • REAL10 for extended precision floating point values (10 bytes)

The arithmetic operations that the FPU (Floating Point Unit) does, all happen within the FPU. You need to load operands from / store results to memory:

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