按位的NodeJS运营商从C ASM [英] NodeJS bitwise operator from C ASM

查看:199
本文介绍了按位的NodeJS运营商从C ASM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这关系到我的previews <一个href=\"http://stackoverflow.com/questions/22766731/inc-al-is-not-incrementing-by-1/22766768\">question.

函数的C中的一个完整的ASM是这里

我的问题就在于:

  00408091 |&GT; F6D3 ||不BL
00408093 |。 FEC3 || INC BL
00408095 |。 02D3 || ADD DL,BL

在JavaScript的,当我使用NOT位运算符的 0x35 返回 -36 而不是预期的 0xCA 。这是为什么?

  // CMP人,DL
  如果(b将=一){
    一个 - = B;
  }其他{
    //问题就在这里
    的console.log(〜B);
    A + = B;
    一个++;
  }

我的NodeJS code目前:

 为(VAR I = 0; I&LT; hashed.length;我++){
  VAR一个=散列[I]
  变种B = seqX [I]
  变种C = seqX [I + 1];  变种斯捷平= 1 + 1;
  VAR步距=斯捷平-1;  // CMP BL,DL - 0x63,0x4e - 0xf9,0xc5 - 0x75。 0x7a
  为(VAR J = internalRounds - 1; J&大于0; j--,stepIn--,stepOver--){
    如果(seqX [(我* 2)+1]下; =一){
      一个 - = seqX [(我* 2)+1];
    }其他{
      A + = seqX [(我* 2)+1];
      一个++
    }
    // XOR DL,BL - 为0x1C,将0xC0
    一个^ = seqY [斯捷平]
  }  // CMP人,DL
  如果(b将=一){
    一个 - = B;
  }其他{
    //问题就在这里
    的console.log(〜B);
    A + = B;
    一个++;
  }  //异人,DL --- 0xd4,0xb8
  一个^ = seqY [I]  //异人,CL
  一个^ = 0x6e;  的console.log(a.toString(16)); //我期望这是2。
  的console.log('--------------------------');
}


解决方案

指令顺序如下:

  00408091 |&GT; F6D3 ||不BL
00408093 |。 FEC3 || INC BL
00408095 |。 02D3 || ADD DL,BL

时的处理在 BL DL 作为签名值,基本上减去 BL字节 DL 。前两个走2的 BL的补码为一个字节,那么第三个加否定 BL DL 。除非是处理一定的方式与处理器状态标志后面的指令,我不知道为什么它不只是说, SUB DL,BL

所以,我觉得这组指令只会翻译成:

  B  -  =一;

而不是逐字翻译每一条指令。

这一定程度上取决于整个ASM程序,如何 BL DL 被处理的情况下。如果它们被作为字节值consistentlyt治疗,那么上面应该工作。

This is related to my previews question.

A complete ASM of the function in C is here.

My problem lies on:

00408091  |>  F6D3          ||NOT BL
00408093  |.  FEC3          ||INC BL
00408095  |.  02D3          ||ADD DL,BL

On javascript when I use the NOT bitwise operator on 0x35 it returns -36 instead of the expected 0xCA. Why is that?

  // cmp al, dl
  if (b <= a) {
    a -= b;
  } else {
    // problem lies here
    console.log(~b);
    a += b;
    a++;
  }

My nodejs code currently is:

for (var i = 0; i < hashed.length; i++) {
  var a = hashed[i];
  var b = seqX[i];
  var c = seqX[i+1];

  var stepIn = i+1;
  var stepOver = stepIn-1;

  // cmp BL, DL -- 0x63, 0x4e -- 0xf9, 0xc5 -- 0x75. 0x7a
  for (var j = internalRounds - 1; j > 0; j--, stepIn--, stepOver--) {
    if (seqX[(i*2)+1] <= a) {
      a -= seqX[(i*2)+1];
    } else {
      a += seqX[(i*2)+1];
      a++
    }
    // xor dl, bl -- 0x1c, 0xc0
    a ^= seqY[stepIn];
  }

  // cmp al, dl
  if (b <= a) {
    a -= b;
  } else {
    // problem lies here
    console.log(~b);
    a += b;
    a++;
  }

  // xor al, dl --- 0xd4, 0xb8
  a ^= seqY[i];

  // xor al, cl
  a ^= 0x6e;

  console.log(a.toString(16)); // I expect this to be 2.
  console.log('--------------------------');
}

解决方案

The following sequence of instructions:

00408091  |>  F6D3          ||NOT BL
00408093  |.  FEC3          ||INC BL
00408095  |.  02D3          ||ADD DL,BL

Is treating the bytes in BL and DL as signed values and essentially subtracting BL from DL. The first two take the 2's complement negation of BL as a byte, then the third adds the negated BL to DL. Unless there are subsequent instructions that deal a certain way with the processor status flags, I'm not sure why it doesn't just say, SUB DL,BL.

So I would think this group of instructions would just translate into:

b -= a;

Rather than literally translating each instruction.

This depends somewhat on the context of the whole asm program, how BL and DL are treated. If they are treated as byte values consistentlyt, then the above should work.

这篇关于按位的NodeJS运营商从C ASM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