:biggrin:
I have wondered how would a Windows user start to write assembly programs for Linux.
Linux OS needed, certainly - to run the program that is.
But what I want to know is what the programming environment would look like.
What development programs there are, debugging tools, maybe some Linux specific reference materials.
Maybe even tips on the Linux operating system as well. Which one, there are many different 'flavors'?
Serious replies only please, from those that know what is needed. :smiley:
for a beginner like myself, I would do the following
if you don't have the sasm IDE and nasm then install them
if you are a Linux beginner then open the terminal and issue these commands
sudo apt update
sudo apt dist-upgrade
sudo apt install nasm
sudo apt install sasm
some nasm examples https://cs.lmu.edu/~ray/notes/nasmtutorial/
you may need to set the sasm preferences to nasm and x64
:eusa_clap: Thanks jack.
Eeks! :dazzled: What have I gotten myself into? Seems it will be a steep learning curve to be sure. I will have to set aside a few weekends to investigate all of this, if I decide to explore this further. :smiley:
Can you recommend a Linux distro?
I like Zorin OS (https://zorin.com/os/)
Quote from: jack on August 07, 2024, 01:59:49 AMI like Zorin OS (https://zorin.com/os/)
I'll look into that later. :smiley:
OpenSuse is good too, but has a different package manager
Quote from: zedd151 on August 06, 2024, 11:13:30 PMWhat development programs there are, debugging tools, maybe some Linux specific reference materials.
Yeah, good question. Specifically:
- What assembler?
- What linker?
- What debugger?
- What librarian?
- What other programming tools? (make, etc.)
And while we're at it, what editors are good for writing code? (Please, please,
please don't say
vi!)
QuoteUASM 2.56 (Linux 64bit) 27/10/2022 uasm256_linux64.zip 64bit Linux Executable (GCC)
https://www.terraspace.co.uk/uasm.html#p2 (https://www.terraspace.co.uk/uasm.html#p2)
Quotesudo apt update
sudo apt dist-upgrade
sudo apt install nasm
sudo apt install sasm
It should be mentioned that not all Linux distro's use '
apt' as mentioned above.
Different Distro's, use different 'Package Managers' depending on what initial distribution they are based on.
That said, the process is basically the same, although some distro's also provide a Graphical interface as well, like
SuSE.
SuSE was the very first linux distro' I tried, way back and whilst I haven't played with it in a while, it is a very mature and stable product and the founders,
are Zappa fans,.. :smiley: :thumbsup:
I also liked
Zorin OS but can also suggest and recommend Porteus (http://www.porteus.org/) as well :smiley:
FASM has a Linux version (https://flatassembler.net/download.php) and a sub-forum (https://board.flatassembler.net/forum.php?f=4) too.
QuoteAnd while we're at it, what editors are good for writing code? (Please, please, please don't say vi!)
:wink2:
Well, whilst Not a programmer, I am aware of a few Editors,.. NOT vi / vim etc :joking:
Kate (https://kate-editor.org/?ref=itsfoss.com)
Kate stands for KDE Advanced Text Editor.
KDE is a desktop environment (graphical interface) for Linux.
The KDE desktop
isn't required to use Kate – you can install it on Windows, Linux, and Mac.
Kate allows you to edit multiple documents at the same time.
It supports color-coded syntax, customization, and plugins.
Geany (https://www.geany.org/?ref=itsfoss.com)
Geany is a relatively popular text editor and is one of the best Notepad++ alternatives for Linux.
It supports various programming languages (with cross-platform support).
It is fast, powerful, and lightweight.
Easily customizable
Various plugins available
There is also
Visual Studio Code (https://code.visualstudio.com/?ref=itsfoss.com), which may or may not accord with your general outlook on life ... lol It may have issues depending on your distro'.
An interesting and similarly powerful alternative to Visual Studio might be
VSCodium (https://github.com/VSCodium/vscodium?ref=itsfoss.com), definitely worth a look :thumbsup:
Some beginner examples of using nasm on Linux NASM Tutorial (https://cs.lmu.edu/~ray/notes/nasmtutorial/)
I am familiar with the geany IDE and use it for all my fun programming exercises.
I had posted a recommendation for geany to experiment with assembly programming in Linux but I ran into some strange problems which I was unable to resolve at the moment, so I withdrew that post, and recommended sasm instead which did a bit better but it has problems of it's own, for one, no matter how hard I looked for the executable I couldn't find it anywhere.
The examples in the tutorial mentioned above work fine with geany if some minor details are taken care of
if you create a Build command in geany with the following command the examples work
nasm -felf64 "%f" && gcc -no-pie -o %e %e.o -lc
but the gcc compiler is not happy unless you change this
global _start
section .text
_start:
to this
global main
section .note.GNU-stack progbits
section .text
main:
As for what distro' to use, I like Zorin but OpenSuse ThumbleWeed has the more recent dev tools
here is a series of 13 videos on 64-bit Linux programming using yasm COS284 (https://archive.org/details/07-64-bit-intel-assembler-for-linux-course-the-stack-and-functions-7-of-14), about 14 hours altogether
Quote from: zedd151 on August 06, 2024, 11:13:30 PMMaybe even tips on the Linux operating system as well.
A) Linux kernel system calls is all you need to know. Everything else can be derived from that.https://gpages.juszkiewicz.com.pl/syscalls-table/syscalls.html (https://gpages.juszkiewicz.com.pl/syscalls-table/syscalls.html)
You want print some text on a 64 bit x86 CPU, do the following:
1. Look for syscall write() in the list linked above or read
man 2 syscalls
Put its syscall number in register RAX.
You should also read
man 2 write
, so that you know, what is needed next.
2. Set file handle to stdout, which means RDI must be 1.
3. Set address of string in RSI.
4. Set number of bytes of string in RDX.
5. Do the syscall.
Example:
; For an 64 bit x86 machine compile this with:
; nasm -felf64 hello64.asm && ld -m elf_x86_64 hello64.o -o hello64.bin
global _start
section .text
_start: mov rax, 1 ; system call write()
mov rdi, 1 ; file handle 1 is stdout
mov rsi, hello ; set address of string in rsi
mov rdx, 13 ; number of bytes
syscall ; do syscall
mov rax, 60 ; setup system call for exit()
xor rdi, rdi ; set return value to 0
syscall ; do syscall
section .data
hello: db "Hello, World", 10 ; note the newline (10) at the end
B) Linux supports various computer architectures.
For this reason, it makes sense to always write high-level language code, e.g. in C or C++, in addition to assembly code, which can then be used alternatively for other platforms. To do this, use the preprocessor of C or C++. If you want to use another high-level language, e.g. ZIG programming language, find out how to do it there.
You could also download EuroAssembler (https://euroassembler.eu/eadoc/#HelloWorld), save the following example as "hello.asm" and create executable programs for 32 bits and 64 bits at once
with a simple command euroasm hello.asm
EUROASM CPU=x64
HelloL32 PROGRAM Format=ELFX, Entry=Main:, Width=32 ; HelloL32.exe works in 32-bit Linux.
Main: MOV EAX,4 ; Kernel operation sys_write=4.
MOV EBX,1 ; File descriptor of the standard output (console).
MOV ECX,Message ; Address of the message.
MOV EDX,SIZE# Message ; Size of the message.
INT 0x80 ; Invoke the kernel.
MOV EAX,1 ; Kernel operation sys_exit=1.
XOR EBX,EBX ; Returned errorlevel=0.
INT 0x80 ; Invoke the kernel.
Message: DB "Hello, world of %^Width bits in Linux!",10
ENDPROGRAM HelloL32
HelloL64 PROGRAM Format=ELFX, Entry=Main:, Width=64 ; HelloL64.exe works in 64-bit Linux.
Main: MOV RAX,1 ; Kernel operation sys_write=1.
MOV RDI,1 ; File descriptor of the standard output (console).
LEA RSI,[Message] ; Address of the message.
MOV RDX,SIZE# Message ; Size of the message.
SYSCALL ; Invoke the kernel.
MOV RAX,60 ; Kernel operation sys_exit=60.
XOR EDI,EDI ; Returned errorlevel=0.
SYSCALL ; Invoke the kernel.
Message: DB "Hello, world of %^Width bits in Linux!",10
ENDPROGRAM HelloL64
Quote from: vitsoft on September 29, 2024, 03:13:14 AMYou could also download ...
No, but thanx. Personally I have abandoned this endeavor. But that might be of interest to others.