📄 00000003.htm
字号:
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>作者: JoeLu (恼人的 RS-232) 看板: Linux <BR>标题: Re: assembly for Linux?? <BR>时间: Mon Mar 10 16:32:03 1997 <BR> <BR>※ 引述《<A HREF="mailto:Chipmunk.bbs@chip.v1.dorm.ncku.edu.tw">Chipmunk.bbs@chip.v1.dorm.ncku.edu.tw</A> (□□花栗鼠)》之铭言: <BR>∶<I> 有没有assembly for Linux的啊?? </I><BR> <BR> check the info document of "as" <BR> <BR> (注:另外也有 Assembly-HOWTO 可以参阅) <BR> <BR> <BR>><I> -------------------------------------------------------------------------- < </I><BR> <BR>发信人: <A HREF="mailto:wenij.bbs@bbs.mgt.ncu.edu.tw">wenij.bbs@bbs.mgt.ncu.edu.tw</A> (我想应该是这样...), 看板: Linux <BR>标 题: Re: assembly for Linux?? <BR>发信站: 中大资管龙猫资讯天地 (Tue Mar 11 09:38:05 1997) <BR>转信站: sobee!netnews.ntu!news.mcu!news.cs.nthu!UUserv.Net.tw!aidebbs!spring!N <BR> <BR>==> <A HREF="mailto:gcc.bbs@bbs.ee.ntu.edu.tw">gcc.bbs@bbs.ee.ntu.edu.tw</A> (双面人) 提到: <BR>∶<I> ==> 在 <A HREF="mailto:JoeLu.bbs@freebsd.ee.ntu.edu.tw">JoeLu.bbs@freebsd.ee.ntu.edu.tw</A> (恼人的 RS-232) 的文章中提到: </I><BR>∶<I> : check the info document of "as" </I><BR>∶<I> but 指令不太一样就是... </I><BR> check the "nasm" <BR> it can generator for djgpp linux .. <BR> <BR> <BR>><I> -------------------------------------------------------------------------- < </I><BR> <BR>发信人: <A HREF="mailto:ljchuang@csie.nctu.edu.tw">ljchuang@csie.nctu.edu.tw</A> (Chuang Li-chung), 看板: Linux <BR>标 题: Re: assembly for Linux?? <BR>发信站: somewhere in NCTU (Tue Mar 11 13:22:10 1997) <BR>转信站: sobee!netnews.ntu!spring!aidebbs!netnews.csie.nctu!ljchuang <BR> <BR>mufa (<A HREF="mailto:mufa.bbs@bbs.nchu.edu.tw)">mufa.bbs@bbs.nchu.edu.tw)</A> 提到: <BR>∶<I> ==> 在 [<A HREF="mailto:Chipmunk.bbs@chip.v1.dorm.ncku.edu.tw]">Chipmunk.bbs@chip.v1.dorm.ncku.edu.tw]</A> 文中提到: </I><BR>∶<I> : ri </I><BR>∶<I> : 来 源: chip.v1.dorm.ncku.edu.tw </I><BR>∶<I> : 有没有assembly for Linux的啊?? </I><BR>∶<I> : 用dosemu跑masm好像有一点问题. </I><BR>∶<I> : 都会给我出现. </I><BR>∶<I> : DOSXNT : fatal error DX1140: DOSXNT.386 required to run with Windows </I><BR>∶<I> : DOSXNT : fatal error DX1230: DOSXNT initialization failed ?? </I><BR>∶<I> : 有方法解决吗??? </I><BR>∶<I> 找找你有没有 as 吧!不过我也不会用 ! </I><BR> <BR> 用c先写一个hello.c, 然後 gcc -S hello.c 产生hello.s (assembly档) <BR> , 自己看看就懂了! <BR> <BR> <BR> <BR>><I> -------------------------------------------------------------------------- < </I><BR> <BR> <BR>发信人: <A HREF="mailto:taichi.bbs@bbs.ee.ncu.edu.tw">taichi.bbs@bbs.ee.ncu.edu.tw</A> (小太极), 看板: Linux <BR>标 题: Re: 初穴组合语言 <BR>发信站: 中央大学松涛风情资讯站 (Tue Apr 15 03:58:08 1997) <BR>转信站: sobee!netnews.ntu!news.mcu!news.cs.nthu!UUserv.Net.tw!news.cis.nctu!ne <BR> <BR>><I>: 如果要看这份文件, 建议先看Mechine Dependence的80386 Dependence吧! </I><BR>><I>: 这□说明了at&t的组语语法 </I><BR>><I> 这在哪里找得到? </I><BR> <BR> <BR> 在 info as 的 Mechine Dependencies 下的 i386-Dependent <BR> i386-Syntax:: AT&T Syntax versus Intel Syntax 这一章有提到 <BR> <BR> 下面转贴一个外国人 Mauro Ziliani (<A HREF="mailto:mauro.ziliani@rsadvnet.it)写的">mauro.ziliani@rsadvnet.it)写的</A> <BR> linux assembly tutorial <BR> <BR>************************************************************************* <BR> <BR>Mauro Ziliani (<A HREF="mailto:mauro.ziliani@rsadvnet.it)">mauro.ziliani@rsadvnet.it)</A> wrote: <BR> <BR>here's a linux assembly tutorial I wrote.. it may be inaccurate in places, so <BR>if you find something wrong let me know. <BR> <BR>---------cut here n stuph------------------ <BR>Assembly <BR> <BR>To code assembly in Linux, you must use GNU Assembler (GAS). This seems to <BR>scare away a lot of people for some reason, but it's not that hard. The AT&T <BR>syntax is not love at first sight if you're used to traditional 386 <BR>assemblers, but it's not incredibly difficult to get used to. To see how the <BR>syntax works, look at the info page for the 'as' command, by typing 'info as'. <BR> <BR>* as: (as). GNU Assembler <BR> <BR>If if when you do 'info as' it comes up with the manpage, you probably need to <BR>do this as well. Lots of other stuff is probably missing too. Anyways... <BR> <BR>I'll sum up the differences between MASM and GAS here: <BR> <BR>- put % in front of every register name ('eax' turns into '%eax') <BR>- reverse the operand order ('mov eax, ebx' turns into 'mov %ebx, %eax') <BR>- put a size postfix on instruction names ('push dword ptr foo' turns into <BR> 'pushl foo') (you can do this to nearly every instruction, but it's mostly <BR> optional) <BR>- put $ in front of immediate operands ('mov eax, 666' turns into 'mov $666, <BR> %eax') <BR>- use labels and .byte, .short, .long instead of db, dw, dd <BR>- use # instead of ; for comments <BR>- use the disp(base, index, scale) format ('mov eax, [ptr+ebx+edx*4]' turns <BR> into 'movl ptr(%ebx,%edx,4), %eax') <BR>- put prefixes on a seperate line before the actual instruction <BR> ('rep movsd' turns into: <BR> rep <BR> movsl) <BR> <BR>Now then, here is a Linux hello world program written entirely in assembly, to <BR>show you how it's done: <BR> <BR>..data <BR> <BR>message: <BR> .string "Hello, world\n" <BR> <BR>..text <BR> <BR>..global main <BR> <BR>main: <BR> pushl $message <BR> call printf <BR> popl %ecx <BR> ret <BR> <BR>Pretty simple, eh? Going line-by-line, the first line declares the start of <BR>the data section (segment in ye olde DOS terms). The second line <BR>labels the "Hello, world" message which follows in ASCIIZ format on the third <BR>line. The fourth line starts the text (i.e. code) section and then the 'main' <BR>label is made global so the linker knows where the program starts. Then <BR>there's the 'main' label, and a call to the printf() standard C library <BR>function. Then the program ends. To assemble this, put it in a file named <BR>'hello.s' then run 'gcc -o hello hello.s'. <BR> <BR>To call a function in another object or library, you must use the Linux <BR>calling convention, which basically means you save eax, edx, and ecx; push the <BR>parameters in reverse order; and then after the call clean up stack. The <BR>return value of the function you called will be in eax. <BR> <BR>To write your own function callable from C, do the same in reverse. Save ebx, <BR>edi, esi, ebp, and esp if you use them and restore them upon returning; the <BR>parameters passed to your function will be available starting at esp+4. Be <BR>sure to make the function label global. <BR> <BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -