flat assembler
Message board for the users of flat assembler.

Index > Linux > Why is there no output ?

Author
Thread Post new topic Reply to topic
Adnarim



Joined: 02 Jan 2007
Posts: 8
Adnarim 03 Jan 2007, 21:29
Hi,
I want to make a loop and wanna print the loopcount on the screen but nothing happens. I debugged the code and see that after the write call, eax is filled with 0xFFFFFF2 which seems to be an error code or?

This is my code:
Code:
section .text
        global _start

_start:
        
        mov ecx,0
label1: inc ecx
        cmp ecx,5
        jne label1
        mov eax,4          
        mov ebx,1  
        mov edx,5  
        int 80h              
        mov eax,1           
        mov ebx,0            
        int 80h
    

You see a 5 should appear but it doesn't. What is the problem?
Post 03 Jan 2007, 21:29
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 03 Jan 2007, 21:54
According to Arafel's system calls reference
Quote:
sys_write [fs/read_write.c]

Writes number of bytes to a device (file, socket, etc.) while advancing the file offset position accordingly.

Arguments

eax 4
ebx Device descriptor.
ecx Pointer to the buffer containing the data to be written.
edx Number of bytes to be written.


So you are requesting to the kernel to write five characters at address 0x00000005 to device 1 (stdout)
Post 03 Jan 2007, 21:54
View user's profile Send private message Reply with quote
Adnarim



Joined: 02 Jan 2007
Posts: 8
Adnarim 04 Jan 2007, 15:12
Hey thanks,
I changed the code this way and it works:
Code:
section .text
        global _start

_start:
        mov esi,0
label1: inc esi
        cmp esi,5
        jne label1
        add esi,48
        mov eax,4          
        mov ebx,1
        push esi
        mov ecx,esp       
        mov edx,4
        int 80h              
        mov eax,1           
        mov ebx,0            
        int 80h
    


But two questions remain: Is there a better or let's say a more general way to convert integer 5 to Char 5 instead of adding 48?

And the other thing is how can I add a newline character to this? So after add esi,48 I have dec 53 = char 5 in esi but how can I add now an newline charachter to this, so that when I print it a newline is shown after that? I know that the dec code is 10 and hex code of the newline feed is A, but how do I use this now?

greets
Post 04 Jan 2007, 15:12
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.