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

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.

主站蜘蛛池模板: 拜城县| 镇远县| 子长县| 同德县| 革吉县| 冕宁县| 东海县| 白银市| 汕头市| 治县。| 运城市| 息烽县| 佳木斯市| 灵璧县| 华坪县| 河津市| 湖北省| 清河县| 吴川市| 元朗区| 临沭县| 青铜峡市| 南阳市| 湟源县| 北宁市| 孝昌县| 乐陵市| 瑞金市| 台湾省| 开原市| 恭城| 东方市| 福海县| 克拉玛依市| 平定县| 宁波市| 平潭县| 额尔古纳市| 塔城市| 日土县| 盐城市|