【我所認知的BIOS】->汇编语言之宏汇编1

【我所認知的BIOS】->汇编语言之宏汇编1

By LightSeed

2010-2-2 

其实早就想写点关于汇编语言的文章了,但是最近感觉比较累,自己也比较懒今天才动手写。哎。。。真是身心俱疲,房价涨了,小菜也涨了,妹儿的要求也涨了,但是哥的工资还是不涨。这社会我快混不下去了。但是想想做男人嘛,有什么大不了的。做人,最重要的是心态要好,要稳。

1、我体会到的C和汇编

目前我还做的legacyBIOS,里面全是汇编语言。老实说,最近在study C语言的东西,也在研究用C生成ASM的文件,细细想来C确实很强大,汇编语言的效率确实也高。从C生成的汇编语言来看的话,如果是组织的好,实际的汇编语言的效率应该是比C高的。关于汇编语言的基础性的东西我就不多赘述了。在这里我想谈谈我在仿写ADU那个debug tool的时候用的一些汇编语言的里的高级语句。(当然先说清楚,这也是参考了BIOS code的东西,让我自己写我想我是写不出来的啦。),话有说回来,对于程序员来说,如果让我在C和汇编语言之间选择,当然还是比较喜欢用C了。(最近我在study ACPI的东西的时候,就试图用C来写一个ACPI dump的工具,发觉用C写真的好方便哦,两天就能搞出来一个功能了,但是如果用汇编的话,就算知道算法,估计写起来也比较费神。)

在组织数据段中的数据的时候,按照结构体的形式来存储有关联的数据是一种明智的选择。但是由于这个结构体需要输入的东西比较多,那么每次都手动去输入相关数据的话,估计烦也烦死了。所以宏汇编在这里就其了很大的作用。

2、宏汇编

(以下这段话是引用自网上的,对于这些定义放在这里纯粹是为了这篇文章的完整性。)

----------------------------引用开始----------------------

在程序设计中,为了简化程序的设计,将多次重复使用的程序段用宏指令代替。宏指令是指程序员事先定义的特定的指令,这种指令是一组重复出现的程序指令块的缩写和替代。宏指令定义后,凡在宏指令出现的地方,宏汇编程序总是自动地把它们替换成对应的程序指令块。宏指令有时也称为宏,包含宏定义和宏调用。

使用宏指令的好处是:简化源程序的编写,传递参数灵活,功能更强。

2.1宏指令的定义

宏是源程序中的一段具有独立功能的程序代码。它只要在源程序中定义一次,就可以多次调用,调用时只要使用一个宏指令语句就可以了。宏指令定义由开始伪指令MACRO、宏指令体、宏指令定义结束伪指令ENDM组成。格式如下:

宏指令名  MACRO

 [形式参数1,形式参数2 形式参数N]

;宏指令体(宏体)

ENDM

其中,宏指令名是宏定义为宏体程序指令块规定的名称,可以是任一合法的名字,也可以是系统保留字(如指令助记符、伪指令操作符等),当宏指令名是某个系统保留字时,则该系统保留字就被赋予新的含义,从而失去原有的意义。MACRO语句到ENDM语句之间的所有汇编语句构成宏指令体,简称宏体,宏体中使用的形式参数必须在MACRO语句中列出。

形式参数是出现在宏体内某些位置上可以变化的符号,也可以是任一合法的名字,甚至是寄存器名(笔者:我不建议你这样使用)。如果形式参数中使用某些寄存器名,那么在宏汇编展开时,将不认为这些寄存器名是寄存器本身,而是形式参数,并被实际参数所代替。形式参数可以缺省,也可以有一个或多个。当形式参数多于一个时,形式参数之间用逗号隔开。定义宏指令时,每行的字符数不能多于132个。宏指令定义一般放在源程序的开头,以避免产生不应发生的错误。

宏指令必须先定义后调用(引用)。宏指令可以重新定义,也可以嵌套定义。嵌套定义是指在宏指令体内还可以再定义宏指令或调用另一宏指令。(笔者:其实这和C中的方式也比较相似。扩展一下,汇编语言中的结构体也是这也的。)

2.2宏指令的调用

宏指令一旦定义后,就可以用宏指令名字(宏名)来引用(或调用),这个引用过程即为宏调用。宏调用的格式为

宏指令名  实际参数1,实际参数2,实际参数N

