Using assembly writing algorithm programs
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 -
- # rdx --- i, rax --- min, rcx --- j, rbx --- tmp
- .section .data
- data_item:
- .quad ,,,,,,,,,,,,,
- before_sort:
- .asciz "sorted nums:\n"
- sort_output_format:
- .asciz "%d\n"
- .section .text
- .globl _start
- _start:
- movq $, %rdx
- out_loop: # outer loop
- movq %rdx, %rax
- movq data_item(,%rdx,), %rbx # if arr[i] == print all nums sorted and exit.
- cmp $, %rbx
- je print_arr
- movq %rdx, %rcx
- incq %rcx
- inner_loop: # inner loop, get the min-value
- cmp $, data_item(,%rcx,)
- je inner_loop_exit
- movq data_item(,%rax,), %rbx
- cmp %ebx, data_item(,%rcx,)
- jg not_change_min
- movq %rcx, %rax
- not_change_min:
- incq %rcx
- jmp inner_loop
- inner_loop_exit:
- movq data_item(,%rdx,), %rbx # swap the value, of arr[i] and the min-value.
- movq data_item(,%rax,), %rdi
- movq %rdi, data_item(,%rdx,)
- movq %rbx, data_item(,%rax,)
- incq %rdx
- jmp out_loop # inner loop exits.
- print_arr:
- movq $, %rbx # print 'sorted nums:'
- movq $before_sort, %rdi
- call printf
- print_loop: # print all nums sorted in a loop
- movq data_item(,%rbx,),%rax
- cmp $, %rax
- je end
- movq $sort_output_format, %rdi
- movq %rax, %rsi
- call printf
- incq %rbx
- jmp print_loop
- end: # program ends.
- movq $, %rdi
- movq $, %rax
- syscall
Using assembly writing algorithm programs的更多相关文章
- writing concurrent programs
Computer Systems A Programmer's Perspective Second Edition To this point in our study of computer sy ...
- Practical Go: Real world advice for writing maintainable Go programs
转自:https://dave.cheney.net/practical-go/presentations/qcon-china.html?from=timeline 1. Guiding pri ...
- 32 Profiling Go Programs 分析go语言项目
Profiling Go Programs 分析go语言项目 24 June 2011 At Scala Days 2011, Robert Hundt presented a paper titl ...
- Writing Reentrant and Thread-Safe Code(译:编写可重入和线程安全的代码)
Writing Reentrant and Thread-Safe Code 编写可重入和线程安全的代码 (http://www.ualberta.ca/dept/chemeng/AIX-43/sha ...
- zhihu spark集群,书籍,论文
spark集群中的节点可以只处理自身独立数据库里的数据,然后汇总吗? 修改 我将spark搭建在两台机器上,其中一台既是master又是slave,另一台是slave,两台机器上均装有独立的mongo ...
- The Go Programming Language. Notes.
Contents Tutorial Hello, World Command-Line Arguments Finding Duplicate Lines A Web Server Loose End ...
- K老在拿图灵奖时的发言:Computer Programming as an Art
很多话说得很透彻,把一些觉比较精彩的摘抄一下. ... It seems to me that if the authors I studied were writing today, they wo ...
- bsdasm
bsdasm 来源 http://www.int80h.org/bsdasm/ Preface by G. Adam StanislavWhiz Kid Technomagic Assembly la ...
- PatentTips - Safe general purpose virtual machine computing system
BACKGROUND OF THE INVENTION The present invention relates to virtual machine implementations, and in ...
随机推荐
- z-stack组网过程
z-stack组网分:协调器建立网络.路由器和终端加入网络 暂时只记录第一次上电建立网络的过程,至于开启NV_RESTORE后,恢复原有的网络则暂时不分析. 一.协调器建立网络: 1.ZDO层的ZDA ...
- 关于利用bat文件调用exe批量处理文件下的文件的问题
for %%i in (E:\radar_20120721\sjz_sa\*.bin) do start/wait radas.exe -i=%%i -o=E:\longjiang\out 找到 文件 ...
- linux查看是什么操作系统是什么命令
https://zhidao.baidu.com/question/361519585968730492.html
- 测试--easymock的使用
使用场景:对于调用其它类中的方法,但是还没有编写完,使用easymock进行单元测试,它提供这些没有编写完的代码期待的默认值. 使用步骤: step1: pom引入: <dependency&g ...
- tomcat -ROOT 与webapps 的关系,关于部署的一些问题
现象:之前遇到很奇怪的问题,发完版之后没有效果,页面还是读取上一版的. 反复查找原因发现 http://localhost:8080/mobie 这个路径下的页面是正常的, 而 http://lo ...
- SQL Server 里的递归查询
http://www.360doc.com/content/13/0607/11/8463843_291221684.shtml
- 定时任务crontab 例子
查看定时任务格式 [root@centos ~]# vim /etc/crontab 1 SHELL=/bin/bash 2 PATH=/sbin:/bin:/usr/sbin:/usr/bin 3 ...
- Odoo 二次开发教程(五)-新API的介绍与应用
[关于odoo新API的介绍,Internet上资料很少,或者不够完整详实,这会对初学者造成很大的困惑,本篇的目的就是希望能帮助新手了解新API的大概] odoo 新api的实现是借助于python装 ...
- *POJ 1222 高斯消元
EXTENDED LIGHTS OUT Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9612 Accepted: 62 ...
- c++ 宏定义声明类,并在类中实现回调
#include <iostream> #include <windows.h> #include <string> using namespace std; ty ...