can i copy compiled asm instructions and jump to it

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
anthony
Posts: 9
Joined: Sat Jun 18, 2022 10:42 am

can i copy compiled asm instructions and jump to it

Post 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
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

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

Post by Octocontrabass »

Isn't that how all programs get loaded?
anthony
Posts: 9
Joined: Sat Jun 18, 2022 10:42 am

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

Post by anthony »

Octocontrabass wrote:Isn't that how all programs get loaded?
oh
anthony
Posts: 9
Joined: Sat Jun 18, 2022 10:42 am

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

Post 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
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post by iansjack »

Just make sure that any memory references in the code are relative, not absolute.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post 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.
davmac314
Member
Member
Posts: 121
Joined: Mon Jul 05, 2021 6:57 pm

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

Post 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" :)
Post Reply