官术网_书友最值得收藏!

Linux

If you are on Linux, the source code will be even shorter. Open your favorite source editor, whether it is nano, emacs, or vi, or whatever, and enter the following code:

 format ELF executable 3
entry _start

segment readable executable
_start:
mov eax, 4
mov ebx, 1
mov ecx, message
mov edx, len
int 0x80

xor ebx, ebx
mov eax, ebx
inc eax
int 0x80


segment readable writeable
message db 'Hello from FASM on Linux!', 0x0a
len = $ - message

The code is much more compact than that on Windows, as we are not using any high-level API functions; we'd rather use Linux system calls directly (this could turn into a nightmare on Windows). Save the file as fasm1lin.asm (this is not GAS or GCC, so we are free to give the Assembly source file its usual extension) and go to the terminal emulator. Issue the following command (assuming the fasm executable is in the place mentioned in the PATH environment variable) in order to build the executable out of this code:

fasm fasm1lin.asm fasm1lin

Then, try to run the file with the following:

./fasm1lin

You should see something like this:

Building and running a Linux executable with Flat Assembler

As simple as that.

主站蜘蛛池模板: 来凤县| 永州市| 康马县| 醴陵市| 彰武县| 仙桃市| 钟山县| 剑河县| 攀枝花市| 西林县| 临邑县| 隆昌县| 全南县| 丽水市| 文化| 晋宁县| 定日县| 庐江县| 习水县| 诸城市| 司法| 青神县| 襄垣县| 南华县| 崇仁县| 濉溪县| 桃园市| 攀枝花市| 吉林省| 安化县| 宁陕县| 商都县| 冷水江市| 共和县| 珲春市| 潍坊市| 万源市| 巴楚县| 东辽县| 灵璧县| 贵州省|