如何解决无效的操作数错误?

问题描述

我的首要目标是用汇编语言制作一个计算器,但是我发现了很多以前从未想过的问题。

之前,Nasm无法以2个数字之间的比较来为“无效操作数”汇编我的程序。我解决了一些问题。

当前:我可以汇编并解压缩该程序,但控制台会显示“ -NaN”询问。

希望您可以解决此问题。

;--------------------------------------------------------------
; calculam.asm
; This program will check if a number is an INT or DOUBLE one.
; if INT it will convert to DOUBLE
; if DOUBLE it won't nothing,continue
; finally it will diplay the final DOUBLE number.
; -------------------------------------------------------------
; Assembly with GNU/Linux x80_86) & NASM compiler & GCC
; -------------------------------------------------------------
; 1) Compile:  nasm -f elf64 calculam.asm
; 2) Link: gcc -no-pie calculam.o -o calculam
; 3) Run:./calculam
; ------------------------------------------------------------

bits 64
extern printf

section .data
    a: dq 28.33
    fmt: db "Result is: %g",10,0

section .bss
    op1: resq 1

section .text
    global main

main:
    push rbp

.rounding:
    movsd       xmm1,qword [a]     ; load a on xmm1
    roundsd     xmm2,xmm1,3       ; truncates xmm1 and loading to xmm2
     
        ; Extract of http://www.ray.masmcode.com/tutorial/fpuchap7.htm#ficom
        ; (i adapted to this program):

    fcom  qword[a]    ;compare ST(0) with the value of the real8_var variable
    fstsw ax          ;copy the Status Word containing the result to AX
    fwait             ;insure the prevIoUs instruction is completed
    sahf              ;transfer the condition codes to the cpu's flag register

        ;jpe error_handler ;the comparison was indeterminate
        ;                  ;this condition should be verified first
        ;                  ;then only two of the next three conditional jumps
        ;                  ;should become necessary,in whatever order is preferred,;                  ;the third jump being replaced by code to handle that case
        ;ja    st0_greater ;when all flags are 0
        ;jb    st0_lower   ;only the C0 bit (CF flag) would be set if no error
        ;jz    both_equal  ;only the C3 bit (ZF flag) would be set if no error

    ja      .display
    jb      .display

    fild dword [a]  ; If both are equal xmm1=integer so we need to do it double

.display:
    fstp        qword [op1]         
    mov         rdi,fmt                
    movsd       xmm0,qword [op1]   
    mov         rax,1                 
    call        printf            
    
    pop rbp
       
.exit:  mov rax,0
    ret

谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)