I'm doing a class in assembly that is called from a class in C. The C class sends 2 integers as parameters but that's not relevant cause I'm getting a segmentation fault error that I don't seem to quite understand why.
Here's the relevant part of the assembly class:
.global testingclass testingclass:
pushl %ebp
movl %esp, %ebp
subl $4, %esp #reserves space for local variable
movl 8(%ebp), %ebx #first argument of the function to %ebx
movl 12(%ebp), %ecx #second argument of the function to %ecx
function:
movl $0, %eax ----------------< segmentation fault
movl 0x0000FFFF, %eax
and %bx, %ax
movw %ax, -4(%ebp)
...
I signed the line that gives me the segmentation fault error when debugging. I really don't know how can a simple move command trigger a segmentation fault, but hope you can help me.
This is the debugger console output:
...
11 movl 12(%ebp), %ecx #second argument of the function to %ecx
(gdb) n
function() at asm.s:16
16 movl 0x0000FFFF, %eax
(gdb) n
Program received signal SIGSEGV, Segmentation fault.
function() at asm.s:16
16 movl 0x0000FFFF, %eax
the seg fault occurred at this instruction:
movl 0x0000FFFF, %eax
Not at this instruction:
movl $0, %eax
The reason for the seg fault is reading from address (64k-1)
The program can only read/write addresses that are available to the user space.
Since the OS is first, after the interrupt vectors, the code tried to read an address within the OS code. The OS code is not part of the user space.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.