Find the answer to your Linux question:
Results 1 to 3 of 3
Hi how do you read the argc and argv arguments in 64 bit assembler(AMD athlon 64 bit)?...I know how to do it in 32 bit intel/amd assembler i.e. Code: .section ...
  1. #1
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714

    [SOLVED] AMD athlon 64 bit assembler

    Hi how do you read the argc and argv arguments in 64 bit assembler(AMD athlon 64 bit)?...I know how to do it in 32 bit intel/amd assembler i.e.

    Code:
    .section .data
    
    .section .bss
    
    .section .text
    	.global _start
    
    _start:
    			nop
    			popl	%ebx
    			popl	%ebx
    			popl	%ebx
    
    			movl	$8, %eax
    			movl	$0644, %ecx
    			int	$0x80
    
    			movl	%eax, %ebx
    			movl	$1, %eax
    			int	$0x80
    compile and then run the program
    ./programname filename
    and you will create a file called filename

    but when I try the same in AMD athlon 64 bit i.e.

    Code:
    .section .data
    
    .section .bss
    
    .section .text
    	.global _start
    _start:
    			nop
    			popq	%rbx
    			popq	%rbx
    			popq	%rbx
    
    			movq	$8, %rax
    			movq	$0644, %rcx
    			int	$0x80
    
    			movq	%rax, %rbx
    			movq	$1, %rax
    			int	$0x80
    compile and then run the program
    ./programname filename
    and its does not create a file called filename

    The gnu debugger gdb (in the 64 bit example)does show a char pointer in %rbx with the value "filename" but the program fails to create a file
    any help will be appreciated...Thanks Gerard
    Note: its not a permissions problem because I create and delete files in this folder all the time in C/C++.

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714

    Not A Solution...But

    AMD Athlon 64 bit assembler

    Not a solution(at least not a pretty one) but it does copy the data from argv[1] when compiled and run

    ./programname one two three four

    it will write "one" to the terminal. All I did was copy the pointer value of avgv[1] off the stack and dereferenced it byte by byte and copied into one, two, three and then printed it with the system call write(system call 4). Like I said not pretty...but if I use the copied pointer value directly in the system call write nothing happens...
    could it be that the kernel has problems with the larger pointer values ie.

    the pointer value in %rdi = 0x7fff5a703342 and I can dereference it properly in the assembler code but as soon as I try to pass it in a system call it fails...any thoughts on this would be appreciated...Thanks Gerard4143

    Code:
    .section .data
    	one: .byte 'a' 
    	two: .byte 'a'
    	three: .byte 'a'
    
    .section .bss
    
    .section .text
    	.global _start
    _start:
    			nop
    			movq	16(%rsp), %rdi
    			
    			movb	(%rdi), %cl 
    			movb	%cl, one
    			movb	1(%rdi), %cl 
    			movb	%cl, two
    			movb	2(%rdi), %cl 
    			movb	%cl, three
    
    			movq	$4, %rax 
    			movq	$1, %rbx
    			movq	$one, %rcx
    			movq	$3, %rdx
    			int	$0x80
    
    			movq	$1, %rax
    			movq	$0, %rbx
    			int	$0x80
    Here's the original problem with file creation system call...it works but not pretty

    Code:
    .section .data
    	one: .byte 'a' 
    	two: .byte 'a'
    	three: .byte 'a'
    
    .section .bss
    
    .section .text
    	.global _start
    _start:
    			nop
    			movq	16(%rsp), %rdi
    
    			movb	(%rdi), %cl
    			movb	%cl, one
    			movb	1(%rdi), %cl
    			movb	%cl, two
    			movb	2(%rdi), %cl
    			movb	%cl, three
    
    			movq	$8, %rax
    			movq	$one, %rbx
    			movq	$0644, %rcx
    			int	$0x80
    
    			movq	$1, %rax
    			movq	$0, %rbx
    			int	$0x80

  3. #3
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714

    Solved it

    This have really changed for 64 bits AMD machines...this is the solution

    and here's the web page that I got the info:

    http://ubuntuforums.org/showthread.php?t=728995

    Code:
    .section .data
    	
    .section .bss
    
    .section .text
    	.global _start
    _start:
    			nop
    			movq	24(%rsp), %rsi
    
    			movq	$1, %rax
    			movq	$1, %rdi
    			movq	$3, %rdx
    			syscall
    
    			movq	$60, %rax
    			movq	$0, %rdi
    			syscall

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...