X86 32 Bit Assembly question?

Use the call instruction instead of je to get into write . Ret expects the return address to be on the stack, but it won't get pushed if you use a jump to get there! You're going to have to put esp back to whatever it was when you entered the function, too.

Here's a best-guess example based on your code.

Up vote 4 down vote favorite share g+ share fb share tw.

I am currently in the process of learning assembly and I was playing around with if statements. My current code is as follows. Write: mov eax, 0x4 sub esp, 4 int 0x80 main: ; The message has already been pushed to the stack mov eax, 4 inc eax cmp eax, 5 je write If I put the ret at the end of write: then I get a bus error 10 and if I do not I get an infinite loop resulting in a segmentation error.

What should I do to make this work? Assembly x86 32bit intel osx link|improve this question asked Aug 26 '11 at 21:36Jjack42318 80% accept rate.

Use the call instruction instead of je to get into write. Ret expects the return address to be on the stack, but it won't get pushed if you use a jump to get there! You're going to have to put esp back to whatever it was when you entered the function, too.

Here's a best-guess example based on your code: write: mov eax, 0x4 sub esp, 4 int 0x80 add esp, 4 ret main: ; The message has already been pushed to the stack mov eax, 4 inc eax cmp eax, 5 jne dontwrite ; skip calling 'write' if eax! = 5 call write dontwrite: ; the rest of the program goes here.

I am still getting a bus error 10. – Jjack Aug 26 '11 at 22:31 @Jjack where do you get the error - your question doesn't provide enough information to give you much more help. – Carl Norum Aug 26 '11 at 22:34 after it prints one message.

– Jjack Aug 26 '11 at 22:40 I mean after it calls the function once. – Jjack Aug 26 '11 at 23:05 I figured out that if I clear the whole stack, it works but then I get a segmentation fault... – Jjack Aug 26 '117 at 2:45.

Try this instead. No need to call a procedure in your example. Main: ; The message has already been pushed to the stack mov eax, 4 inc eax cmp eax, 5 jne dontwrite ; Skip Write ; Write mov eax, 0x4 sub esp, 4 int 0x80 dontwrite: ; the rest of the program goes here.

I'm not real familiar with interrupts, but I can't see any reason you're subtracting 4 from esp (which is the stack pointer). If you're getting seg faults I would think that would be causing it. Try commenting out that line if it's not important in some way.

– Sparafusile Aug 30 '11 at 13:36.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions