flat assembler
Message board for the users of flat assembler.

Index > Windows > how to take a string from user?

Author
Thread Post new topic Reply to topic
vicky



Joined: 22 Dec 2010
Posts: 9
vicky 22 Dec 2010, 21:39
Hi,
I need a code that takes string from user and i'll use it to seperate the string char by char and write it on screen again. Can anyone help or give some advises?
Post 22 Dec 2010, 21:39
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 22 Dec 2010, 22:07
Use GetDlgItemText on your editbox's ID. It will store the data in the buffer you pass it. When you're done precessing the data (in the buffer), use MessageBox to display it. Couldn't get any easier.

I have no idea what you mean by "seperate the string char by char" though.
Post 22 Dec 2010, 22:07
View user's profile Send private message Reply with quote
vicky



Joined: 22 Dec 2010
Posts: 9
vicky 22 Dec 2010, 22:15
ok, the english i use maybe isn't perfect Smile So i meant that i'll write the string char by char on the screen.
Like:
v
i
c
k
y

Thanks for reply SmileI'm looking on that text.
Post 22 Dec 2010, 22:15
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 22 Dec 2010, 23:54
So you just want to put every input character on its own line?

Use 2 buffers: the first will be used by GetDlgItemText to store the input data and the second will receive the final data and will be displayed by MessageBox.

You read 1 character from buf1, put it in buf2, insert CR/LF bytes (13, 10) in buf2, move to the next position in buf1 and repeat until NULL is reached in buf1.

You can do that using either mov and inc instructions or string manipulation instructions lods* and stos*. The latter are highly recommended.

Don't forget to zero-terminate buf2 and make sure you avoid buffer overflows.
Post 22 Dec 2010, 23:54
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20520
Location: In your JS exploiting you and your system
revolution 23 Dec 2010, 00:26
vicky: Are you sure you want to ask this in the Windows section? Your other thread has DOS code so I wonder if you really wanted DOS advice instead.
Post 23 Dec 2010, 00:26
View user's profile Send private message Visit poster's website Reply with quote
vicky



Joined: 22 Dec 2010
Posts: 9
vicky 23 Dec 2010, 11:54
I really don't know what should i do. I don't have an idea about FASM. It's our instructor's surprise to us. So i don't know what to do, trying to learn. And i have only one day to learn too. So that's like a torture for me Sad
Post 23 Dec 2010, 11:54
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 23 Dec 2010, 12:09
You could start by telling us exactly what OS you are supposed to run code on.
You're posting in the Windows forum and you have DOS code in another thread. fasm writes *nix ELFs too. So which one is it?

Or is the OS-dependent interface unimportant and all that matters is the algorithm?

If we write the code for you and you don't understand it, how are you going to answer the instructor tomorrow when s/he asks you why you did "this" that way or asks you to modify the code to do something else or differently?


Last edited by ManOfSteel on 23 Dec 2010, 12:25; edited 2 times in total
Post 23 Dec 2010, 12:09
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 23 Dec 2010, 12:21
vicky wrote:
It's our instructor's surprise to us.


Interesting, what is this school where FASM is studied?
Post 23 Dec 2010, 12:21
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
vicky



Joined: 22 Dec 2010
Posts: 9
vicky 23 Dec 2010, 12:40
Ok i wrote the code and works in FASM now but our instructor wanted that our code should work in 32 bit windows OS. So is it ok?

Code:

org  100h


macro print_new_line  {
    mov dl, 13
    mov ah, 02
    int 21h   
    mov dl, 10
    mov ah, 02
    int 21h      

    }
    mov dx, msg1
    mov ah, 09
    int 21h
    ; input the string:
    mov dx, s1
    mov ah, 0ah
    int 21h
    mov di,dx
    ; get actual string size:
    xor cx, cx
    mov cl,[di+1]
    print_new_line
                  

