News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

binary to ascii

Started by hfheatherfox07, December 21, 2012, 03:44:57 PM

Previous topic - Next topic

hfheatherfox07

Quote from: dedndave on January 01, 2013, 09:27:20 PM
if you look at the masm32 library code (masm32\m32lib), you'll see a few routines that use LUT's
you might get some ideas - using LUT's is quite often the fastest way to do things


Thanks I found 2 LUT,s right off the top ....
argbynum.asm  and ascdump.asm
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

What is bintbl.asm used for ?
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

Donkey

If all you want to do is strip out spaces simply copy the string over itself skipping over the space character

StripSpaces FRAME pszString
uses edi,esi

// copy the string 1 byte at a time
mov edi,[pszString]
mov esi,[pszString]
:
mov al,[edi]
cmp al," "
je >.SKIP
mov [esi],al
inc esi
.SKIP
inc edi
cmp al,0
jne <

ret
endf


The string will have all spaces removed.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

hfheatherfox07

Thank You Donkey!!  :t
I was looking for something like that
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

dedndave

bintbl.asm...
the public symbol is "bintable"
use explorer search tool
look for files in masm32\m32lib containing "bintable"   :P

i get...
b2b_ex.asm
dw2b_ex.asm
w2b_ex.asm

Donkey

No problem hfheatherfox07, I changed the post to include the full procedure I used to test it with.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

hfheatherfox07

For some odd reason it is not working for me ?


;###############################################################################################

        .XCREF
        .NoList
        INCLUDE    \Masm32\Include\Masm32rt.inc
        .List

;###############################################################################################

Char2AscBin PROTO :DWORD,:LPSTR
Sz2AscBin   PROTO :LPSTR,:LPSTR
StripSpaces PROTO :DWORD,:DWORD
;###############################################################################################

        .DATA

szString  db 'Hello Heather',0

;***********************************************************************************************

        .DATA?

szBuffer db 9*(sizeof szString-1) dup(?)
szNewString dd ?
mybuffer dd ?
;###############################################################################################

        .CODE

;***********************************************************************************************

_main   PROC

        mov     edi,offset szBuffer
        mov     esi,offset szString
        INVOKE  Sz2AscBin,esi,edi
        invoke lstrcat, addr mybuffer,edi
        INVOKE  StripSpaces,addr mybuffer,addr szNewString
        INVOKE  MessageBox,HWND_DESKTOP,addr szNewString,esi,MB_OK
        exit

_main   ENDP

;***********************************************************************************************

Char2AscBin PROC USES EDI dwChar:DWORD,lpBuffer:LPSTR

        mov     edx,dwChar
        mov     al,30h
        mov     edi,lpBuffer
        bswap   edx
        mov     ecx,8

ChAsc0: shr     eax,1
        shl     edx,1
        rcl     eax,1
        dec     ecx
        stosb
        jnz     ChAsc0

        xchg    eax,ecx
        stosb
        ret

Char2AscBin ENDP

;***********************************************************************************************

Sz2AscBin PROC USES ESI EDI lpSrc:LPSTR,lpDest:LPSTR

        mov     esi,lpSrc
        mov     edi,lpDest
        jmp short SzAsc1

SzAsc0: INVOKE  Char2AscBin,eax,edi
        add     edi,8
        mov     al,32
        stosb

SzAsc1: lodsb
        or      al,al
        jnz     SzAsc0

        dec     edi
        stosb
        ret

Sz2AscBin ENDP

;###############################################################################################
StripSpaces Proc uses edi esi pszString:DWORD ,pNewString:DWORD


; copy the string 1 byte at a time
mov edi,[pszString]
mov esi,[pNewString]

mov al,[edi]
cmp al," "
je SKIP
mov [esi],al
inc esi
SKIP:
inc edi
cmp al,0
jne SKIP

ret
StripSpaces endp
END     _main

Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

dedndave

your buffers are too small
szNewString dd ?
mybuffer dd ?

those are both 4 bytes long   :P

Donkey

You mistranslated the code I posted as well, should be:

StripSpaces Proc uses edi esi pszString:DWORD ,pNewString:DWORD

; copy the string 1 byte at a time
mov edi,[pszString]
mov esi,[pNewString]

