Page 1 of 1

can i copy compiled asm instructions and jump to it

Posted: Sat Sep 17, 2022 4:28 pm
by anthony
in an os could i theoretically copy hexadecimal code of compiled assembly into a space in memory and jump to it

kinda like this

Code: Select all

 ┌────────────┐     jump
 │App Executer├─────────────────────┐
 └────────────┘                     │
                                   │
                                   │
                                   │
                                   │
                                   │
                                   ▼
┌────────────────┐   copy   ┌─────────────┐
│Hexadecimal Code├─────────►│Space for App│
└────────────────┘          └─────────────┘
i thought about it at like 4am when trying to sleep so it probably wont work or only sounds good in theory

Re: can i copy compiled asm instructions and jump to it

Posted: Sat Sep 17, 2022 4:54 pm
by Octocontrabass
Isn't that how all programs get loaded?

Re: can i copy compiled asm instructions and jump to it

Posted: Sat Sep 17, 2022 5:00 pm
by anthony
Octocontrabass wrote:Isn't that how all programs get loaded?
oh

Re: can i copy compiled asm instructions and jump to it

Posted: Sat Sep 17, 2022 5:29 pm
by anthony
so what i did was just have a function which copies a 128-member u16 array to an address (0x4000) and just uses inline assembly to jump into it and it works when copying an array with assembly of just cli hlt

Re: can i copy compiled asm instructions and jump to it

Posted: Sun Sep 18, 2022 1:20 am
by iansjack
Just make sure that any memory references in the code are relative, not absolute.

Re: can i copy compiled asm instructions and jump to it

Posted: Sun Sep 18, 2022 1:22 am
by iansjack
Octocontrabass wrote:Isn't that how all programs get loaded?
Not really. Many program loaders also perform some relocation of memory addresses. Simply copying hex codes places some restrictions on the code being copied.

Re: can i copy compiled asm instructions and jump to it

Posted: Wed Sep 21, 2022 1:45 am
by davmac314
in an os could i theoretically copy hexadecimal code of compiled assembly into a space in memory and jump to it
I think you mean "data representing compiled assembly". It's not hexadecimal nor any other base; it's just data. Don't use "hexadecimal" to mean "data" :)