NASM增加了注册bug的价值

我试图添加几个像素在一起,以便在NASM中做一个模糊的filter。 我已经设法添加三个像素的值为00 + d3 + d8(0 + 211 + 216)。 当我尝试添加一个像素,值为0时,程序无法打印可变模糊的值。

更新:
似乎添加到variables总和可以在最多三次完成,因为如果我注释掉另一个add ,值将被打印在我的输出文件。

 blurrTopRow: ;from 0 - 251 there will be no pixels above the active pixel ;set ah to 0 to be sure that no other values changes the byte ;save byte in al, ax should be [0000](ah) value(al) mov ah, byte 0 mov al, byte [info + 0] ;store sum all pixels in sum, divition will be done here add [sum], ax ;add pixel beside it (1) ;mov ah, byte 0 mov al, byte [info + 1] ;add the value to sum ;add [sum], ax If i add this value, the program stops working ;add the pixels below the first pixel ;move data to the first 8-bits mov ah, 0 mov al, byte [info + 251] add [sum], ax ;set the last 8-bits in the 16-bit register (ax) to 0 ;to avoid messing up the value mov ah, 0 mov al, byte [info + 252] add [sum], ax ;devide the digit with 4 mov eax, 0 mov ax, [sum] mov ebp, 4 mov edx, 0 idiv ebp mov [blurr], al ret 

我相信这是由于一些字节错误或有效的处理,我还不明白。 如果你想看到我所有的代码,你可以在pastebin中find它

目前,我感到非常困惑,为什么在我的总和中添加0会破坏程序,特别是当我已经在上面的代码中完成了这个操作。

最好
勒布

我有一个想法 – 我不知道这是否是正确的:

在你的程序中,你打电话“打开”两次。 有一次你注意到了mov ecx, ... ; 另一次ecx寄存器从来没有被设置:

 openFileIn: mov eax, 5 mov ebx, fileName ; <-- Here you are trusting Linux that ecx=0 on program start ; This is not guaranteed; ; it may change in future Linux versions! mov edx, 0777 int 0x80 mov [fd_in], eax ret openFileOut: mov eax, 5 mov ebx, outName ;mov ecx, 1 <-- why did you comment this out? ; Maybe "1" is not the correct value! mov edx, 0777 int 0x80 

在另一行中,你写一些地址给ecx寄存器:

 readFromFileIn: mov eax, 3 mov ebx, [fd_in] mov ecx, info ; <-- Here mov edx, IMAGE_SIZE int 0x80 ret 

向代码添加说明时,程序中元素的地址可能会更改 – 包括info的地址。

我怀疑没有额外的指令, info的地址偶然是“打开”系统调用的有效参数,而在插入指令后,地址不再是“打开”的有效参数。

你可以用strace工具运行程序的两个变种来测试这个,它显示哪个系统调用被调用了最好的参数。