我正在尝试将几个像素添加在一起,以便在 NASM 中进行模糊过滤。我成功添加了三个像素,其值为 00 + d3 + d8 (0 + 211 + 216)。当我尝试再添加一个值为 0 的像素时,程序无法打印变量 blurr 的值。
更新:
似乎添加到变量 sum 最多可以完成三次,因为如果我注释掉另一个 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 中找到。
目前,我非常困惑为什么在我的 sum 中添加 0 会破坏程序,尤其是当我已经在上面的代码中完成此操作时。
最佳
塞布
最佳答案
我有一个想法 - 我不确定它是否正确:
在你的程序中你调用了“open”两次。有一次你注释掉了 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
的地址偶然是“open”系统调用的有效参数,而在插入指令后,该地址就不是不再是“open”的有效参数。
您可以通过使用 strace
工具运行程序的两个变体来测试这一点,该工具会显示使用 wich 参数调用了哪些系统调用。
关于linux - NASM 为注册 bug 增加值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45999476/