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 ...
随机推荐
- EventLoop和EventLoopGroup
Netty框架的主要线程就是I/O线程,线程模型设计的好坏,决定了系统的吞吐量.并发性和安全性等架构质量属性.Netty的线程模型被精心地设计,既提升了框架的并发性能,又能在很大程度避免锁,局部实现了 ...
- centos 研究
默认工具: yum , (Ubuntu: apt-get)
- select2 清空数据
最近用select2插件,发现用jquery重置不好使,最后搜罗了一把发现下面这个方法可以间接的实现,有空还得看看插件的API $('#integratorId').select2('data', n ...
- shr 右移测试
fdword :DWORD; procedure TForm10.btn1Click(Sender: TObject); var temp:DWORD; begin fdword :=; //7866 ...
- 通过 listboxitem 查找属于listbox第几条数据
public override System.Windows.Style SelectStyle(object item, System.Windows.DependencyObject contai ...
- iterm2
Mac下配置iterm2 http://www.dreamxu.com/mac-terminal/ 快捷键 http://cnbin.github.io/blog/2015/06/20/iterm2- ...
- 关闭rdlc报表打印预览后,关闭客户端,抛出异常“发生了应用程序级的异常 将退出”
问题:关闭rdlc报表打印预览后,关闭客户端,抛出异常“发生了应用程序级的异常 将退出” 办法:在容纳ReportViewer的窗体后台代码中,添加如下代码即可 protected override ...
- JFreeChart
花了四个小时给同学写的.还行吧,原来都没有用过到处找资料写的. package DrawLine; import org.jfree.chart.ChartFactory; import org.jf ...
- 【oracle】数据泵expdp与impdp
1.创建directory create directory dump_dir as 'D:\dump_dir' 2.expdp备份schema expdp system/1qaz2wsx@ETCNC ...
- 谈谈rem
用rem已久但是对于它的理解似乎一直都有偏差,使用的时候多采用的是html的font-size:62.5%;然后按照1rem=10px这样来使用.所以我一直不明白,这个rem到底哪里是相对单位了,也不 ...