我有一个运行在VAX机器上的旧应用程序的RTL/2程序语言的源代码。不幸的是,我没有重新编译应用程序的可能性。我必须改变一些系数(实数,“连线代码”)
因此,我有一个想法:我可以直接修改可执行文件中的这些数字(一些.cm8文件,这些是大文件,所有行都以":“开头,然后是某种地址和HEX数据)。
不幸的是,如果我取其中一个系数(es 3.82619e-09)并以二进制形式表示,我得到:
es 3.8262619e-09 In binary is : 00110001100000110111100000101000 hex is: 0x31837828 hex in reverse endianess: 0x28788331但如果我在可执行文件中搜索那些HEX ..。我找不到火柴。如果我能在可执行文件中找到这些数字,我想直接修改它们。问题是,我认为,VAX机器没有使用IEEE 754标准的浮点。我找到了这个链接https://nssdc.gsfc.nasa.gov/nssdc/formats/VAXFloatingPoint.htm,它解释了vax机器上的浮点数据表示,但我不知道如何以VAX浮点数格式显示我的实数(我在源代码中直接找到的0.38262619E-08 )。
有什么帮助吗?
发布于 2022-03-31 19:30:40
这个答案假设浮点数据的格式是32位VAX F_floating格式。这与IEEE-754 binary32类似.一种标准化的二进制浮点格式,允许最重要的意义位(尾数)被假定为1而不是存储。两者都使用8位有偏指数.
binary32格式的意义范围为[1,2],而F_floating格式的意义和范围为[0.5,1]。binary32格式使用的指数偏差为127,而F_floating格式的指数偏差为128。结合起来,这意味着两种格式中相同的编码将以四倍的数值抵消。F_floating格式不支持带符号的零、子法线、无穷大和NaNs。
由于与16位PDP-11兼容,F_floating使用非直观的字节存储顺序.当按升序检查内存映像时,F_floating操作数的四个字节出现在顺序2、3、0、1中。
对于下面的ISO-C99程序,我假设代码是在使用IEEE-754浮点算法的系统上执行的。
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
#include <string.h>
#include <math.h>
uint32_t float_as_uint32 (float a)
{
uint32_t r;
memcpy (&r, &a, sizeof r);
return r;
}
/* Convert a IEEE-754 'binary32' operand into VAX F-float format, represented
by a sequence of four bytes in ascending address order. Underflow is handled
with a flush-to-zero response. Overflow is not handled!
*/
void float_to_vaxf (float a, uint8_t *b)
{
const float TWO_TO_M128 = 2.93873588e-39f; // 2**(-128)
const float SCAL = 4; // factor between IEEE-754 'binary32' and VAX F-float
const float ZERO = 0.0f; // canonical zero
uint32_t t;
// adjust for exponent bias and significant range
a = a * SCAL;
// no support for subnormals in VAX F_floating, flush to zero
if (fabsf (a) < TWO_TO_M128) a = ZERO;
t = float_as_uint32 (a);
// adjust to VAX F_floating byte ordering
b[0] = (uint8_t)(t >> 2 * CHAR_BIT);
b[1] = (uint8_t)(t >> 3 * CHAR_BIT);
b[2] = (uint8_t)(t >> 0 * CHAR_BIT);
b[3] = (uint8_t)(t >> 1 * CHAR_BIT);
}
int main (void)
{
float a = 3.8262619e-9f;
uint8_t vf[4];
float_to_vaxf (a, vf);
printf ("% 15.8e as VAX F-float bytes: 0x%02x,0x%02x,0x%02x,0x%02x\n",
a, vf[0], vf[1], vf[2], vf[3]);
return EXIT_SUCCESS;
}https://stackoverflow.com/questions/71689829
复制相似问题