Okay. So I have this code in intel syntax.

BITS 64

section .text

global asm_proc

asm_proc:
    jmp program

section .data

; b8            - mov rax, <32bit immediate>
; 64 00 00 00   - The number 100 decimal
; C3            - ret

program db 0b8h, 064h, 000h, 000h, 000h, 0c3h

I have the opcodes documented there so you don't have to look them up.

The above code actually does work with a slight modification (moving program to the the .text section).

BITS 64

section .text

global asm_proc

asm_proc:
    jmp program

; b8            - mov rax, <32bit immediate>
; 64 00 00 00   - The number 100 decimal
; C3            - ret
program db 0b8h, 064h, 000h, 000h, 000h, 0c3h

I have this declared in a C file extern uint64_t asm_proc(); and it returns 100 when program is in the .text. section, but Windows crashed the application when program is in the .data section.

Could anyone explain this to me? Maybe a solution to what I am trying to do?

Also is this information correct?

.text - Flags: read & exec
.data - Flags: read | (read & write)
.bss - Flags: Not sure, but I think just read
Heap - Flags: read & write
Stack - Flags: read & write

THANKS! :D

I am doing this to implement JIT into a simple language I designed in C. What I am trying to do is convert bytecode functions into assembly and then run them at runtime. Maybe there is another way to do this? I looked at RunPE, but that is for an exe and so it won't fit this purpose (I think). I would rather it work on Linux and Mac too though.

Okay. I found a way in Windows using VirtualAllocEx and a few other things.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.