OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 3:35 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: can i copy compiled asm instructions and jump to it
PostPosted: Sat Sep 17, 2022 4:28 pm 
Offline

Joined: Sat Jun 18, 2022 10:42 am
Posts: 9
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:
┌────────────┐     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


Top
 Profile  
 
 Post subject: Re: can i copy compiled asm instructions and jump to it
PostPosted: Sat Sep 17, 2022 4:54 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Isn't that how all programs get loaded?


Top
 Profile  
 
 Post subject: Re: can i copy compiled asm instructions and jump to it
PostPosted: Sat Sep 17, 2022 5:00 pm 
Offline

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

oh


Top
 Profile  
 
 Post subject: Re: can i copy compiled asm instructions and jump to it
PostPosted: Sat Sep 17, 2022 5:29 pm 
Offline

Joined: Sat Jun 18, 2022 10:42 am
Posts: 9
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


Top
 Profile  
 
 Post subject: Re: can i copy compiled asm instructions and jump to it
PostPosted: Sun Sep 18, 2022 1:20 am 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
 Post subject: Re: can i copy compiled asm instructions and jump to it
PostPosted: Sun Sep 18, 2022 1:22 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
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.


Top
 Profile  
 
 Post subject: Re: can i copy compiled asm instructions and jump to it
PostPosted: Wed Sep 21, 2022 1:45 am 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 118
Quote:
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" :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: DotBot [Bot] and 26 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group