GoSublime icon indicating copy to clipboard operation
GoSublime copied to clipboard

can we have assembler(asm) syntax coloring ?

Open ghost opened this issue 12 years ago • 8 comments

Hi. I have a file.s which looks like this:


//this code is from here: https://groups.google.com/d/msg/golang-nuts/q01oIascmiU/wuoqrF_TOqgJ

TEXT ·FlipByte(SB),7,$0
    MOVQ    addr+0(FP), BP // This gets the address of the byte pointed to. 
    MOVL    0(BP), DX // This stores the byte in DX 
    MOVL    $8, CX // Use the CX register as a loop counter 
    XORL    AX, AX // Clear the AX register, to store the result in

loop: // This is a label to be jumped to.
     SHLB   $1, DX // Shift the byte in DX right, pushing the leftmost bit into the carry flag 
         RCRB   $1, AX // Rotate with carry the value in AX to the left, pushing the bit in the carry flag to the leftmost position in AX. 
     DECB  CX // Decrement the counter by one
     JNZ    loop // Jump to the loop label if the counter isn't zero

MOVL AX, 0(BP) //Move the result back into the address of the byte pointed to (modify the value pointed to by the pointer passed into the function).
RET //Return from the function

Sublime uses R syntax for it, and I don't see any asm or assembler syntaxes. Any ideas ?

Thanks.

ghost avatar Aug 16 '13 11:08 ghost

Try this https://sublime.wbond.net/packages/MasmAssembly

leafy7382 avatar Aug 17 '13 13:08 leafy7382

Thanks, but it kinda looked better before: MasmAssembler syntax: masmassembly

R syntax: r syntax

ghost avatar Aug 17 '13 13:08 ghost

It's just my 2 cents that assembly highlighting shouldn't be handled in GoSublime, given the number of platforms there is out there.

leafy7382 avatar Aug 17 '13 14:08 leafy7382

where can i find documentation for the golang asm? all searches lead directly back to plan9 but i'm almost certain that they've deverged in some way

DisposaBoy avatar Aug 17 '13 14:08 DisposaBoy

@DisposaBoy I would tell you but I've no idea (didn't even try to search for it, but I assumed it's in the go docs somewhere and I'll eventually get to them after I learn the Go basics) since I'm new to Go and all the asm info that I got was from Jonathan Barnard (whose github account I can't find to link here)

ghost avatar Aug 17 '13 15:08 ghost

This might be relevant: http://golang.org/src/cmd/vet/asmdecl.go?h=assembly at line 70 it has some regexps for parsing asm files

ghost avatar Aug 17 '13 15:08 ghost

@DisposaBoy I've asked Jonathan(thanks!) in email and he replied the following (I'm pasting this with his permission) I hope you find this useful, at least with respect to your question:

where can i find documentation for the golang asm?

" I don't think there are any docs about Go's assembly support; I asked one of the devs, and they said just check the source, so I did. In go/src/pkg/, the bytes, runtime, maths and sync/atomic folders all include some assembly files. It appears you can include C header files in the assembly code, like #include "zasm_GOOS_GOARCH.h", and in this case that file contains a heap of '#define's, some of which the assembly files uses, so that's how you can use constants in Go assembly. I found this:

#if defined(__APPLE__)
#define EXT(s) _##s
#else
#define EXT(s) s
#endif

in a gcc_amd64.S, so it seems the assembler files support the C preprocessor directly too. Actually, that particular assembly file uses traditional AT&T syntax, and the filename has a capital S rather than a lower-case s, so maybe Go supports that kind of assembly too somehow? I should mention that as well as assembly Go also supports declaring functions in standard c files, many example of which are available in the source.

To find out what assembly mnemonics Go supports, the easiest way is just to test the instruction you're interested in, and if Go treats it as a syntax error then it's probably not supported. If you want to use an unsupported instruction, you can do so using the bytecode directly, like I did here: here, where BYTE $0x0f; BYTE $0x49; BYTE $0xc1 performs the instruction cmovns %ecx,%eax. The way I got the opcodes was just checking the disassembly of a compiled C executable that already used those instructions. The code at the link was done as an attempt at speeding up a benchmark, but proved ineffective due to the lack of inlining.

One thing I don't yet know about Go assembly is what the last two values in the function declarations mean: TEXT runtime·mcall(SB), 7, $0 I think the final one may have something to do with where the stack taken in starts, as I've seen one where $-8 is used instead, but I've no idea about the 7. All functions seem to use seven for this value, however, so there doesn't seem to be any need at present to understand what it does. "

EDIT: PS: some small sample of using asm: https://github.com/DeMLinkS/demlinks/tree/3ceb1b72219ca738dfaef990c99f28842c3b2e81/poc/asm

EDIT2: an update by Jonathan: " Reading through that source file, it seems assembly files can only be lower case .s, so the upper case .S one may instead have been used by a C file somewhere. "

ghost avatar Aug 18 '13 16:08 ghost

thanks, i'll and try and have look at it this week

DisposaBoy avatar Aug 18 '13 18:08 DisposaBoy