In line Machine code

Started by Baggey, December 16, 2024, 10:03:34

Previous topic - Next topic

Baggey

@Derron

Is there a way to have Inline Machine Code in BlitzmaxNG
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!

Derron

I only know of inline C code.

And to inline ASM you would possible be able to use "__asm__(...)" in the C code.

print "now comes inline c with asm:"
'! __asm__ ("movl %eax, %ebx\n\t"
'!           "movl $56, %esi\n\t"
'!           "movl %ecx, $label(%edx,%ebx,$4)\n\t"
'!           "movb %ah, (%ebx)");
print "...done"


bye
Ron

Dabz

#2
Just for ze referonceeeee... If your ever using VC++ tools, and you want the same(ish), you do something like:-

__asm {

mov eax, edx
add eax, 2
}

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Baggey

Thanks,

Could someone put that into something that i could run in BlitmazNG I don't always see the obvious. :-[

I need to be slapped across the face with a big FISH!? :-X

Kind regards Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!

Dabz

#4
Lol, I'm the same right now, I'm looking at a problem, and my head is just farting off egg! :D

Anyway, like Derron says, a line of 'inline C' starts with '!

So if you open a new file, and put:-

'!printf("Hello");
It will compile and print "Hello"

So, as you can see '! gets you into C, and then you write your assembly within __asm__ brackets formatting it like Derron has, though don't quote me on that as I'm not sure as Derrons example throws an error on my setup. But whatever you do, don't forget the semi-colon after closing the statement/expression.

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Dabz

#5
This actually builds and runs in BMXNG:-

Print "now comes inline c with asm:"
'!__asm__("movl %edx, %eax\n\t"
'!       "addl $2, %eax\n\t");
Print "...done"

So, yeah, that's the angle you need to go.

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Baggey

Quote from: Dabz on December 16, 2024, 15:55:11Lol, I'm the same right now, I'm looking at a problem, and my head is just farting off egg! :D

Anyway, like Derron says, a line of 'inline C' starts with '!

So if you open a new file, and put:-

'!printf("Hello");
It will compile and print "Hello"

So, as you can see '! gets you into C, and then you write your assembly within __asm__ brackets formatting it like Derron has, though don't quote me on that as I'm not sure as Derrons example throws an error on my setup. But whatever you do, don't forget the semi-colon after closing the statement/expression.

Dabz
WOW so i can use 'C' with '! as well as asm 8)

i ran the example but i get compile errors on my setup!? What build settings did you use!

Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!

Dabz

My little example built and ran, it didnt do much, it printed the strings outside of the inline C, and there's nothing really to show there for the ASM part other then there was no errors.

I'm on another PC now but it would of been set for Win32 and x86

Dabz

Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

GW

You can also import functions and run them that way

SuperStrict
Framework brl.basic
Import "test.s"
Extern
Function myasmfunc%()
EndExtern
Print myasmfunc()

Rem -=[ test.s ]=-

.global myasmfunc
#.type myasmfunc, @function

myasmfunc:
    mov $42, %rax
    ret

EndRem


Baggey

Quote from: GW on December 29, 2024, 20:43:26You can also import functions and run them that way

SuperStrict
Framework brl.basic
Import "test.s"
Extern
Function myasmfunc%()
EndExtern
Print myasmfunc()

Rem -=[ test.s ]=-

.global myasmfunc
#.type myasmfunc, @function

myasmfunc:
    mov $42, %rax
    ret

EndRem


BlitzmaxNG keeps on getting even better and better!
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!