flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > movc/endc to move block of code to a spec. location

Author
Thread Post new topic Reply to topic
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode 24 Jul 2008, 14:37
With Fasm 1.67, i can move previously declared blocks of code
to a specified location thank to this kind of macro (and the
flexibility of Fasm!):

movc/endc
Code:
aBlockList equ
macro realize_item [value] { 
  value
       }
macro realize_rept argList  {
        match items,argList     \{
            realize_item items
          \}
 }                             

macro movc arg,blockname  {
                    
    add_to_list aBlockList,blockname
    local p1,p2
p1:  
    jmp p2
      mov eax,arg
 macro blockname \{
p2:
 mov eax,p2-p1
 }        

endc fix }
     

        start:
  nop
 nop
 movc 1111h,my_blockname
             xor eax,eax
         xor ecx,ecx
         xor edx,edx
         ret
 endc
        nop
         nop
 movc 2222h,your_blockname
           mul eax
             mul ecx
             mul edx
             ret
 endc
        nop
 nop                     
    ret
                         
    .block_starts:
          realize_rept aBlockList

    


and the output
Code:
Section .code (0x00402000) with PEBrowser

01 0x402000: 90                 NOP                            
02 0x402001: 90                 NOP                            
03 0x402002: EB11               JMP         0x402015           ; (*+0x13)  
04 0x402004: B811110000         MOV         EAX,0x1111         
05 0x402009: 90                 NOP                            
06 0x40200A: 90                 NOP                            
07 0x40200B: EB14               JMP         0x402021           ; (*+0x16)  
08 0x40200D: B822220000         MOV         EAX,0x2222         
09 0x402012: 90                 NOP                            
10 0x402013: 90                 NOP                            
11 0x402014: C3                 RET                            
12 0x402015: B813000000         MOV         EAX,0x13           ; <==0x00402002(*-0x13) 19 bytes
13 0x40201A: 31C0               XOR         EAX,EAX            
14 0x40201C: 31C9               XOR         ECX,ECX            
15 0x40201E: 31D2               XOR         EDX,EDX            
16 0x402020: C3                 RET                            
17 0x402021: B816000000         MOV         EAX,0x16           ; <==0x0040200B(*-0x16) 22 bytes ?
18 0x402026: F7E0               MUL         EAX                
19 0x402028: F7E1               MUL         ECX                
20 0x40202A: F7E2               MUL         EDX                
21 0x40202C: C3                 RET                            
22 0x40202D: 0000               ADD         BYTE PTR [EAX],AL  
23 0x40202F: 0000               ADD         BYTE PTR [EAX],AL  
...
    

But the one and only question :

Why on line 12 the bytes ar 19 (it is right so!) and
on line 17 the bytes ar 22 for two blocks of code of the same size?
But Fasm is really no limits!

Fasm, NO LIMITS !!!
hopcode[mrk]
Post 24 Jul 2008, 14:37
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 19 Sep 2008, 21:45
And what do you expect? Hint: even with this modification
Code:
        movc 2222h,your_blockname
                rd  1000000
                mul eax
                mul ecx
                mul edx
                ret
        endc    
there would be 0x16 @0x402022...
Post 19 Sep 2008, 21:45
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.