News:

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

[new question] string processing

Started by JayJay, December 14, 2011, 08:00:32 PM

Previous topic - Next topic

JayJay

Hellow,

I got a question. Could somebody explain me a little more about string processing? Because i read a lot. Bot on the forum and in books but one thing is still unclear to me and that i want to declare a byte in a proc/function so i could use it.

lets say for example

main PROC
      var1 db "test",0
      invoke  MessageBox,0,ustr$(ebx),ADDR capt,MB_OK
      ret
main ENDP


This will cause my program to crash.

I only see examples of bytes that are defined in the .data segment. But what if i don't have a fixed number of strings? That's why i want to use it in a PROC.


jj2007

You are declaring a variable var1 that you don't use. Why?

JayJay

ow sorry.


main PROC
      var1 db "test",0
      invoke  MessageBox,0,ustr$(ebx),ADDR var1,MB_OK
      ret
main ENDP



the code needs to be like this

FORTRANS

Hi,

   The way you declared var1 will result in it being executed as
the first part of your program.  Put it in a data section or after
the return.

Steve

JayJay

Hi steve. Thank you for your reply. But i don't want to put it in the data section because then i am stuck to a fixed number of strings that i can use. Can you explain me what you mean by after the return?

clive

I don't understand why you're limited in strings, it is not like you are doing 16-bit coding?

Put the data AFTER the last RET instruction.

Or bracket it between a .DATA and .CODE within the PROC

main PROC
      invoke  MessageBox,0,ustr$(ebx),ADDR var1,MB_OK
      ret
      var1 db "test",0
main ENDP


main PROC
.DATA
      var1 db "test",0
.CODE
      invoke  MessageBox,0,ustr$(ebx),ADDR var1,MB_OK
      ret
main ENDP

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

clive

main  PROC
      lea edi,@F
      invoke  MessageBoxA,0,ustr$(ebx),edi,MB_OK
      ret
@@:
      db        "test",0
main  ENDP


Disassembly

00000000                    _main@0:
00000000 8D3D27000000           lea     edi,[$$000027] ; 'test',000h
00000006 6A0A                   push    0Ah
00000008 6830000000             push    offset ??0019
0000000D 53                     push    ebx
0000000E FF150000FFEF           call    dword ptr [__imp___ultoa]
00000014 83C40C                 add     esp,0Ch
00000017 6A00                   push    0
00000019 57                     push    edi
0000001A 6830000000             push    offset ??0019
0000001F 6A00                   push    0
00000021 E8DAFFFDEF             call    _MessageBoxA@16
00000026 C3                     ret

00000027                    $$000027:                   ; Xref 00000000
00000027 7465737400             db      'test',000h
It could be a random act of randomness. Those happen a lot as well.

bomz

Quotejmp label
test db 'my text',0
label:
invoke MessageBox,0,addr test,0,0

bomz

Under DOS code is not write protected. so

; ===============================================================
; ===============================================================
name NONAME
; ===============================================================
;   === Начало программы: ===
CSEG segment
assume cs:cseg, ds:cseg, ss:cseg, es:cseg
org  100h         ; COM файл
; ===============================================================
Start:
   jmp   init      ;на инициализацию резидента
new_16:            ;новая отработка вектора 16
   cmp   ah, 01h      ;
   jne   to_old_16   ;на старый вектор
   pushf
   call   dword ptr cs:old_16 ;на старый вектор
   jz   @F
   pushf   
   mov   cx,0001h   ;старшее слово числа микросекунд паузы
   mov   dx,0000h   ;младшее слово числа микросекунд паузы
   mov   ah,86h      ;функция 86h
   int   15h      ;пауза
   popf
@@:
   iret
to_old_16:
   db      0eah      ;Код межсегментного JMP.  jmp code
old_16   dw      0, 0      ;Адрес старого обработчика.old offset address


init:            ;инициализация программы
   mov   ax, 3516h   ;прочитаем старый вектор
   int   21h
   mov   old_16, bx   ;сохраним в переменной смещение
   mov   old_16+2, es   ;и сегмент
   mov   ax, 2516h   ;установим новый вектор отработки прерывания 16
   lea   dx, new_16   ;адрес нового обработчика
   int   21h
   lea   dx, init   ;последний адрес программы, который оставляем в памяти
   int   27h      ;оставляем резидент в памяти и завершаемся

CSEG ends
end Start
; ===============================================================
; ===============================================================

MichaelW

JayJay,

How could putting your strings in the data section limit you to a "fixed number of strings", and putting them in the code section not limit you to a fixed number of strings?

eschew obfuscation

bomz


var1 must be before place where it used


dedndave

var1    db "test",0

main    PROC
        invoke  MessageBox,0,ustr$(ebx),ADDR var1,MB_OK
        ret
main    ENDP

        END     main


:P

clive

Quote from: bomzvar1 must be before place where it used
touche, but only because the implementation of ADDR sucks, forward references aren't impossible to implement.

But in any case, the repeated use of "var1" or "label" doesn't work either.

I think we can infer from JayJay's request is that he wants to use the same generic string name over and over, so defining it with global scope probably isn't the way to go.
It could be a random act of randomness. Those happen a lot as well.

bomz

I make this examples that he understand what he do only

JayJay

Hi,

I solved the problem by putting it in the .data section. I thought it was not allowed to put a .data section in a proc. I thought it was only allowed at the beginning of your .asm file :lol

Thanks for the help you all!

JayJay