x86: EAX contains value of 1 but cmp eax, 1 gives false

283 Views Asked by At

I have such part of code

cmp eax, [SPHERE]
je VolumeSphere

I use the variable SPHERE and it's like enum for 1. Also, I check what is in eax and it 1 too(by printf). So, I have changed the code to this and it's giving me false too(je didn't work and jne work):

cmp eax, 1
je VolumeSphere

Eax must contain 1, coz it definitely points to place in memory, where I write/read from file value 1. But in this situation comparison is false.

So, I start debugging with gdb. More detailed code:

mov [cont], rdi                       ; I saving address of array / rdi contains 4211776
mov [len], rsi                        ; Length of array

mov r9, 0                             ; It will be counter for calling cont[r9]
mov rsi, 0
mov rdi, 0                            ; each elem of struc takes 20 bytes
lea rsi, [r9 + r9*4]
lea rdi, [cont + rsi*4]               ; rdi contains 4412024
call ....

into method

mov eax, [rdi]                        ;rdi must contains beginning of cont[r9](cont[0])
cmp eax, 1                            ; rdi and eax contains 4211776
je VolumeSphere                       ; after cmp PF IF RF change to PF AF IF RF

if I try to check eax by gdb it writes:

p $eax
    $1 = 4211776
x/s 0x404440
    0x404440 <cont>: "\001"
x/s 4211776
    0x404440 <cont>: "\001"

Even if I try to compare eax with 001 or 4211776 its gives false.

And this is all I do in my code after getting into it. All registers are copied and get 0. I didn't have any idea why it can have such behavior. I really need help, so if I can find more information in code/gdb, say what u need.

I post full code in the cloud. The same part of code I use in output.asm(117), inrnd.asm(133), input.asm(131).

0

There are 0 best solutions below