Segmentation Fault when using "mov" in Assembly
Posted
by
quithakay207
on Stack Overflow
See other posts from Stack Overflow
or by quithakay207
Published on 2013-11-08T23:30:50Z
Indexed on
2013/11/09
3:55 UTC
Read the original article
Hit count: 330
I am working on a simple assembly program for a class, and am encountering an odd segmentation fault. It's a pretty simple program to convert bytes into kilobytes. However, within the function that does the conversion, I get a segmentation fault when I try to move the value 1024 into the ebx
register. I've never had this kind of problem before when working with registers. Does someone know what could be causing this? I imagine it is something simple that I'm overlooking. Thank you!
asm_main:
enter 0,0
pusha
mov eax, 0
mov ebx, 0
call read_int
push eax
call functionA
popa
mov
leave
ret
functionA:
mov eax, [esp + 4]
call print_int
call print_nl
mov ebx, 1024 ;segmentation fault occurs here
div ebx
call print_int
ret
UPDATE: One interesting discovery is that if I delete the lines interacting with the stack, push eax
and mov eax, [esp + 4]
, there is no longer a segmentation fault. However, I get a crazy result in eax
after performing div ebx
.
© Stack Overflow or respective owner