x86 - (fldcw [sp]) Control Word issue in assembly code -
i new assembly & first programming language.
i have question line:fldcw [sp]
. causes build error: error a2031: must index or base register
i aware that:
sp 16 bit stack pointer
esp 32 bit stack pointer
-
i trying learn utilizing fpu control word. use skylake processor.
all information obtained at: http://www.website.masmforum.com/tutorials/fptute/fpuchap3.htm#fstcw
when replace esp sp builds fine.
am misunderstanding guide? causing error?
.386 .model flat, stdcall option casemap :none includelib \masm32\lib\msvcrt.lib sprintf proto c :vararg includelib \masm32\lib\user32.lib messageboxa proto :ptr,:ptr,:ptr,:dword includelib \masm32\lib\kernel32.lib exitprocess proto :dword .data _title db "result",13,10,0 $interm db "%0.4f","+","%0.5f",13,10,0 oldcw dw ? .code main proc local szbuf[9]:byte fstcw oldcw ;get current control word retain setting bits ;not related rounding control (rc) bits fwait ;to insure storage instruction completed mov ax,oldcw ; , ax,0f3ffh ;clears rc bits, leaving other bits unchanged ;not necessary here because both bits set or ax,0c00h ;this set both bits of rc field truncating mode ;without affecting of other field's bits push eax ;use stack store modified control word in memory fldcw [sp] ;load modified control word fldcw oldcw ;restore previous control word pop eax ;clean-up stack ;this retrieve 16-bit or 32-bit integer ;possibly returned "other fpu instruction(s)" finished: invoke sprintf, addr szbuf, offset $interm, eax, edx invoke messageboxa, 0, addr szbuf, offset _title, 0 invoke exitprocess, 0 main endp end main
in 16 bit mode, [sp]
not valid memory operand. following memory operands valid, each having optional displacement:
[bx] [bx+si] [bx+di] [bp] [bp+si] [bp+di] [si] [di] [addr16]
to fix code, recommend set stack frame , use bp
-relative addressing:
push bp ; establish stack frame mov bp,sp ; dito fstcw oldcw fwait mov ax,oldcw or ax,0c00h push ax fldcw [bp-2] ; load control word stack leave ; tear down stack frame
however, if in 32 bit mode, should refer esp
, 32 bit stack pointer instead. don't ever use 16 bit registers in memory operands unless in 16 bit mode or know doing:
fstcw oldcw fwait mov ax,oldcw or ax,0c00h push eax fldcw [esp] ; load control word stack pop eax ; restore stack
Comments
Post a Comment