Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-05-2010, 01:51 AM   #1
Senior Member
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 9.2
Posts: 1,065

Rep: Reputation: 48
debugging nasm source code

I found on the Internet a rough suggestion to debug code which says to add a line:
%define notdeadyet sys_write STDOUT,0,__LINE__
"and then, you can litter your code with"
An example shows this lists the lines of source that do work.

I do not know where these lines are supposed to go and whether the "notdeadyet" should be a call to a subroutine or what. I only found that "%define" is used to link to external files, so I am confused because what I tried did not work.

(I am unable to use (and learn) any debugging tool for another few weeks and I'd like to progress on this If I can.)

Can anyone point me in the right direction, this is learning nasm64 on AMD64 at the same time.

Thank you for your help.

Last edited by rblampain; 12-05-2010 at 01:54 AM.
Old 12-05-2010, 03:00 AM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

As I'm sure you've guessed, the "define" is just a macro (exactly like C/C++ "#define"), and "sys_write" is the actual call.

I confess, however, I'm not at all familiar with "%define" per se. And I vastly prefer "as" syntax to Intel/Masm syntax (for many, many reasons; I won't bore you with them here ).

In ANY case: here's an example that should completely answer your question:

#include <asm/unistd.h>
#include <syscall.h>
#define STDOUT 1

    .ascii "hello world\n";

.globl _start

    movl $(SYS_write) , %eax  //ssize_t write(int fd, const void *buf, size_t count);
    movl $(STDOUT) , %ebx
    movl $hellostr , %ecx
    movl $(helloend-hellostr) , %edx
    int $0x80

    movl $(SYS_exit), %eax //void _exit(int status);
    xorl %ebx, %ebx
    int $0x80

Note the explicit call to "SYS_write" (whose prototype is defined in "syscall.h"), and the macro definition ("#define") for STDOUT (file #1).

'Hope that helps!

Last edited by paulsm4; 12-05-2010 at 03:04 AM.
Old 12-05-2010, 09:17 AM   #3
Senior Member
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 9.2
Posts: 1,065

Original Poster
Rep: Reputation: 48
Thank you for your answer but I have no knowledge of C or C++ whatsoever.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Open Source rocks, learning from code by debugging LXer Syndicated Linux News 0 05-13-2009 02:40 PM
facing problem in kernel debugging(not able to find source code) through lauterbach vrsonu Linux - Mobile 0 04-14-2009 06:34 AM
NASM bootable code problem vargadanis Programming 1 01-11-2008 07:18 PM
linux debugging without source code Newbie123 Programming 2 03-10-2002 02:12 PM
debugging without source code Newbie123 Linux - Newbie 3 03-10-2002 01:10 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:59 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration