试试我的
Linux程序集,我遇到了以下问题.我刚刚开始,所以我的程序是一个相对简单的程序,源自我在linuxassembly上找到的一些例子.它将传递给命令行的第一个参数打印出来.这是我到目前为止所拥有的……
- section .bss
- test_string: resb 3
- section .text
- global _start
- _start:
- pop ebx ;argument number
- pop ebx ;program name
- pop ebx ;first argument
- mov [test_string],ebx
- mov eax,4
- mov ebx,1
- mov ecx,test_string
- mov edx,3
- int 80h
- mov eax,1
- mov ebx,0
- int 80h
我知道这写得不好,但由于我是新手,所以我只是想在继续之前更好地理解装配指令/变量的工作原理.我使用…组装和链接
- nasm -f elf first.asm
- ld -m elf_i386 -s -o first first.o
然后我继续使用..
- ./first one two
我当时认为它会打印出“one”,但它打印出像“Y *&”这样的gibbrish.我究竟做错了什么?我的test_string是错误的类型吗?
解决方法
您正在尝试打印指向字符串的指针的值而不是打印字符串.你想要这样做.
- pop ebx ;argument number
- pop ebx ;program name
- pop ebx ;pointer to the first argument
- mov ecx,ebx ;load the pointer into ecx for the write system call
- mov eax,4 ;load the other registers for the write system call
- mov ebx,1
- mov edx,3
- int 80h
- mov eax,1
- mov ebx,0
- int 80h