LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 12-05-2010, 12:51 AM   #1
rblampain
Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 7
Posts: 833

Rep: Reputation: 35
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"
notdeadyet
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 12:54 AM.
 
Old 12-05-2010, 02:00 AM   #2
paulsm4
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:
Code:
http://stackoverflow.com/questions/2...-explain-the-a

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

.data
hellostr:
    .ascii "hello world\n";
helloend:

.text
.globl _start

_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

    ret
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 02:04 AM.
 
Old 12-05-2010, 08:17 AM   #3
rblampain
Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 7
Posts: 833

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


Reply


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 01:40 PM
facing problem in kernel debugging(not able to find source code) through lauterbach vrsonu Linux - Mobile 0 04-14-2009 05:34 AM
NASM bootable code problem vargadanis Programming 1 01-11-2008 06:18 PM
linux debugging without source code Newbie123 Programming 2 03-10-2002 01:12 PM
debugging without source code Newbie123 Linux - Newbie 3 03-10-2002 12:10 PM


All times are GMT -5. The time now is 07:25 AM.

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