flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Macroinstructions > Help with 'repeat' directive

Author
Thread Post new topic Reply to topic
Nistix



Joined: 10 Jan 2012
Posts: 6
Help with 'repeat' directive
Hi

I invented this code for print dword in hex ascii:

Code:

; Input    
;   eax   dword for print    
;   rdi   buffer    
; Usage    
;   edx    tmp    
PrintToBufferDwordHex:             
repeat 8       
  rol eax,4    
  mov dl,al                            
  and dl,00Fh                          
  cmp dl,00Ah                          
  jb @f                                
  add dl,7                             
@@:                                    
  add dl,'0'                           
  mov [rdi+%-1],dl                     
end repeat                             
                                       
  ret   




But cann't compile:

Code:

@@:
processed@@:
errorsymbol already defined.




Is there a workaround? (Do not use cycle loop or repeat the whole block of instructions manually)
Post 13 Jul 2017, 21:28
View user's profile Send private message ICQ Number Reply with quote
Nistix



Joined: 10 Jan 2012
Posts: 6
Found beautiful solution!



Code:

; Input
;   eax   dword for print
;   rdi   buffer
PrintToBufferDwordHex:
  push rdx
  mov edx,eax
rept 8 n:0 {
  rol eax,4
  mov dl,al  
  and dl,00Fh
  cmp dl,00Ah
  jb @f   
  add dl,7
@@:         
  add dl,'0'        
  mov [rdi+n],dl
}
  pop rdx
  ret


Post 13 Jul 2017, 21:56
View user's profile Send private message ICQ Number Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 72
Location: Belarus

Nistix wrote:
Found beautiful solution!

Code:
...



Why not just use plain assembler loops? 8 times more code might in most cases be worse than a small loop.
Post 16 Jul 2017, 09:09
View user's profile Send private message Reply with quote
Nistix



Joined: 10 Jan 2012
Posts: 6

DimonSoft wrote:

Why not just use plain assembler loops? 8 times more code might in most cases be worse than a small loop.


Yes, you are right. I had make this optimized code:

Code:

; Input    
;   eax   dword for print    
;   rdi   buffer    
PrintToBufferHexDWord:    
  push rcx rdx    
  mov ecx,8    
align 16    
.char:    
  shl rdx,8    
  mov dl,al    
  and dl,00Fh    
  cmp dl,00Ah    
  jb @f    
  add dl,'A'-'9'-1                              ; 7    
@@:    
  add dl,'0'    
  ror eax,4    
  loop .char    
  mov [rdi],rdx    
  pop rdx rcx    
  ret    




It works fine Very Happy
Post 16 Jul 2017, 16:04
View user's profile Send private message ICQ Number 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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.