Using assembly writing algorithm programs
来源:互联网 发布:软件开发可行性报告 编辑:程序博客网 时间:2024/05/21 14:47
This's my first version.The logic is simple, just the selection sort.
I spent much time learning how to write AT&T assembly on 64-bit Linux.almost all books just talk about 32-bit assembly.
Such as registers, on 64-bit linux, rax, rbx, rcx..... are all 8 bytes. not like eax,ebx,ecx 4 bytes.
And the differences with the use of libraries such as printf.32-bit AT&T assembly push the parameters before calling printf.but 64-bit AT&T assembly saving the parameters in registers such as rsi or rdi before calling printf.
movq .quad 8bytes 64-bit
movl .long 4bytes 32-bit
movw .word 2bytes 16-bit
movb .byte 1bytes 8-bit
# func: selection sort algorithm # by whoami# Oct 1-4 2016# rdx --- i, rax --- min, rcx --- j, rbx --- tmp.section .datadata_item: .quad 3,67,34,222,45,75,54,34,44,33,22,11,66,0before_sort: .asciz "sorted nums:\n"sort_output_format: .asciz "%d\n".section .text.globl _start_start: movq $0, %rdx out_loop: # outer loop movq %rdx, %rax movq data_item(,%rdx,8), %rbx # if arr[i] == 0 print all nums sorted and exit. cmp $0, %rbx je print_arr movq %rdx, %rcx incq %rcx inner_loop: # inner loop, get the min-value cmp $0, data_item(,%rcx,8) je inner_loop_exit movq data_item(,%rax,8), %rbx cmp %ebx, data_item(,%rcx,8) jg not_change_min movq %rcx, %rax not_change_min: incq %rcx jmp inner_loop inner_loop_exit: movq data_item(,%rdx,8), %rbx # swap the value, of arr[i] and the min-value. movq data_item(,%rax,8), %rdi movq %rdi, data_item(,%rdx,8) movq %rbx, data_item(,%rax,8) incq %rdx jmp out_loop # inner loop exits.print_arr: movq $0, %rbx # print 'sorted nums:' movq $before_sort, %rdi call printf print_loop: # print all nums sorted in a loop movq data_item(,%rbx,8),%rax cmp $0, %rax je end movq $sort_output_format, %rdi movq %rax, %rsi call printf incq %rbx jmp print_loopend: # program ends. movq $127, %rdi movq $60, %rax syscall
0 0
- Using assembly writing algorithm programs
- Writing ROS programs
- Excerpts from Writing Efficient Programs
- A Basic Template For Assembly Language Programs
- Using WinPcap in your programs
- 重读《Programming Pearls》之四:Writing Correct Programs
- Learning Linux(5): writing C programs in Linux
- A Summary of Jon Louis Bentley's ``Writing Efficient Programs''
- Writing XML File using XmlWriter
- Assembly-Level Representation of Programs on IA32 and x86-64
- Using Assembly Language in Linux
- Using Inline Assembly With gcc
- Using Assembly Language in Linux
- Using Assembly Language in Linux
- Best Practice in Writing a COM-Visible Assembly (C#)
- Writing a boot loader in Assembly and C
- Writing and Optimizing ARM Assembly Code 《ARM...》Chapter-6
- Design sequences using genetic algorithm
- 关于中断服务函数带来返回值的思考
- OpenGrok源码搜索引擎搭建
- 数组中出现次数超过一半的数字
- java 写一个简单的计算器
- java io系列08之 File总结
- Using assembly writing algorithm programs
- 操作系统下的指针长度
- Ubuntu下搭建R语言开发环境
- Java-IO之字符输入输出流(Reader和Writer)
- 剑指offer(4)-O(1)时间删除链表结点
- 8086数据寄存器介绍
- 一个页面从输入 URL 到页面加载显示完成,这个过程中都发生了什么?
- 如何对示波器中的参数和图片进行处理心得整理
- 百度云的产品及使用场景分析