linux 51 汇编语言,使用SDCC中的sdas8051写单片机汇编程序

最近在学51单片机,我用的是Linux系统。是个坚定的Linuxer。所以不打算换系统。只好自己找在Linux下能够写51单片机程序的编译器。不负苦心人,终于找到了,SDCC,在Fedora的自带的软件包中也有。^_^,OK。工具搞定了,可以开始学习了。我是学电气的,专业也是要学单片机的,但等老师教要等到猴年马月。自学是我一向崇尚的,而且大学里最重要的就是学会怎样学习。好了,废话不多说了。还是讲点靠谱的。

学校图书馆单片机的书还不少,但编译器都用的 Keil的。网上搜了搜,没什么sdcc的资料,:-),还不惨,官网上有文档。虽然是英文的,但最近几年坚持看英文技术书可不是盖的。用上 StarDic终于勉强弄懂。关于C51方面的就不多说了,虽然编译器不同,但基本还是可移植的。

就是Keil中的有些库SDCC中没有,貌似现在才发现一个,毕竟研究的时间还不长。就说说汇编的部分吧。

玩单片机我还是喜欢汇编,但Keil的汇编器语法和sdcc的实在不一样。怎么办呢?sdcc文档中也未提到汇编器的解释。但我在一大堆英文中苦苦的寻找者,终于看到SDCC的汇编器用的是ASXXXX的汇编器,而且还是个开源项目。^_^,顺藤摸瓜,找到那个网站。又是一堆的英文手册。为了技术,看吧。。。。

看手册,并把sdcc生成的汇编代码看看,还是摸出了一点门道,只是一点点阿,以后有新的进展会写进博客的,不过最近不会啦,课程太紧。还要备考四级。

如果用sdas8051写汇编版的单片机程序。会有几个文件。

sourcefile.asm          你自己编辑的源程序文本

sourcefile.rel             汇编器生成的目标文件

sourcefile.lst              汇编器生成的列表文件   用       -l         选项

sourcefile.rst             连接器生成的更新列表文件的文件

sourcefile.sym         汇编器生成的symbol listing(:-),不会翻译拉,看懂就行,意会)  用        -s           选项

soutcefile.mem         应该是连接器生成的内存使用状况的文件

sourcefile.ihx             连接器生成的hex文件,可以用sdcc自带的packihx工具转换为hex格式

。。。。。。。。。。。可能还会有,就不一一列举了,以上是几个重要的。

还有自己要创建的一个sourcefile.lnk文本文件,里面放的是连接器sdld所用的参数。

####################################################################################################

======================================================

所有sdcc可能会有的文件我粘帖在在下面:有兴趣的自己研究。

=====================================================

• sourcefile.asm - Assembler source file created by the compiler

• sourcefile.lst - Assembler listing file created by the Assembler

• sourcefile.rst - Assembler listing file updated with linkedit information, created by linkage editor

• sourcefile.sym - symbol listing for the sourcefile, created by the assembler

• sourcefile.rel - Object file created by the assembler, input to Linkage editor

• sourcefile.map - The memory map for the load module, created by the Linker

• sourcefile.mem - A file with a summary of the memory usage

• sourcefile.ihx - The load module in Intel hex format . Both formats are documented in the documentation of srecord

• sourcefile.adb - An intermediate file containing debug information needed to create the .cdb file (with --debug)

• sourcefile.cdb - An optional file (with --debug) containing debug information. The format is documented in cdbfileformat.pdf

• sourcefile. - (no extension) An optional AOMF or AOMF51 file containing debug information (generated

with option --debug). The (Intel) absolute object module f ormat is a subformat of the OMF51 format and is commonly used by third party tools (debuggers, simulators, emulators).

• sourcefile.dump* - Dump file to debug the compiler it self (generated with option --dumpall)

#######################################################################################################

下面用个实例解释以下sdas8051的汇编格式:

===========================================================================

;-----------------------------------------------------

;    sy3_2.asm

;        the P1 port exam

;------------------------------------------------------

.module sy3_2

.globl start

.globl P1_3

.globl P1_2

.area RSEG (ABS,DATA)

.org 0x0000

P1_3 = 0x0093

P1_2 = 0x0092

.area HOME (ABS,CODE)

.org 0x0000

sjmp start

.org 0x0030

start:

setb P1_3

IF1:

jnb P1_3,ELSE1

THEN1:

clr P1_2

sjmp ENDIF1

ELSE1:

setb P1_2

ENDIF1:

sjmp start

sjmp .

=======================================================================

与keil中的第一大不同就是sdas8051中的伪指令都用  .  开头。

比如定位伪指令为   .org

还有.area伪指令,貌似在keil中没看到。

我的理解就是声明一段区域,是绝对地值,还是重定位的,等等。。。这个很重要,但实在英文不好,说不清还请有兴趣的,去相关网站上下载手册。我会在文章的最后给出相关链接。

其余没有什么大的不同。

还要介绍以下怎么汇编这个文件。

汇编用   sdas8051 -o sourcefile.rel -l -s sourcefile.asm   就可以的到.rel .lst .sym的文件。

至于链接,需要自己写个.lnk的文件。

参考格式如下:

sourcefile.lnk:

##############################################################以下是文本中的内容

-myux

-i sourcefile.ihx

-Y

sourcefile.rel

-e

############################################################结束了

用命令sdld -f sourcefile.lnk

####################################################################################################

相关链接:

好了,基本介绍完了,只是给大家介绍个思路,在具体我的作业就完不成了。大学还是很苦的。这是我的第一篇技术博客,以后还会努力的。在这里要感谢我的舍友,我在他去上课的时候偷用他的上网号,才完成了这篇博客。真的谢谢他,嘿嘿!谁让他不管什么密码都是同一串数字。

希望这些对Linux下想玩单片机的朋友有点用。以上是个人的一点点心得,有错误的地方还请大家指教,互相帮助,才能进步。这也是我喜爱开源的原因之一。0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值