标签: cmp

x86"cmp"指令的奇怪行为

这是代码:

#include <iostream>
#include <time.h>

using namespace std;

#define ARR_LENGTH 1000000
#define TEST_NUM 0
typedef unsigned int uint;

uint arr[ARR_LENGTH];

uint inc_time(uint x) {
    uint y = 0, tm = clock();
    for (uint i = 0; i < x; i++) y++;
        return clock() - tm;
}

int main() {
    uint div = 0, mod = 0, tm = 0, overall = 0, inc_tm;
    srand(time(NULL));
    for (uint i = 0; i < ARR_LENGTH; i++) arr[i] = (uint)rand() + 2;

    tm = …
Run Code Online (Sandbox Code Playgroud)

architecture performance x86 assembly cmp

2
推荐指数
1
解决办法
598
查看次数

如何比较 (os x) bash 脚本中的 2 个(图像)文件,忽略最后更改/修改的日期标头?

我想递归比较目录中的屏幕截图文件。我尝试使用cmp,但它总是返回差异 - 即使图像在视觉上没有不同 - 我猜文件中的差异一定是 和last changed日期last modified

有没有办法我只能比较图像文件的像素内容而忽略这些标题?

unix macos bash cmp

2
推荐指数
1
解决办法
4116
查看次数

比较二进制文件并仅打印匹配行的偏移量

对于常规文件,我可以使用 comm命令来查找公共行。

例如我们有两个文件

$ cat f1
line1
line2
line3
line4
line5

$ cat f2
line1
line20
line30
line4
line5
Run Code Online (Sandbox Code Playgroud)

它比较像:

$ comm -12 f1 f2
line1
line4
line5
Run Code Online (Sandbox Code Playgroud)

如何找到匹配行的偏移量以及如何对两个二进制文件进行比较并打印匹配行偏移量?

我一直在使用诸如diff, cmp,comm过去1小时,摸不清头脑。

编辑 1:不是确切的解决方案,但发现 vbindiff 有帮助。

linux diff binaryfiles cmp comm

2
推荐指数
1
解决办法
3101
查看次数

比较程序集中的整数值

我们的任务是比较整数值并打印出适当的提示以显示哪些值更大.

我在下面的代码分别将'i'和'j'初始化为5和4.目标是比较"变量"而不是直接值本身.所以在这个例子中,我把'i'和'j'放在cmp中,而不是5和4.

global _main
extern _printf, _system 

section .text


_main:
; clear screen
    push clr
    call _system
    add esp, 4

;Test prints out i. Successfully does the job.
    push dword [i]          ; why did it work here and not in *cmp*?
    push prompt2
    call _printf      
    add esp, 8

;compare values and do a conditional jump.
    CMP dword [i], dword [j]            ; compares values stored in i and j. i and j are base 10 nums. This is where …
Run Code Online (Sandbox Code Playgroud)

assembly integer compare intel cmp

2
推荐指数
1
解决办法
2363
查看次数

bisect和用户定义对象列表(python 3)

在python 3之前,我使用bisect将用户定义的对象插入到列表中.bisect对此很满意,因为我的用户定义对象有一个__cmp__定义如何比较对象的def .我已经阅读了在python 3中不支持cmp的理由,我对此很好.我认为我的旧代码的修复方法是通过将其转换为元组来"装饰"我的用户定义对象

(integer, user-defined object).
Run Code Online (Sandbox Code Playgroud)

但是,如果我有一个我的元组列表,并尝试...

i = bisect_left([list_of_tuples], (integer, user-defined object))
Run Code Online (Sandbox Code Playgroud)

然后我收到错误"builtins.TypeError:unorderable types ..."

那么,(在python 3中)我如何使用bisect作为完全不具有自然排序顺序的项目列表?

python cmp bisect python-3.x

1
推荐指数
1
解决办法
1288
查看次数

cmp je/jg他们如何在装配中工作

我想了解cmp和je/jg如何在汇编中工作.我在谷歌上看到了一些例子,但我仍然有点困惑.下面我展示了我试图转换为C语言和相应C代码的汇编代码的一部分.它是以正确的方式实现还是我对cmp如何工作有错误的理解?

cmp    $0x3,%eax
je     A
cmp    $0x3,%eax
jg     B
cmp    $0x1,%eax
je     C


 int func(int x){


  if(x == 3)
    goto A;

  if (x >3)
    goto B;


  if(x == 1)
     goto C;

    A:
    ......

    B:
    ......

    C:
    ......
Run Code Online (Sandbox Code Playgroud)

c x86 assembly cmp conditional-statements

1
推荐指数
1
解决办法
2万
查看次数

将排序从 Python2 转换为 Python3

我已经用Python2编写了一个排序,我试图将其转换为Python3,它要求提供一个密钥并表示没有更多的cmp函数可用:

test.sort(lambda x, y: cmp(x[2],y[2]) or cmp(x[4], y[4]) or cmp(y[9], x[9]))
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

此致,

python sorting cmp python-3.x

1
推荐指数
1
解决办法
1562
查看次数

使用带有输出重定向的cmp,bash shell脚本无法正常工作

我正在尝试编写一个bash脚本,从文件夹中删除重复的文件,只保留一个副本.该脚本如下:

#!/bin/sh

for f1 in `find ./ -name "*.txt"`
do
    if test -f $f1
    then
        for f2 in `find ./ -name "*.txt"`
        do
            if [ -f $f2 ] && [ "$f1" != "$f2" ]
            then
                # if cmp $f1 $f2 &> /dev/null # DOES NOT WORK
                if cmp $f1 $f2
                then
                    rm $f2
                    echo "$f2 purged"
                fi 
            fi
        done
    fi 
done 
Run Code Online (Sandbox Code Playgroud)

我想重定向输出和stderr以/dev/null避免将它们打印到屏幕..但使用注释语句此脚本不能按预期工作并删除所有文件,但第一个..

如果需要,我会提供更多信息.

谢谢

bash cmp stderr io-redirection output

0
推荐指数
1
解决办法
1395
查看次数

这个语句在汇编中意味着什么?

ptr当处理翻译以下代码段时,有人可以告诉我在那里的目的吗?

cmp byte ptr [eax], 0
Run Code Online (Sandbox Code Playgroud)

ptr 是一个标签,它的值是:

(++>
Run Code Online (Sandbox Code Playgroud)

我的理解cmp是,它将左侧的值与右侧的值进行比较。

涉及到第三个参数(ptr),这是什么意思?是与ptr中的内存地址值进行 AND比较吗?eax0

如果有人可以帮我把它翻译成英文,那就太好了。谢谢。

x86 assembly cmp

0
推荐指数
1
解决办法
3375
查看次数