其中,实际参数的类型和顺序要与形式参数的类型和顺序保持一致,宏调用时将一一对应地替换宏指令体中的形式参数。当有两个以上参数时,中间用逗号、空格或制表符隔开。宏指令调用时,实际参数的数目并不一定要和形式参数的数目一致。当实参个数多于形参的个数时,忽略多余的实参;当实参个数少于形参个数时,多余的形参用空串代替。

;---------------------------------引用结束------------------------

哈哈,我们应该向前辈看齐的嘛,多学习前辈的东西,总是不会错的。

3、条件汇编

IF/IFE伪指令中的表达式可以采用第3章学习的关系运算符EQ(相等)、NE(不相等)、GT(大于)、LT(小于)、GE(大于等于)、LE(小于等于)。关系表达式用0ffffh(非0)表示真,用0表示假。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
代码部分来自Google的重建IBMPC BIOS项目(https://sites.google.com/site/pcdosretro/ibmpcbios),其中的BIOS镜像(*.rom)可用于各种IBM PC模拟器,可按情况使用。源代码可以用masm编译,站内英文说明文件如下: IBM PC BIOS source code reconstruction This is a reconstruction of the IBM PC, PC XT, PC AT and PC XT 286 BIOS source code using scanning and transcription of the BIOS listings found in the IBM Technical Reference manuals. This historically relevant source code is presented here for software preservation. The following BIOS source code has been reconstructed: IBM PC version 1 04/21/81 IBM PC version 2 10/19/81 IBM PC version 3 10/27/82 IBM PC XT version 1 11/08/82 (also used on the Portable PC) IBM PC XT version 2 01/10/86 IBM PC XT version 3 05/09/86 IBM PC AT version 1 01/10/84 IBM PC AT version 2 06/10/85 IBM PC AT version 3 11/15/85 (used on the PC AT models 319 and 339) IBM PC XT 286 04/21/86 Notes: • All 3 versions of the IBM PC BIOS and the first version of the IBM PC XT BIOS were built using Intel ASM86 on an Intel development system. In each case the BIOS source code is a single large file and the BIOS code is 8KB which resides at F000:E000 • The IBM PC AT version 1 BIOS was built using IBM MASM 1.0 on DOS. This is the first IBM BIOS which uses multiple source files. Since IBM MASM 1.0 did not support the 80286 there is a macro file (IAPX286.MAC) which is used to generate the necessary opcodes. This is also the first BIOS to be split into two parts: the main BIOS code resides at F000:0000 and the compatibility section (ORGS.ASM) resides at F000:E000. An additional file FILL.ASM has been added to define the area between the end of the main BIOS code and the compatibility section to allow the BIOS to be linked properly. It is currently unknown how this was originally handled. • The IBM PC AT version 2 and 3 BIOS and the IBM PC XT 286 BIOS were built using IBM MASM 2.0 on DOS. These are similar to the PC AT version 1 BIOS but there are fewer source files as some files were combined and a bit of cleanup was done. IAPX286.INC is used to generate the protected-mode 80286 opcodes which IBM MASM 2.0 did not support. FILL.ASM serves the same purpose as it does for the PC AT version 1 BIOS though in each case the file is specific to the particular BIOS being built. • The IBM PC XT version 2 and 3 BIOS were built using IBM MASM 2.0 on DOS. The later PC XT BIOS code was restructured to be similar to the PC AT BIOS code so there are multiple source files. Like the PC AT BIOS the code is split into two parts though the compatibility section is in the file POST.ASM. Again the additional file FILL.ASM is used to define the area between the end of the main BIOS code and the compatibility section. • The following code is present in all versions of the PC AT BIOS and the PC XT 286 BIOS but does not appear in the published listings. It is inferred from the public symbols in ORGS.ASM and code disassembly. It is unknown what purpose this code serves. .XLIST ;;- ORG 0FF5AH ORG 01F5AH HRD PROC FAR CALL DISK_SETUP RET HRD ENDP FLOPPY PROC FAR CALL DSKETTE_SETUP RET FLOPPY ENDP SEEKS_1 PROC FAR CALL SEEK RET SEEKS_1 ENDP TUTOR: JMP K16 .LIST • In all cases the 32KB ROM BASIC code which resides at F6000 is not available as its source code was never published. • Versions of MASM later than 4.0 cannot be used to build the IBM BIOS source code since older constructs and macros are used. More information about functionality changes in the IBM PC BIOS code is listed here: IBM PC BIOS version history

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值