我写了一个程序,它应该像while循环一样,打印一定数量的文本string。
这里是代码:
global _start section .data msg db "Hello World!",10 ; define the message msgl equ $ - msg ; define message length ; use minimal size of storage space imax dd 0x00001000 ; defines imax to be big! section .text _start: mov r8,0x10 ; <s> put imax in r8d,this will be our 'i' </s> ; just attempt 10 iterations _loop_entry: ; loop entry point mov eax,4 ; setup the message to print mov ebx,1 ; write,stdout,message,length mov ecx,msg mov edx,msgl int 0x80 ; print message ; this is valid because registers do not change dec r8 ; decrease i and jump on not zero cmp r8,1 ; compare values to jump jnz _loop_entry mov rax,1 ; exit with zero mov rbx,0 int 0x80
我遇到的问题是程序运行到一个无限循环。 我在gdb中运行它,原因是:
int 0x80被调用来打印消息,并且这个工作正常,但是在中断完成之后,r8的内容被设置为零,而不是它应该是的值。 r8是计数器坐的位置,计数(减less)string打印的次数。
在共享库中重定位条目
x86 Linux与Windows?
帮助理解GDB中一个非常基本的main()反汇编
使用_RTL_USER_PROCESS_ParaMETERS
int 0x80是否修改寄存器值? 我注意到rax,rbx,rcx,rdx没有受到同样的影响。
检测结果
答:是的! 它修改r8。
我在程序中改变了两件事。 首先我现在cmp r8,0得到Hello World! 正确的次数,和
我已经添加了
mov [i],r8 ; put away i
在_loop_entry:之后_loop_entry:
我也加了
mov r8,[i] ; get i back
之后第一个int 0x80 。
这是我现在的工作计划。 更多的信息来对照C ++的性能。
; ; main.asm ; ; ; To be used with main.asm,as a test to see if optimized c++ ; code can be beaten by me,writing a for / while loop myself. ; ; ; Absolute minimum code to be competative with asm. global _start section .data msg db "Hello World!",10 ; define the message msgl equ $ - msg ; define message length ; use minimal size of storage space imax dd 0x00001000 ; defines imax to be big! i dd 0x0 ; defines i section .text _start: mov r8,0x10 ; put imax in r8d,this will be our 'i' _loop_entry: ; loop entry point mov [i],r8 ; put away i mov eax,msgl int 0x80 ; print message ; this is valid because registers do not change mov r8,[i] ; get i back dec r8 ; decrease i and jump on not zero cmp r8,0 ; compare values to jump jnz _loop_entry mov rax,0 int 0x80
执行shellcode分段错误
操作大小没有指定
在汇编器中插入sorting不起作用
在X86_32 Linux中使用汇编语言保留一部分控制台
我如何移动registry中的标签地址?
int 0x80只是引起一个软件中断。 在你的情况下,它被用来进行系统调用。 是否影响任何寄存器将取决于您所调用的特定系统调用以及您的平台的系统调用调用约定。 阅读您的文档的细节。
具体而言,从System V应用程序二进制接口x86-64™体系结构处理器增补 [ PDF链接 ],附录A, x86-64 Linux内核惯例 :
对于用户级别的应用程序, r8是一个临时寄存器,这意味着它的呼叫者保存。 如果您希望通过系统调用来保留它,则需要自行完成。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。