Thread: asm asciz question

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    69

    asm asciz question

    Bellow is the example that I am going to use.


    The bellow code should compile on GNU assembler. Syntax is AT&T incase any numbies are curious.
    Code:
    .data 
    
    
    HelloWorldString:
    	.asciz "Hello"
    
    
    .text 
    
    
    .globl _start 
    
    
    _start:
    	# Load all the arguments for write () 
    
    
    	movl $4, %eax
    	movl $1, %ebx
    	movl $HelloWorldString, %ecx
    	movl $6, %edx #<-- This is where the number matters.
    	int $0x80
    
    
    	# Irrelivant. Just the exit syscall
    	movl $1, %eax
    	movl $0, %ebx
    	int $0x80
    Okay, I am using the write syscall. Did I do it correctly? Would I have to allocate 6 bytes of space(like I did), instead of just five? Because of the NUL? Thanks.

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    It's not C, there is no need for the string to be null terminated, nor to send a null character at the end of the string (in fact, it's probably wrong to do so)
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    69
    Are you ........ing kidding me? Where did you learn ASM?
    Last edited by inu11byte; 10-16-2012 at 02:58 AM.

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    In this case you use the write system call, it's not a string function and does not rely on a terminating zero, instead it writes the amount of bytes you give as an argument. Let's call it from C.

    Code:
    int main()
    {
        const char *s = "Hello";
    
        write(STDOUT_FILENO, s, 5);
    
        return 0;
    }

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by inu11byte View Post
    Are you ........ing kidding me? Where did you learn ASM?
    do you really think you're going to get useful help by responding to people that way?

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Quote Originally Posted by inu11byte View Post
    Are you ........ing kidding me? Where did you learn ASM?
    Where did you learn it if you need to run to a forum for a bit of code that makes 2 system calls?

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by inu11byte View Post
    Are you ........ing kidding me? Where did you learn ASM?
    I'm glad that my response has put you in a state of awe, but seriously... The compliments are unnecessary.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  8. #8
    Registered User
    Join Date
    Dec 2011
    Posts
    69
    Okay, I'm sorry, I shouldn't have replied like that. :/ I understand you were just trying to help. Anyway, if I was shifting that variable to another area of memory, would that area of memory have to have 6 bytes of space, or just 5?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-23-2011, 09:00 AM
  2. *szString = things question/memory question
    By Jang in forum C Programming
    Replies: 3
    Last Post: 01-20-2011, 04:59 AM
  3. Newbish Question file reading question....
    By kas2002 in forum C Programming
    Replies: 23
    Last Post: 05-17-2007, 12:06 PM
  4. java question, how do you interpret this question.
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 11-02-2006, 10:30 AM
  5. Self regiserting DLLs question and libraries question.
    By ApocalypticTime in forum Windows Programming
    Replies: 2
    Last Post: 03-22-2003, 02:02 PM