home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.asm.x86      Ahh, the lost art of x86 assembly      4,675 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 4,012 of 4,675   
   JJ to none   
   Re: Why does adding a 49 prefix to this    
   08 Mar 20 12:23:02   
   
   XPost: comp.lang.forth   
   From: jj4public@nospicedham.vfemail.net   
      
   On 07 Mar 2020 10:39:51 GMT, none wrote:   
   > I have an 64 bits Forth system, and I can add a program that   
   > executes a single instruction, like so   
   > "   
   > WANT ASSEMBLERi86   
   >   
   > CODE PIET   
   >  MOVI|X, AX| 2 IL,   
   > NEXT,   
   > END-CODE   
   > "   
   >   
   > And execute it like so   
   > PIET OK   
   >   
   > This program does nothing. It fills EAX with 2 which is inconsequential   
   > because EAX is a free register. [Only SP BP and SI are used in the   
   > virtual system.]   
   > Now let us prefix the instruction, such that the alternate register set   
   > is used. This should be likewise inconsequential.   
   >   
   > CODE PIET1   
   > $49 C,   \ That is the way to do that in Forth   
   >  MOVI|X, AX| 2 IL,   
   > NEXT,   
   > END-CODE   
   >   
   > Now PIET1 leads to a segfault.   
   > I've no clue what could cause this.   
   >   
   > I have been working with those prefixes for ages.   
   > My ciasdis has disassembled and reassembled a 64 bit elf program   
   > without problems.   
   > [ This is in the context of an optimiser, I seem to have used   
   > this R1 in optimised programs, that work. ]   
   >   
   > Groetjes Albert   
      
   Inserting that 0x49 opcode would change the instruction functionality from:   
      
     mov eax, <32-bit immediate value>   
      
   To:   
      
     mov r8, <64-bit immediate value>   
      
   As well as changing the instruction length from 5 bytes, to 10 bytes.   
      
   So, the 4 bytes following the `mov eax, ` instruction are the upper   
   32-bits of the `mov r8, `.   
      
   If the generated code is like this:   
      
     49               db  49h   
     B8 02 00 00 00   mov eax, 2   
     C3               ret   
     90               nop   
     90               nop   
     90               nop   
      
   It will be interpreted as:   
      
     49 B8 02 00 00 00 C3 90 90 90   mov r8, 909090C300000002   
      
   Where the following instruction is no longer a `RET` instruction. So, it   
   won't immediately return to the caller. When executed, the result would be   
   unpredictable and eventually ends up crashing the program, because we don't   
   know what data follows that instruction.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca