flat assembler
Message board for the users of flat assembler.

Index > Main > HOW to read a byte from a string

Author
Thread Post new topic Reply to topic
0x004549554F4C



Joined: 16 Mar 2004
Posts: 14
0x004549554F4C
I have a buffer with a string in it
.data
buffer rb 0xA000
i want to be able to output that string 1 byte at a time to a message box

if someone could give me an example of storing the buffers address, taking the 1st byte from the buffer, converting that byte into a string sending it as the message in a messagebox, and then looping to go through the whole buffer until it gets to the null

I would really appreciate it
i seem to get stuck when i try to put just 1 byte from the buffer into a 1 byte buffer or al etc.
Post 17 Mar 2004, 04:36
View user's profile Send private message Reply with quote
inskipp



Joined: 23 Jun 2003
Posts: 25
Location: Poland
inskipp
A 1 byte string is actually a word, which hi-byte is 0. So you can simply convert a byte to a string using movzx instruction and storing it somewhere in memory. Maybe this code will be helpfull:
Code:


.data

buffer             rb 0xA000
temp_buffer        dw ?

.code
   
    (...)
   
        mov   esi,buffer                ;esi=pointer to first byte in a buffer
output_1byte:   
      movzx   ax,byte[esi]            ;extend the byte to word
    test    ax,ax                   ;end of string?
     jz      end_of_string
       mov     [temp_buffer],ax        ;store word
 invoke  MessageBox,0,temp_buffer,0,0
        inc     esi
 jmp     output_1byte
end_of_string:                              ;done
        
   (...) 
    
Post 17 Mar 2004, 21:28
View user's profile Send private message ICQ Number Reply with quote
0x004549554F4C



Joined: 16 Mar 2004
Posts: 14
0x004549554F4C
.data
buffer rb 0xA000
buffer2 rb 20
cntr rd 1
.code
invoke SendMessage,[edithwnd],WM_GETTEXT,0xA000,buffer
mov eax, 00000000000000000000000000000000b
mov ebx, 00000000000000000000000000000000b
mov [cntr], 00000000000000000000000000000000b
lbl1:
mov ebx, [cntr]
mov al, byte [buffer + ebx]
cmp al, 0
je lbl2
cinvoke wsprintf, buffer2, fwsp, eax
invoke MessageBox,[hwnd], buffer2,_about_title,MB_OK
inc [cntr]
jmp lbl1
lbl2:
jmp finish

thats how i solved my own problem, inskipps way is obviously much more efficient. thank you for you help
Post 17 Mar 2004, 23:43
View user's profile Send private message Reply with quote
Bitdog



Joined: 18 Jan 2004
Posts: 97
Bitdog
ZZTOP:
LODSB
OR AL,AL ;if nul=0
JZ BYE ;X-it
STOSB
JMP ZZTOP ;short jmp
BYE:
------------------------------------
Hello,
at start up, [DS:SI] = source (of string, and)
[ES:DI] = destination = screen address ?
Things don't need to be any more complicated than you want them to be.
KISS = Keep It Simple Stupid
is my motto......'er, the motto I strive for...
Post 18 Mar 2004, 06:27
View user's profile Send private message Reply with quote
VitalOne



Joined: 29 Jul 2003
Posts: 54
Location: USA
VitalOne
Haven't tested it but...

Code:
.data
buffer rb 0xA000
buffer2 db 0,0

.code
mov esi,buffer
one_byte:
lodsb
mov byte[buffer2],al
invoke MessageBox,NULL,buffer2,buffer2,MB_OK
loop one_byte
invoke ExitProcess,0
    
Post 20 Mar 2004, 00:36
View user's profile Send private message AIM Address Yahoo Messenger 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.