Strange segmentation error in assembly

I wrote the hexdump utility in assembly language using the nasm compiler and the ld linker. The program should download the hexadecimal values ​​for any input file. However, this may be due to one specific “LoadBuff” procedure. Function loadbuff - read the input to the buffer of 16 bytes. The code

LoadBuff:
    push ebx                 
    push edx
    push eax

    mov eax,3       ;sys_read call      
    mov ebx,0               ;read from standard input
    mov ecx,Buff            ;pass the buffer adress
    mov edx,BuffLen         ;pass the number of bytes to be read at a time
    int 80h                 ;call the linux kernel
    mov ebp,eax
    ;cmp eax,0              ;number of characters read is returned in eax
    ;jz exit                ;if zero character is returned i.e end of iinput file      
                            ;jump to exit

    xor ecx,ecx 
    pop eax
    pop edx
    pop ebx
    ret

If the lines

;cmp eax,0                   
;jz exit                      

without commenting, the code works fine, without any seg error. However, when I comment on it and include these lines in the caller to perform the same comparison in the caller, and not here, this procedure causes seg errors.

gdb backtrace gives

#0  0x00000000 in ?? ()

Any idea why this is happening?

+5
source share
1 answer

NASM, , Intel AT & T-style. , , , Intel.

Intel mov :

mov <destination>, <source>

, , "destination = source". AT & T :

mov <source>, <destination>

, , " ".

:

mov ebp, eax

Intel ( , , AT & T-style mov %ebp, %eax), eax ebp. ebp " "... , "" ... . 0 eax, . .


. :

jz exit

, , SOMEWHERE ( ) . , . , .

, . ebx, edx eax. (eax, edx ebx). , , , , .

, jz , , , , . , .

, . ( ) , , .

+1

All Articles