assembly 从main .asm调用conversion.asm中的过程

wa7juj8i  于 2022-12-29  发布在  其他
关注(0)|答案(1)|浏览(129)

我有两个asm文件,一个是conversion.asm,另一个是main.asm,我在main.asm中使用conversion.asm。我使用浮点堆栈,但没有得到正确的输出。
main.asm

Include conversion.asm

.386
.stack 4096

ExitProcess PROTO, dwExitCode:DWORD

.data
Cel DD 25
Faren DD ?

.code
main PROC
  push dword ptr Cel
  fld dword ptr [esp]

  call C2F

  fstp dword ptr [Faren]
  mov ebx, [Faren]
  INVOKE ExitProcess, ebx
main ENDP
END main

conversion.asm

.model flat, stdcall

ExitProcess PROTO, dwExitCode:DWORD
.stack 4096

.data 
Cfirst DD 2
Csecond DD 1
common DD 32

C2F PROC
    push dword ptr Cfirst
    fld dword ptr [esp]
    add esp,4
    fmulp
    sub esp,4
    push dword ptr Csecond
    fld dword ptr [esp]
    add esp,4
    fdivp
    sub esp,4
    push dword ptr common
    fld dword ptr [esp]
    add esp,4
    faddp
    sub esp,4
    RET
C2F ENDP

请你帮帮我

xqk2d5yq

xqk2d5yq1#

fmul、fdiv、fadd直接在浮动堆栈中编辑数据,因此直接在浮动堆栈中执行操作,而不是从堆栈拉到寄存器。
conversion.asm中浮点堆栈的正确用法:

.DATA
five DWORD 5.0
nine DWORD 9.0
ttw DWORD 32.0

.CODE
C2F proc
    fmul nine
    fdiv five
    fadd ttw
    ret
C2F ENDP

对于阅读和写入浮点数,我使用了Irvine库,它使用浮点堆栈:

Include Irvine32.inc
Include conversion.asm

.data
Celprompt BYTE "Enter a value in C:",0
Cel DWORD 0
Resprompt BYTE "In Farenheit that value is - "
Faren DD ?

.code
main PROC
  mov edx, OFFSET Celprompt
  call WriteString
  call Crlf
  call ReadFloat
  call C2F
  call Crlf
  mov edx, OFFSET Resprompt
  call WriteString
  call WriteFloat
main ENDP
END main

相关问题