Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Assembly x86 > Re: Question ab...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 6 Topic 4553 of 4729
Post > Topic >>

Re: Question about NASM

by Frank Kotler <spamtrap@[EMAIL PROTECTED] > Mar 2, 2008 at 09:56 AM

fetag wrote:
> hello, All:
> I have a little puzzle on NASM, I write a very simple case:
> [bits 32]
> segment	.text
> 	global	_start
> _start:
> 	mov	eax, 4
> 	mov	ebx, 2
> 	ret
> then, compiled it as:
> C:\ASM>nasm first.asm -o first.exe -l first.lst
> but, When I  disassembling the first.exe, I get the code like this:
> C:\ASM>ndisasm -b 32 first.exe
> 00000000  B8                 db 0xB8
> 00000001  0400              add al,0x0
> 00000003  0000              add [eax],al
> 00000005  BB02000000   mov ebx,0x2
> 0000000A  C3                 ret
> My question is: where the mov eax,0x4 in disassembly code? and where
> the two add statements come from? where the "00000000
> B8                 db 0xB8" come from?
> Thank you all!

Hi Fetag,

I can't duplicate this, either. Ndisasm will produce some very puzzling 
results if you don't "do it right", but I'd expect what you've done to 
work! I've used a *lot* of versions of nasm/ndisasm, and never seen it 
do *that*, exactly...

But I wonder what in hell you're trying to do! "start_", and "bits 32" 
look like maybe a Linux executable... But the command line you're giving 
Nasm will produce a flat binary. You can name the output file ".exe", 
but it won't be any known executable format. I mention that because some 
people start out with "nasm -o myfile.com myfile.asm" (which will work, 
since Nasm's default output format is "-f bin... in a "normal" build, 
this *can* be changed easily). Then they swap to "-o myfile.exe" or "-o 
myfile.obj", and don't add an "-f switch". Won't work - you just get a 
flat binary file named ".exe"!

"global" doesn't do anything in bin mode, so I'm confused. We *can* get 
an executable for Windows or Linux out of "-f bin" mode, but it requires 
an executable header stuck on the front. "_start" would be the default 
entrypoint for Linux, but it's jumped to, not called, so "ret" won't end 
cleanly. "ret" will work for a PE (I think), but you'd want to preserve 
ebx (and esi, edi, ebp... but you don't alter them in this code). 
Obviously not intended to be a "useful" executable, but I wonder what 
you're working towards...

None of that explains the weird behavior from ndisasm. I can produce 
exactly the results you show by adding "-s1" to ndisasm's command 
line... I doubt if you've done that...

Good puzzle! Hope you'll post the answer...

Best,
Frank

P.S. Anyone using "early 64-bit Nasm" should probably upgrade. 0.98.39 
was pretty stable, but there are known glitches in 0.99 through... well, 
we *think* 2.02 is okay..

http://nasm.sf.net
 




 6 Posts in Topic:
Question about NASM
fetag <spamtrap@[EMAI  2008-03-01 20:08:25 
Re: Question about NASM
Jack Klein <jackklein@  2008-03-01 23:29:00 
Re: [Clax86list] Question about NASM
Charles Crayne <spamt  2008-03-01 21:38:08 
Re: Question about NASM
Frank Kotler <spamtra  2008-03-02 09:56:08 
Re: Question about NASM
"H. Peter Anvin"  2008-03-03 11:05:20 
Re: Question about NASM
fetag <spamtrap@[EMAI  2008-03-03 16:40:55 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 21:02:04 CDT 2008.