5 ms·
global _start section .text _start: mov rax, 1 ; write( mov rdi, 1 ; STDOUT, mov rsi, msg ; msg, mov rdx, len ; sizeof(
by anhldbk 7y ago
global _start
section .text
_start:
mov rax, 1 ; write(
mov rdi, 1 ; STDOUT,
mov rsi, msg ; msg,
mov rdx, len ; sizeof(msg)
syscall ; );
mov rax, 60 ; exit(
mov rdi, 0 ; EXIT_SUCCESS
syscall ; );
section .rodata
msg: db "RIP Tony, Father of Assembly Language", 10
len: equ $ - msg%
- jdswain 7y agoAlways stayed away from Intel assembly, but thought I'd have a go at running this. First issue was this is I think, Intel format, whereas I was using GNU as, so I had to make a few changes: .global _start .text _start: mov $1,%rax # write( mov $1,%rdi # STDOUT, mov $msg,%rsi # msg, mov $len,%rdx # sizeof(msg) syscall # ); mov $60,%rax # exit( mov $0,%rdi # EXIT_SUCCESS syscall # ); .data msg: .ascii "RIP Tony, Father of Assembly Language\n" len = . - msg Then you can run with: gcc -c src.s && ld src.o && ./a.out
- jimws 7y agoI think you can use ".intel_syntax noprefix" with GNU as to assemble Intel assembly.
- anhldbk 7y agoThanks for correcting code :3
- xuejie 7y agoAny chance you can elaborate the reasons for staying away from Intel syntax?
- astrobe_ 7y agoNot OP, but I think it is like indentation styles: you learn it one way, then everything else feels weird and ugly.
- jdswain 7y agoMainly because the assembler I knew I had on my computer was the GNU assembler and it uses that syntax. I did quickly try the .intel_syntax directive but it was just easier to change it around as the code was so short. Most of my assembler experience is with 6502 or ARM.
- molticrystal 7y agoA couple online places to try this and where you can play around with this code. The "%" after msg on the last line seems to cause an error, at least for when I tried it with my version of nasm, so I removed it in the below links. A small website with a few dozen compilers/assemblers, just press F8 or click "Run it" to try the sample above: https://rextester.com/SBEL3962 https://rextester.com/SBEL3962 Hundreds of compilers and assemblers are offered online and configurable with tio.run in a bit of a more complex website, just hit the play button: https://tio.run/##fZAxT8MwFIT3/IpTxdBKKQoLQzKhUqRKSCCSSmzVS@IYS44t/FxI@PEEA2lKFm57/p7P5yNm0Za6XxvidhiktiVpHNiT81HEovLKGlx60YXx9ziNIqC1b3DUxbjCqAzvTnmxPMFazSCQF7cP@yI@cQ68ZXnmYZhgHZy1MCMJYvUhbLMMO6uwwz1XpDXOyrDKZrmuk4mITvlZrORvrO3zrjjk@81mm@f/WE9VOFuTp5@3WKaoSyyedo8orOlj3JF/EQ62wc1YLO7JyCNJsQh1JOFW@FYK8XrEBdbfFsPwWTWaJA9f https://tio.run/##fZAxT8MwFIT3/IpTxdBKKQoLQzKhUqRKSCCSSmzVS@...
- takeda 7y agotitle is wrong it was autocode (precursor of high level languages) not assembly and Brooker not Booker