AT&T Assembler

This is a discussion on AT&T Assembler within the Linux Programming forums, part of the Platform Specific Boards category; I'm learning AT&T syntax assembly, and as a little exercise want to write a program that outputs the number of ...

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    AT&T Assembler

    I'm learning AT&T syntax assembly, and as a little exercise want to write a program that outputs the number of command line arguments [including program name].

    As I understand it, the number of args [argc to C gurus] is the first value to be pushed to the stack when a program executes?

    Here's what I have so far:
    Code:
    		.section .data
    argnum:
    		.ascii   ""
    
    		.section .text
    		.globl _start
    
    _start:
    		movl $4, %eax
    		movl $1, %ebx
    		movl (%esp), %edx
    		movl %edx, argnum
    		movl argnum, %ecx
    		movl $2, %edx
    		int  $0x80
    
    		movl $1, %eax
    		xorl %ebx, %ebx
    		int  $0x80
    It compiles and runs fine, but nothing visible is output. I think it might have something to do with sys_write not outputting numbers, so that's why I used an ascii var [argnum], with no avail.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,848
    Some points
    1. .ascii ""
    Does this reserve enough space - it seems like it's just 1 byte containing \0 to me

    2. movl %edx, argnum
    a) you need to convert to ascii, say by adding '0' to it.
    b) you need to move a byte, not a long
    Note this only works for argc in the range 0..9, for larger numbers, the process gets more complicated.

    3. movl argnum, %ecx
    I'm guessing you wanted to move the address here, and not the contents?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Thanks for your help I'll have a fiddle and post up any other problems
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  4. #4
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Hmm still no joy - I movb'd instead, and it [as] warned me it was using %dl instead. I now move the address of argnum into %ecx, but I don't know what you mean by converting it to ascii (I don't know how)

    As you can imagine, here it is now:

    Code:
    		.section .data
    argnum:
    		.ascii   ""
    
    		.section .text
    		.globl _start
    
    _start:
    		movl $4, %eax
    		movl $1, %ebx
    		movl (%esp), %edx
    		movb %edx, argnum
    		movl (argnum), %ecx
    		movl $2, %edx
    		int  $0x80
    
    		movl $1, %eax
    		xorl %ebx, %ebx
    		int  $0x80
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,848
    Random guesses....

    .ascii "0" # space for a single char, which has a \0 following it.

    addb %edx,$48 # convert 0 into '0' say
    movb %edx, argnum
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 10:13 AM
  2. 68000 assembler (building one that is)
    By Nutcasey in forum C Programming
    Replies: 7
    Last Post: 01-22-2004, 04:14 PM
  3. Assembler in GCC
    By Magos in forum Linux Programming
    Replies: 4
    Last Post: 11-05-2002, 04:22 PM
  4. Assembler...
    By face_master in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 10-18-2002, 04:44 PM
  5. MAINFRAME Assembler.
    By sean in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 12-05-2001, 05:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21