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

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.

主站蜘蛛池模板: 西峡县| 黄浦区| 水富县| 西和县| 崇州市| 三台县| 阜平县| 甘谷县| 大连市| 璧山县| 滦南县| 玉门市| 永丰县| 库车县| 阜城县| 龙海市| 南江县| 玉龙| 芜湖市| 中江县| 马山县| 闸北区| 桐城市| 保亭| 赤峰市| 青冈县| 宁波市| 黑山县| 保定市| 深水埗区| 西和县| 垫江县| 肥城市| 清苑县| 千阳县| 饶平县| 石河子市| 保亭| 原阳县| 岱山县| 固安县|