flat assembler
Message board for the users of flat assembler.

Index > Windows > Simple problem

Author
Thread Post new topic Reply to topic
HtLrR



Joined: 04 Aug 2009
Posts: 5
HtLrR 04 Aug 2009, 01:03
hi every body

I'm begging with assembly

I have simple question

look at the picture

Image

and this my Answer

Code:
.386
.model flat ,stdcall
OPTION CASEMAP:NONE
include windows.inc
include kernel32.inc
include masm32.inc
includelib kernel32.lib
includelib masm32.lib
.DATA
MasgName db "Enter the name  ",0
endl db 00ah,00dh ,0
good db " good name",0
Exit db "Exit   ",0

.DATA?
name1 db ?
.code
start:

invoke StdOut ,addr MasgName
invoke StdIn,addr name1,10
invoke StdOut ,addr name1
invoke StdOut ,addr good
invoke StdOut ,addr endl
invoke StdOut ,addr Exit
invoke StdIn,addr name1,100

invoke ExitProcess,0
end start
    
Post 04 Aug 2009, 01:03
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 04 Aug 2009, 05:41
so, where is the question exactly? some tips:

1.
Code:
name1 db 16 dup(?)
    

2.
Code:
invoke StdIn,addr name1,10
mov [name1 + eax - 2],0 ; removing trailing 0Dh,0Ah
invoke StdOut ,addr name1
invoke StdOut ,addr good
    

3.it is MASM, while here is FASM board Wink
4.
Code:
endl db 00dh,00ah,0
    
Post 04 Aug 2009, 05:41
View user's profile Send private message Visit poster's website Reply with quote
HtLrR



Joined: 04 Aug 2009
Posts: 5
HtLrR 04 Aug 2009, 12:20
Thank you for quick reply

if you can't see the picture Smile

this is a question
I- write a console program that receive the name of the user then print it , like this :
Image
note that the program should take the name then print it followed by the sentence "is da best" .
thanks it work now Smile but how..!!!!

if you can explain this Embarassed

Code:
mov [name1 + eax - 2],0 ;    


Sorry ...... Crying or Very sad
Post 04 Aug 2009, 12:20
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 04 Aug 2009, 12:34
you said: "this my Answer" - with this i've supposed that you have wrote that code.
even if not it is working code and there is no need to be a genius to understand how does it work and what to change to get "is da best" there.

do not mix "help" and "do it all instead of me"

mov [name1 + eax - 2],0 - string after StdIn (eg. name) will have "end of line" in the end (two bytes 0Dh,0Ah). since StdIn returns entered striing length in eax, it is ease to cut off this eol (put "0" there)
Post 04 Aug 2009, 12:34
View user's profile Send private message Visit poster's website Reply with quote
HtLrR



Joined: 04 Aug 2009
Posts: 5
HtLrR 04 Aug 2009, 22:56
thanks for your help Smile

if you please what's the different between

Code:
name1 db 16 dup(?)     


and

Code:
name1 db ?    



Smile)
Post 04 Aug 2009, 22:56
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 05 Aug 2009, 04:28
name1 db ? allocates one uninitialized byte
name1 db 16 dup(?) allocates 16 uninitialized bytes

you need at least 10 to fit entered name (StdIn,10)

the original code does not fails due to spare space between sections. if in original code name1 were followed with another data, it would be destroyed while entering name there
Post 05 Aug 2009, 04:28
View user's profile Send private message Visit poster's website Reply with quote
HtLrR



Joined: 04 Aug 2009
Posts: 5
HtLrR 06 Aug 2009, 11:04
Thanks shoorick
Post 06 Aug 2009, 11:04
View user's profile Send private message Reply with quote
Pirata Derek



Joined: 31 Oct 2008
Posts: 259
Location: Italy
Pirata Derek 27 Aug 2009, 17:27
Also you can use the "Reserve" declaration:
Code:
rb 10 ; reserve 10 uninizialized bytes
rw 3 ; reserve 3 uninizialized words (3 x 2 btyes)
rd 1 ; reserve 1 double word    

They have the same function as:
Code:
db 5 dup (?) ; equivalent to rb 5    

Also if you put all the reserved data in the end of a section
you can assemble a file smaller than you imagine!!!

This program will be 1024 bytes...
Code:
; Demonstration 1
Format PE GUI 5.0
entry start
section '.code' code readable executable
start: ret ; simply exit process

JUNK rb 10000h ; the reserved INVISIBLE data    

But this one will be 66560 bytes!
Code:
; Demonstration 2
Format PE GUI 5.0
entry start
section '.code' code readable executable
start: ret ; simply exit process

JUNK rb 10000h
var_1 db 0 ; this will increase the size to declare itself    
Post 27 Aug 2009, 17:27
View user's profile Send private message Send e-mail Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael 27 Aug 2009, 18:11
Pirata, it won't even compile - look at first post, HtLrR is using MASM, not FASM (very stupid idea IMO).
Post 27 Aug 2009, 18:11
View user's profile Send private message Reply with quote
Pirata Derek



Joined: 31 Oct 2008
Posts: 259
Location: Italy
Pirata Derek 27 Aug 2009, 18:31
Yes, you're right Embarassed

But it can always be a valid help for who don't know or doesn't use the Reserve declaration in fasm.

There're much more people that can read that post and learn something from it.
Post 27 Aug 2009, 18:31
View user's profile Send private message Send e-mail Reply with quote
HtLrR



Joined: 04 Aug 2009
Posts: 5
HtLrR 29 Aug 2009, 14:17
thanks Pirata Derek i will try to understand it
Post 29 Aug 2009, 14:17
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.