News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

!£*$!^*%$ HEX

Started by oex, March 18, 2010, 09:57:43 PM

Previous topic - Next topic

oex

bin2hex function

Masm Help
"The output data is *approximately* 3 times longer than the source data as it uses 2 characters plus a space for every byte in HEX format. The destination buffer should be at least 3 times the length of the source buffer to hold the result."

* Except for where it adds ' - ' every 8 bytes of data and a newline every 16 bytes of data :lol  :P
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

hutch--

Simple, make the buffer 4 times longer.  :bg
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

oex

:lol that was my solution too after a lot of head scratching and bit twiddling, then I just gave up altogether and decided to dump hex, never liked it anyways :bg
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

dedndave

hex = good stuff   :P

oex

Hex is 'normal' if you have 16 fingers :lol.... I have never learnt to read it properly, I'm getting better as the years go by but I still prefer a 192 or 224, no conversion required. It has it's uses, I use it sometimes in debug but you can tell how little by my finding that issue with the hex function.... I've only ever converted 1 byte at a time with it before in the past :lol.
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

BlackVortex

Hex rocks ! I remember one of the early problems while assembling was that masm assumes decimal for numbers, I found it weird and lame.

Also, what do you guys think about :

@Dword2String:
;eax = dword to convert
;edi = source label
; result is the start of the string, in edi
mov ecx,0Ah
add edi, ecx

.loop
xor edx,edx
div ecx
dec edi
add dl,30h
mov B[edi],dl
or eax,eax
jnz <.loop
ret


I've got it in my collection, I don't remember if it's mine, lol. I use it to print the contents of registers.

clive

Quote from: BlackVortex
Also, what do you guys think about :

Doesn't really handle the leading characters very well, if the buffer isn't cleared with spaces you'll just have random junk.

An alternative variable length C string implementation.


  mov ecx,10
  push  0

divloop:
  xor edx,edx
  div ecx
  add edx,30h
  push  edx
  or  eax,eax
  jnz divloop

outloop:
  pop eax
  mov byte ptr [edi],al ; or stosb
  inc edi
  or  eax,eax
  jnz outloop


or without trailing NUL


  mov ecx,10
  push  0

divloop:
  xor edx,edx
  div ecx
  add edx,30h
  push  edx
  or  eax,eax
  jnz divloop

  pop eax
outloop:
  mov byte ptr [edi],al
  pop eax
  inc edi
  or  eax,eax
  jnz outloop


-Clive
It could be a random act of randomness. Those happen a lot as well.

drizz

Quote from: BlackVortex on March 19, 2010, 07:17:08 PMHex rocks ! I remember one of the early problems while assembling was that masm assumes decimal for numbers, I found it weird and lame.
Default radix is 10, use .radix directive to change it.
pushcontext radix
.radix 16
mov eax,0C0DE
mov eax,10d
mov eax,101y
mov eax,7t
popcontext radix
The truth cannot be learned ... it can only be recognized.

joemc

Quote from: drizz on March 19, 2010, 08:19:53 PM
Default radix is 10, use .radix directive to change it.
pushcontext radix
.radix 16

to change the radix back without the pop is it :

.radix A

or

.radix 10

? :)

i prefer the 0x0A notation to 0Ah myself. 

Ghandi

Preference or not, with MASM we have to use the leading '0' and trailing 'h' don't we? I've still not successfully used the '0x' notation with MASM, i must be using it wrong.

HR,
Ghandi

joemc

Quote from: Ghandi on March 29, 2010, 03:20:34 PM
Preference or not, with MASM we have to use the leading '0' and trailing 'h' don't we? I've still not successfully used the '0x' notation with MASM, i must be using it wrong.

HR,
Ghandi
could always make a short pre-processor.

Ghandi

Sorry i should clarify. When changing the radix from 10 to 16 (0x10), it is expecting a decimal input. Once the radix is changed, it will accept hexadecimal input but you still need to lead A-F with a '0' otherwise it will complain about an undefined symbol. I'm not entirely sure a pre-processor is necessary really, you only need change the radix as you need and then its done but if its something you wish to pursue, by all means. :D

HR,
Ghandi

vanjast

Ohh...HEX... I thought you said SEX.. I must wear my reading glasses
sorry.. wrong forum :)