TOPOFLOOP:
mov al,[edi]
cmp al," "
je SKIP
mov [esi],al
inc esi
SKIP:
inc edi
cmp al,0
jne TOPOFLOOP

ret
StripSpaces endp
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

hfheatherfox07

Ya that did it  Donkey  :t...I was wondering why I am looping at the end back to       inc edi
      cmp al,0

Your StripSpaces Proc is a nice proc to have .... Thank you!  :biggrin:


;###############################################################################################

        .XCREF
        .NoList
        INCLUDE    \Masm32\Include\Masm32rt.inc
        .List

;###############################################################################################

Char2AscBin PROTO :DWORD,:LPSTR
Sz2AscBin   PROTO :LPSTR,:LPSTR
StripSpaces PROTO :DWORD,:DWORD
;###############################################################################################

        .DATA

szString  db 'Hello Heather',0

;***********************************************************************************************

        .DATA?

szBuffer db 9*(sizeof szString-1) dup(?)
szNewString db 4096 dup(?)
szMybuffer db 4096 dup(?)
;###############################################################################################

        .CODE

;***********************************************************************************************

_main   PROC

        mov     edi,offset szBuffer
        mov     esi,offset szString
        INVOKE  Sz2AscBin,esi,edi
        invoke lstrcat, addr szMybuffer,edi
        INVOKE  StripSpaces,addr szMybuffer,addr szNewString
        INVOKE  MessageBox,HWND_DESKTOP,addr szNewString,esi,MB_OK
        exit

_main   ENDP

;***********************************************************************************************

Char2AscBin PROC USES EDI dwChar:DWORD,lpBuffer:LPSTR

        mov     edx,dwChar
        mov     al,30h
        mov     edi,lpBuffer
        bswap   edx
        mov     ecx,8

ChAsc0: shr     eax,1
        shl     edx,1
        rcl     eax,1
        dec     ecx
        stosb
        jnz     ChAsc0

        xchg    eax,ecx
        stosb
        ret

Char2AscBin ENDP

;***********************************************************************************************

Sz2AscBin PROC USES ESI EDI lpSrc:LPSTR,lpDest:LPSTR

        mov     esi,lpSrc
        mov     edi,lpDest
        jmp short SzAsc1

SzAsc0: INVOKE  Char2AscBin,eax,edi
        add     edi,8
        mov     al,32
        stosb

SzAsc1: lodsb
        or      al,al
        jnz     SzAsc0

        dec     edi
        stosb
        ret

Sz2AscBin ENDP

;###############################################################################################
StripSpaces Proc uses edi esi pszString:DWORD ,pNewString:DWORD

; copy the string 1 byte at a time
mov edi,[pszString]
mov esi,[pNewString]

TOPOFLOOP:
mov al,[edi]
cmp al," "
je SKIP
mov [esi],al
inc esi
SKIP:
inc edi
cmp al,0
jne TOPOFLOOP

ret
StripSpaces endp
END     _main

Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

Donkey

Quote from: hfheatherfox07 on January 02, 2013, 07:50:32 AM
Your StripSpaces Proc is a nice proc to have .... Thank you!  :biggrin:

Glad to help
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

hfheatherfox07

OK
Back to my original question I am trying to convert Binary text to ASCII
I think the only way to do this is with a look up table
but every time i try to write a look up table I get errors !!
any body know how to write this table ?
It should have 255 entries like  "StringTable" in ascdump.asm from m32lib since The extended ASCII table has 255 entries   http://www.ascii-code.com/   or maybe less

How do I represent for example that 01000001 = A and that 01100001 = a  ?

Thank you !
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

MichaelW

I still don't understand what you are asking, but perhaps it will help if I point out that 01000001b is the ASCII character code for "A", 01000010b the ASCII character code for "B", etc, and that characters are normally specified by their character code. So for example the string "ABC" would be stored as three bytes: 01000001b, 01000010b, 01000011b
Well Microsoft, here's another nice mess you've gotten us into.

hfheatherfox07

I am trying to make a look up table to convert :
01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100 01100100
To: Hello World

Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

MichaelW

Is this a string of binary digits?

01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100 01100100

Or a binary representation of 11 bytes?
Well Microsoft, here's another nice mess you've gotten us into.