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