Tyler Littlefield wrote: > I'm not guessing. > I'm using nasm, but the gcc output is totally different from anything I > understand. > > Thanks, > Tyler Littlefield > email: [EMAIL PROTECTED] > web: tysdomain-com > Visit for quality software and web design. > skype: st8amnd2005 > > ----- Original Message ----- > From: Thomas Hruska > To: [email protected] > Sent: Sunday, October 19, 2008 2:06 PM > Subject: Re: [c-prog] asm help--not sure where the error is > > > Tyler Littlefield wrote: > > I'm rather new to asm, and started playing around. > > The purpose of write is to write the string char by char. any ideas why > this > > wouldn't be working? I'm not totally sure how to debug it. it just runs > and > > stopps--I finally got past the seg fault: > > section .data > > buff db "Hello world!",10,0 > > section .text > > global _start: > > _start: > > mov eax,buff > > call write > > call exit > > hlt > > > > write: > > mov esi,eax > > ;we'll get the other three registers set up so we don't have to keep > setting > > those: > > mov eax,4 > > mov ebx,1 > > mov edx,1 > > loop: > > mov ecx,[esi] > > cmp ecx,0 > > je end > > inc esi > > int 80h > > jmp loop > > end: > > ret > > > > exit: > > mov eax,1 > > mov ebx,1 > > int 80h > > ret > > > > Thanks, > > Tyler Littlefield > > email: [EMAIL PROTECTED] > > web: tysdomain-com > > Visit for quality software and web design. > > skype: st8amnd2005 > > Instead of guessing, why don't you first write the program in C and then > use the compiler to generate raw assembler code (most compilers have a > switch to do this). Then stare at the generated code, compare to yours, > and that should solve the problem. > > Besides, every compiler treats assembler differently. You didn't > mention yours.
But you ARE guessing. A quick search on Google for sample code turns up: http://snippets.dzone.com/posts/show/3949 I happen to know quite a bit of x86 assembler and this statement: > > mov ecx,[esi] > > cmp ecx,0 Is wrong. You are moving a dword from the target at a time into ecx (e.g. the equivalent of 'Hell' as the value on 32-bit hardware). Then the interrupt is treating that as the _address_ of the data to write out. In other words, you are simply lucky the app. isn't crashing. You don't want the _value_ at that point but the address: mov ecx,esi cmp byte ptr [esi], 0 Or something like that. As I said, you are guessing. gcc uses AT&T-style assembler. NASM uses Intel-style assembler. For experimenting, you should stick with the one that comes with your compiler until you know enough assembler to go off adventuring on your own to use an independent assembler like NASM. But if you are having problems with NASM, this is NOT the list to ask for help. Go find a NASM list. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/