print_char:
    mov dl, [di+2]
    mov ah, 2
    int 21h      
    print_new_line   
    inc di
    loop print_char


    ; wait for any key...
    mov ax, 0 
    int 16h
    
    ret


msg1    db  "ENTER THE STRING: $"
s1      db 100,?, 100 dup(' ') 



    
Post 23 Dec 2010, 12:40
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 206
Location: Brazil
ctl3d32 23 Dec 2010, 14:37
Hi,

Here it is. See attatched files. Hope it helps.

Thanks,
ctl3d32


Description: Another Update.
Download
Filename: vicky.rar
Filesize: 3.04 KB
Downloaded: 256 Time(s)



Last edited by ctl3d32 on 24 Dec 2010, 21:45; edited 1 time in total
Post 23 Dec 2010, 14:37
View user's profile Send private message Reply with quote
vicky



Joined: 22 Dec 2010
Posts: 9
vicky 23 Dec 2010, 18:08
Wow, that's really good, thank you. but it's so much good Smile The 'instructor' never would believe that this code is mine. How can i insert the vicky.rc and vicky.res in the code?
I tried to put it in the code but it gave error. How can i do that?

Thanks a lot again Smile
Post 23 Dec 2010, 18:08
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 23 Dec 2010, 19:05
When designing algorithms, forget about the target OS or the language or anything else.
Design the algorithm on paper, without any idea of what it will run on.
Then choose the instructions and API to suit the target lastly.
If you cant design the algorithm on paper, it is a waste of time trying to implement it with code.
Just some advice, have fun Smile
Post 23 Dec 2010, 19:05
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 206
Location: Brazil
ctl3d32 23 Dec 2010, 19:49
vicky wrote:
Wow, that's really good, thank you. but it's so much good Smile The 'instructor' never would believe that this code is mine. How can i insert the vicky.rc and vicky.res in the code?
I tried to put it in the code but it gave error. How can i do that?

Thanks a lot again Smile


You can download the resource editor at http://www.oby.ro/rad_asm/ named ResEd. Open the .rc file with it. Make any changes you want than compile it using GoRC, downloadable at http://www.godevtool.com/#rc to make the .res file. The last line of the source code shows how to include the resource file into the source code.

Thanks


Last edited by ctl3d32 on 23 Dec 2010, 22:21; edited 1 time in total
Post 23 Dec 2010, 19:49
View user's profile Send private message Reply with quote
vicky



Joined: 22 Dec 2010
Posts: 9
vicky 23 Dec 2010, 20:48
ok thanks, i'll take a look Smile
Post 23 Dec 2010, 20:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20520
Location: In your JS exploiting you and your system
revolution 24 Dec 2010, 04:16
vicky: You had better hope that your instructor doesn't do a web search and find this thread. Hehe, that might be embarrassing for you. Embarassed
Post 24 Dec 2010, 04:16
View user's profile Send private message Visit poster's website Reply with quote
vicky



Joined: 22 Dec 2010
Posts: 9
vicky 24 Dec 2010, 09:42
revolution: I think that it would be embarrasing for him. He gave such a stupid project that we'll never use, waste of time for us. If i need it in the future i'll eat my word ofcourse, but i don't think so Smile
I don't even know how to use FASM, and everybody uses this way in my class. So if i would try for it with my own effort that would be worse than others, and i'll take bad grades with my own effort. So thanks everyone, helped me Smile
Post 24 Dec 2010, 09:42
View user's profile Send private message Reply with quote
vicky



Joined: 22 Dec 2010
Posts: 9
vicky 24 Dec 2010, 09:47
And maybe i won't send the vicky.rar file to him, maybe i'll send the code that i tried to suit to FASM. But i don't know how can i change it to win32. I'm still trying to do it too.
Post 24 Dec 2010, 09:47
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 206
Location: Brazil
ctl3d32 25 Dec 2010, 01:48
File Updated
Post 25 Dec 2010, 01:48
View user's profile Send private message 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.