Embedded Assembly Language

Thread Starter

ApacheKid

Joined Jan 12, 2015
1,533
I'm seeking examples of arbitrary yet real-world, embedded assembly language. If people have examples where they use C or some other HLL and embed assembly language (for any target and any assembler syntax) could they post representative snippets here? Nothing huge, just snippets that capture the typical content of such code.

I'm interested in variations and typical usage patterns.
 

Papabravo

Joined Feb 24, 2006
21,159
I'm seeking examples of arbitrary yet real-world, embedded assembly language. If people have examples where they use C or some other HLL and embed assembly language (for any target and any assembler syntax) could they post representative snippets here? Nothing huge, just snippets that capture the typical content of such code.

I'm interested in variations and typical usage patterns.
Here is an example from a long-forgotten project which shows assembly language embedded in a C program. I have other examples of module written in assembly language that were assembled and linked with C modules if those would be of interest. The code is for an ATmega2560.
 

Attachments

Last edited:

cmartinez

Joined Jan 17, 2007
8,220
Here is an example from a long-forgotten project which show assembly language embedded in a C program. I have other examples of module written in assembly language that were assembled and linked with C modules if those would be of interest. The code is for an ATmega2560.
"Kick the Dog" ? :oops:
 

Thread Starter

ApacheKid

Joined Jan 12, 2015
1,533
I'm seeking examples of arbitrary yet real-world, embedded assembly language. If people have examples where they use C or some other HLL and embed assembly language (for any target and any assembler syntax) could they post representative snippets here? Nothing huge, just snippets that capture the typical content of such code.

I'm interested in variations and typical usage patterns.
Thank you, this is just the kind of stuff I'm looking for!
 

BobaMosfet

Joined Jul 1, 2009
2,110
I'm seeking examples of arbitrary yet real-world, embedded assembly language. If people have examples where they use C or some other HLL and embed assembly language (for any target and any assembler syntax) could they post representative snippets here? Nothing huge, just snippets that capture the typical content of such code.

I'm interested in variations and typical usage patterns.
Do you not have access to an inline assembler? Have you just not done this before? (No Judgement, just asking) IMHO there is no 'typical' content of such code. Dropping to assembly is usually done for primarily 4 reasons- space, performance, register safety (preserveration/restoration to operate a code-block safely outside it's segment), or exception handling (like zero-page extensions, memory paging schemes, or jump-table stuff, etc).

I've done a lot of this in 3D game engines, 3D game world-builders/editors, high-end VR simulators, self-modifying code (old school), etc.

What are you trying to achieve? There are ways to provide assembly inline without leaving C or using an inline assembler.
 

Papabravo

Joined Feb 24, 2006
21,159
Here is a 2nd example from some T89C51CC01 (Atmel 8051 derivative with CAN Hardware) code. The C code makes an explicit call to an assembly language function.
 

Attachments

Thread Starter

ApacheKid

Joined Jan 12, 2015
1,533
Do you not have access to an inline assembler? Have you just not done this before? (No Judgement, just asking) IMHO there is no 'typical' content of such code. Dropping to assembly is usually done for primarily 4 reasons- space, performance, register safety (preserveration/restoration to operate a code-block safely outside it's segment), or exception handling (like zero-page extensions, memory paging schemes, or jump-table stuff, etc).

I've done a lot of this in 3D game engines, 3D game world-builders/editors, high-end VR simulators, self-modifying code (old school), etc.

What are you trying to achieve? There are ways to provide assembly inline without leaving C or using an inline assembler.
There are many different ways this is represented by different languages and different vendors for different platforms. Inline assembler is often just string literals along with vendor specific directives and keywords and so on.

So I'm looking at the various real world examples to see if there's general way to represent this in a new language I'm working on.

I want to define this in such a way that its comprehensive enough for different targets and problem domains yet also an inherent defined part of the language rather that being left to implementors.

It's also closely related to the concept of intrinsic so I'm also seeking a possible way to include these too under the same "umbrella".
 

Thread Starter

ApacheKid

Joined Jan 12, 2015
1,533
Interesting, is that Pascal?

Also:

Code:
BEGIN
          CODE(48e7H,0fffeH); (* save regs *)
          currentprocess^.tmpcor:=PROCESS(REGISTER(15));
          SETREG(8,ADR(currentprocess^.ipenvstr));
          CODE(2f08H);  (* move.l a0,-(sp) *)
          SETREG(8,ADR(currentprocess^.iptail));
          CODE(2f08H);  (* move.l a0,-(sp) *)
          SETREG(8,ADR(currentprocess^.ipname));
          CODE(2f08H);  (* move.l a0,-(sp) *)
          CODE(3f3cH,0);    (* move.w #0,-(sp) LOADEXECUTE *)
          CODE(3f3cH,4bH);  (* move.w #4b,-(sp) gemdos EXEC *)
          CODE(4e41H);      (* trap #1 *)
          SETREG(8,currentprocess^.tmpcor);
          CODE(2e48H);   (* move.l a0,a7 *)
          CODE(4cdfH,7fffH); (* restore regs *)
          currentprocess^.return:=INTEGER(REGISTER(0));
          CODE(4e75H);    (* rts *)
END
What exactly are "CODE" and "SETREG" ?
 

Thread Starter

ApacheKid

Joined Jan 12, 2015
1,533
This is the working draft so far:

Code:
procedure breakpoint(X) intrinsic(arm) 

    arg X fixed bin(15)

    asm (section(".vectors")) // optional attributes, like for example a section specifier...
        LDR R1, =#0x20001000    //Load address 0x20001000 to R1 
        LDR R2, =#0h20001004    /* Load address 0x20001004 to R2 */
        LDR R3, =#{X}0o20001008    /* Load address 0x20001008 to R3 */
        STR R0, [R3]            //Store R0 to the address pointing by R3
        STR R0, [R3]            // Store R0 to the address pointing by R3        
        STR R0, [R3]            // Store R0 to the address pointing by R3
    end

end
 

BobaMosfet

Joined Jul 1, 2009
2,110
There are many different ways this is represented by different languages and different vendors for different platforms. Inline assembler is often just string literals along with vendor specific directives and keywords and so on.

So I'm looking at the various real world examples to see if there's general way to represent this in a new language I'm working on.

I want to define this in such a way that its comprehensive enough for different targets and problem domains yet also an inherent defined part of the language rather that being left to implementors.

It's also closely related to the concept of intrinsic so I'm also seeking a possible way to include these too under the same "umbrella".
Um no. I'm referring to C (the ideal high level language for embedded- Pascal works the same, but is a 'dead' language at this point). We're talking an inline assembler. This is an added function of your compiler (if it has it) to allow you to tell it the next text coming is assembly language, not C, and adjust register usage accordingly around what registers you are referencing in assembly so as not to clobber them. It's purpose is to solve the problem you're talking about for a specific processor matching the assembly language, but with less headache than having to manage everything yourself.

And you can see exactly what the compiler did with a dissassembly, if your compiler has that option to see that your 'inline' matches the actually gen'd object code.

I mean, potato po-tat-oh. You can say 'string literals' and I can simply say all your code is nothing but text. Doesn't matter the high-level language. There are several methods for doing assembly language within your code and maintaining its integrity.
 
Last edited:
Top