gpt4 book ai didi

似乎无法找到数组中最大的 float ,使用内联汇编

转载 作者:太空宇宙 更新时间:2023-11-04 03:03:12 25 4
gpt4 key购买 nike

我的任务是做一些组装工作。一切都很顺利,直到我不得不将程序从使用 int 转换为 float。我可能在尝试中遗漏了一些简单的东西,但是有人有建议吗?我将提供有效的 int 版本。

#include <stdio.h>

int n;
int i;
int arr[50];
int output;

int main(void)
{
scanf("%d", &n);

for (i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}

__asm
{
jmp start

switching:
mov eax, ebx
jmp looping

looping:
mov ebx, arr[ecx*4]
inc ecx
cmp ebx, eax

jg switching

cmp ecx, n
jl looping
ret

start:
mov ecx, 0
mov eax, 0

call looping

mov output, eax
}

printf("%d", output);
scanf("%d", &n);
}

最佳答案

您将需要重写大部分解决方案。如果您不熟悉 float 并想使用 x87,here是很好的阅读指南。

要测试 float ,您需要像这样的条件跳转:

fld     <float to compare>
fcom <maximum value>
fnstsw ax
test ah,$1
jnz <notbigger>

关于似乎无法找到数组中最大的 float ,使用内联汇编,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9036656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com