Message board for the users of flat assembler.
> Main > HOW to read a byte from a string
I have a buffer with a string in it
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.
|17 Mar 2004, 04:36||
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:
.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 (...)
|17 Mar 2004, 21:28||
buffer rb 0xA000
buffer2 rb 20
cntr rd 1
mov eax, 00000000000000000000000000000000b
mov ebx, 00000000000000000000000000000000b
mov [cntr], 00000000000000000000000000000000b
mov ebx, [cntr]
mov al, byte [buffer + ebx]
cmp al, 0
cinvoke wsprintf, buffer2, fwsp, eax
invoke MessageBox,[hwnd], buffer2,_about_title,MB_OK
thats how i solved my own problem, inskipps way is obviously much more efficient. thank you for you help
|17 Mar 2004, 23:43||
OR AL,AL ;if nul=0
JZ BYE ;X-it
JMP ZZTOP ;short jmp
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...
|18 Mar 2004, 06:27||
Haven't tested it but...
.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
|20 Mar 2004, 00:36||
< Last Thread | Next Thread >
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.