Author Topic: nasm problems--not printing  (Read 15800 times)

AzAr

  • Guest
nasm problems--not printing
« on: October 19, 2008, 10:36:35 PM »
Hello,
I'm rather new to nasm, and wrote this program to print out a message byte-by-byte It's not printing, but it seems to run through the loop with gdb. Thoughts/comments would be great.
code:
section .data
buff db "Hello world!",0 ;the message we're going to print
section .text
global _start:
_start:
mov eax,buff ;moves the buffer address to eax for the call.
call write ;will write what ever is stored at eax byte by byet.
call exit ;exits

write:
mov esi,eax ;get what's stored in eax (hopefully an address) and store it in esi.
jmp .wloop
.wloop: ;the loop.
call pc
mov cl,[esi] ;moves the dereferenced esi to cl.
movzx ecx, byte [esi]
cmp cl,0 ;is the byte a null character?
je .wend
mov eax,4
mov ebx,1
mov edx,1
int 80h ;print the character.
inc esi ;move the pointer to the next char in the buffer.
jmp .wloop ;restart the loop
.wend:
ret

exit:
mov eax,1
mov ebx,1
int 80h
ret

pc:
mov eax,4
mov ebx,1
mov ecx,'d'
mov edx,1
int 80h
ret

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: nasm problems--not printing
« Reply #1 on: October 20, 2008, 01:50:52 AM »
You need the address of the buffer in ecx, not the character to print. Since the address of the buffer is in esi, doing "mov ecx, esi" somewhere before the "int 80h" should fix it.

Better(?) answer on the nasm-users list...

Best,
Frank