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 ...
随机推荐
- 高效快捷实用移动开单手持扫描打印一体智能 POS PDA
PDA数据采集器,是一款移动手持开单设备,它通过WIFI和GPRS连接并访问电脑,从进销存软件中读取数据,实现移动开单,打破电脑开单模式. 它自带扫描器,可直接扫描条码来查找产品,且功能强大.操作简单 ...
- iOS Hit-Test应用
最近又看了遍苹果的官方文档<Event Handling Guide for iOS>,对事件响应链中的hit-test view 又多了些理解,个人觉的官方文档对这块讲的非常简单,很多东 ...
- Spring MVC --->>>No mapping found for HTTP request with URI
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> < ...
- MD5加密的Java实现
在各种应用系统中,如果需要设置账户,那么就会涉及到储存用户账户信息的问题,为了保证所储存账户信息的安全,通常会采用MD5加密的方式来,进行储存.首先,简单得介绍一下,什么是MD5加密. MD5的全称是 ...
- jquery 的3D Carousel插件参数说明
这个插件大家都很熟悉了,但是在网上找了很久找不到相关的资料,只有自己琢磨研究了一下.有些参数一眼都可以看出意思,在此我只说一下每个图片要想带一些扩展信息怎么处理. 1:首先需要创建一个ul对象,然后里 ...
- overflow:hidden清除浮动原理
overflow:hidden的意思是超出部分去掉,如果父元素height为auto,内部元素浮动,势必会将内部元素全部隐藏,故计算出内部浮动高度顺便清除浮动.
- 安装cocoaPods的详细步骤
先大概说下安装的步骤: Xcode 这个是开发必须的, HomeBrew RVM Ruby CocoaPods 一.HomeBrew: 打开官网链接:http://brew.sh/index_zh-c ...
- php 迭代器使用
/** * 执行入口 * @author tianyunchong * Time: 4:48 pm * @return null */ public function run() { /** 遍历下所 ...
- Spark源码编译并在YARN上运行WordCount实例
在学习一门新语言时,想必我们都是"Hello World"程序开始,类似地,分布式计算框架的一个典型实例就是WordCount程序,接触过Hadoop的人肯定都知道用MapRedu ...
- SSH整合,必出精品
SSH:顾名思义(spring,struts2,hirbernate) Struts(表示层)+Spring(业务层)+Hibernate(持久层) Struts是一个表示层框架,主要作用是界面展示 ...