Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Dword To Hex Conversion in MASM

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Sean1337
Master Cheater
Reputation: 0

Joined: 04 May 2007
Posts: 478

PostPosted: Mon Aug 06, 2007 12:22 am    Post subject: Dword To Hex Conversion in MASM Reply with quote

Hey,

I've been trying to convert a dword to hexa for the past few hours and haven't really succeeded.

Basically what I'm doing is this.

I get a value (type dword) from a pointer.

My objective is to convert this dword to hexadecimal. E.g. if value is 16, I want to convert it to 10 in hex.

I'm not exactly sure how one might do this in MASM32 since I only started probably a few months back, but I do know, in visual basic you can use the modulus and integer division operators to do it. I.e.

16 div 16 = 1
16 mod 16 = 0 (remainder)

1 div 16 = 0
1 mod 16 = 1 (remainder)

Reading remainder's backwards, decimal 16 = hexadecimal 10.

Does anyone know how to do this in MASM32? I'd greatly appreciate it.

Thanks,
-Sean
Back to top
View user's profile Send private message
opcode0x90
Cheater
Reputation: 0

Joined: 05 Aug 2006
Posts: 27

PostPosted: Mon Aug 06, 2007 1:31 am    Post subject: Reply with quote

Code:

.data
   lpHexString   db "0123456789ABCDEF"
.code
   
   Dec2Hex proc dwValue:DWORD, lpBuffer:DWORD
      
      mov edi, lpBuffer
      mov eax, dwValue
      mov ecx, 8
      
      .repeat
         mov esi, eax
         and esi, 0F0000000h
         shr esi, 28

         movzx edx, byte ptr [lpHexString+esi]
         mov byte ptr [edi], dl
         
         shl eax, 4
         inc edi
      .untilcxz
      
      ret
      
   Dec2Hex endp


Example:
Code:

invoke Dec2Hex, 1337C0DEh, addr lpBuffer
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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

CE Wiki   IRC (#CEF)   Twitter
Third party websites