Skip to content

Commit b61fa70

Browse files
committed
Add support for NASM assembly
1 parent 47ff341 commit b61fa70

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Currently supported grammars are:
1414

1515
| Grammar | File Based | Selection Based | Required Package | Required in [`PATH`] | Notes |
1616
|:------------------------------------|:-----------|:----------------|:------------------------------|:--------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
17+
| Assembly (NASM) | Yes | Yes | [language-x86-64-assembly] | [`nasm`], [`binutils`] | |
1718
| 1C (BSL) | Yes | | [language-1c-bsl] | [`oscript`] | |
1819
| [Ansible] | Yes | | [language-ansible] | `ansible-playbook` | |
1920
| [AutoHotKey] | Yes | Yes | [language-autohotkey] | `AutoHotKey.exe` | |
@@ -113,11 +114,13 @@ Currently supported grammars are:
113114

114115
[-wow]: https://atom.io/packages/language-lua-wow
115116
[#70]: https://github.com/rgbkrk/atom-script/pull/70
117+
[`binutils`]: https://www.gnu.org/software/binutils/
116118
[`gfortran`]: https://gcc.gnu.org/wiki/GFortran
117119
[`ghc`]: https://haskell.org/ghc
118120
[`guile`]: https://gnu.org/software/guile
119121
[`init` file]: http://flight-manual.atom.io/hacking-atom/sections/the-init-file
120122
[`latexmk`]: https://ctan.org/pkg/latexmk
123+
[`nasm`]: https://nasm.us/
121124
[`oscript`]: http://oscript.io
122125
[`panzer`]: https://github.com/msprev/panzer#readme
123126
[`PATH`]: https://en.wikipedia.org/wiki/PATH_(variable)
@@ -239,6 +242,7 @@ Currently supported grammars are:
239242
[language-swift]: https://atom.io/packages/language-swift
240243
[language-tcltk]: https://atom.io/packages/language-tcltk
241244
[language-vbscript]: https://atom.io/packages/language-vbscript
245+
[language-x86-64-assembly]: https://atom.io/packages/language-x86-64-assembly
242246
[latex]: https://latex-project.org
243247
[lein-exec]: https://github.com/kumarshantanu/lein-exec#readme
244248
[leiningen]: https://leiningen.org
File renamed without changes.

examples/hello.nasm.asm

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
section .data
2+
str: db 'Hello, World!', 10
3+
strlen: equ $ - str
4+
5+
section .text
6+
global _start
7+
8+
_start:
9+
mov eax, 4 ; write system call
10+
mov ebx, 1 ; STDOUT
11+
mov ecx, str ; string
12+
mov edx, strlen ; length
13+
int 80h ; system call
14+
15+
mov eax, 1 ; exit system call
16+
mov ebx, 0 ; error code 0
17+
int 80h ; system call

lib/grammar-utils/operating-system.js

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export default {
2121
return os.platform();
2222
},
2323

24+
architecture() {
25+
return os.arch();
26+
},
27+
2428
release() {
2529
return os.release();
2630
},

lib/grammars/index.coffee

+24
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ path = require 'path'
55
{OperatingSystem, command} = GrammarUtils = require '../grammar-utils'
66

77
os = OperatingSystem.platform()
8+
arch = OperatingSystem.architecture()
89
windows = OperatingSystem.isWindows()
910

1011
module.exports =
@@ -326,3 +327,26 @@ module.exports =
326327
'File Based':
327328
command: 'turing'
328329
args: ({filepath}) -> ['-run', filepath]
330+
331+
"x86 and x86_64 Assembly":
332+
'File Based':
333+
command: 'bash'
334+
args: ({filepath}) ->
335+
args = switch arch
336+
when 'x32'
337+
"nasm -f elf '#{filepath}' -o /tmp/asm.out.o && ld -m elf_i386 /tmp/asm.out.o -o /tmp/asm.out && /tmp/asm.out"
338+
when 'x64'
339+
"nasm -f elf64 '#{filepath}' -o /tmp/asm.out.o && ld /tmp/asm.out.o -o /tmp/asm.out && /tmp/asm.out"
340+
return ['-c', args]
341+
342+
'Selection Based':
343+
command: 'bash'
344+
args: (context) ->
345+
code = context.getCode()
346+
tmpFile = GrammarUtils.createTempFileWithCode(code, '.asm')
347+
args = switch arch
348+
when 'x32'
349+
"nasm -f elf '#{tmpFile}' -o /tmp/asm.out.o && ld -m elf_i386 /tmp/asm.out.o -o /tmp/asm.out && /tmp/asm.out"
350+
when 'x64'
351+
"nasm -f elf64 '#{tmpFile}' -o /tmp/asm.out.o && ld /tmp/asm.out.o -o /tmp/asm.out && /tmp/asm.out"
352+
return ['-c', args]

0 commit comments

Comments
 (0)