Personal computing discussed

Moderators: renee, SecretSquirrel, just brew it!

 
fc34
Minister of Gerbil Affairs
Topic Author
Posts: 2816
Joined: Wed May 08, 2002 8:39 am
Location: Somewhere

ASM Help

Fri Nov 07, 2003 9:39 am

Hi, being a n00b at ASM, I have a question. I am making a simple Hello World program, compiling under FASM 1.4.3

For some reason, FASM requires a value after each string, like

HELLO db "Hello World!$", 24h

Just wondering what that 24h meant? Cuz its different between strings. The tutorial that I am following dosent even include that, so FASM wont compile the code in the tutorial because its missing that value.
Windows XP - The 64-bit wannabe with a 32-bit graphics interface for 16-bit extensions to a 8-bit patch on a 4-bit operating system designed to run on a 2-bit processor by a company that can't stand 1-bit of competition
 
liquidsquid
Minister of Gerbil Affairs
Posts: 2661
Joined: Wed May 29, 2002 10:49 am
Location: New York
Contact:

Fri Nov 07, 2003 9:51 am

Uh, really don't know. It all depends how you plan to handle displaying strings. Usually a string is terminated with a NULL (00h) so that whatever routine is running through the characters will know to stop there. Perhaps it is for screen formatting like an escape code is under DOS? Tabs, CRLF and form-feeds? I still think you will need a NULL at the end.

Right now that should show up in the object file output as the ASCII characters of the string ending with a 24h value. I'm not sure if it is something PC related in the assembler because all of the assembly I do is in small microcontrollers.

-LS
 
moog
Gerbil Elite
Posts: 868
Joined: Wed Jun 11, 2003 9:10 am

Fri Nov 07, 2003 10:09 am

As liquidsquid said, 24h may be your terminator. Typically it's 00h. Btw, that 24h you got there is actually the $ char (so your string has two $'s, I'm guessing you can remove one of those).
 
muyuubyou
Grand Gerbil Poohbah
Posts: 3222
Joined: Wed Aug 28, 2002 6:19 am
Location: London, UK or Tokyo/Yokohama, Japan or Madrid, Spain

Fri Nov 07, 2003 10:11 am

I don't know FASM but I think that's an interrupt. It's been ages since I coded DOS assembler.

Int 21h function 9 is the one used for printing strings to standard output.

In that line you identify your byte string with the name "HELLO", then Define "Bytes 'Hello World!$' " then after that I guess it's specific FASM syntax.

My guess is it's loading the string in AX and calling Interrupt 24h afterwards.

EDIT: Nah after rereading your message I think the guys are right. Must be the terminator. (you use it for every string, and btw int 24 happens to be DOS critical error handler)
http://www.ctyme.com/intr/int-24.htm
no sig
 
moog
Gerbil Elite
Posts: 868
Joined: Wed Jun 11, 2003 9:10 am

Fri Nov 07, 2003 11:33 am

One thing was right...

That $ terminator is probably because you're going to use int 21 func. 9 to print the string (dos needs a $ to terminate a string).
 
fc34
Minister of Gerbil Affairs
Topic Author
Posts: 2816
Joined: Wed May 08, 2002 8:39 am
Location: Somewhere

Fri Nov 07, 2003 10:53 pm

I read about that stuff.

Heres the Code:

format MZ

   push   cs
   pop   ds

   mov   ah,9
   mov   dx,hello
   int   21h

   mov   ax,4C00h
   int   21h

hello db 'Hello world!',24h


If you say that '$' is the terminator (which is what the tutorial says as well), FASM dosent seem to recognize it. If i change the coding of the last line to:

hello db 'Hello world!$'

FASM gives a compile error
Windows XP - The 64-bit wannabe with a 32-bit graphics interface for 16-bit extensions to a 8-bit patch on a 4-bit operating system designed to run on a 2-bit processor by a company that can't stand 1-bit of competition
 
dgoba
Gerbil In Training
Posts: 1
Joined: Mon Apr 21, 2003 4:28 pm

Sun Nov 09, 2003 2:08 am

fc34, do you have a lot of experience programming?? I ask because I'm not sure that I'd recommend assembly before you understand a high level language. Also, before you even start programming, I'd try to understand some basic ideas (mainly registers and memory addressing). You may want to get familiar with binary(signed and unsigned) and hex number conversions as it will help with your understanding of what is going on with your program. You could also try writting the code out in another language you are familiar with and then convert it to assembly code on paper(before ever typing it in). Basically, understand what is going on before you even try typing it on the computer.

Anyway, here's another way to do that program.
NOTE: as with other languages, there are a million ways to accomplish most tasks in assembly, so don't get hung up with the idea that there is only one solution. After solving the problem, then you can think about code optimization.

   .model small
   .stack 100h
   .data
message   db   "Hello World!", 0dh, 0ah, '$'
   .code
main   proc
   mov   ax, @data   ;start up code
   mov   ds, ax
   mov   ah, 9      ;display string
   mov   dx, offset message
   int   21h
   mov   ax, 4c00h   ;exit code to DOS
   int    21h
main   endp
   end   main


Here are a couple of links to try if you want to continue with x86 asm
http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc/
http://www.azillionmonkeys.com/qed/asm.htm

Remember, google is your friend.

also goto:
http://www.nuvisionmiami.com/books/asm/

If you follow the 'Printable Chapters' link, you will find a couple of introductory chapters of an Assembly text book in PDF form.

Hope this helps. :)
 
sativa
Grand Gerbil Poohbah
Posts: 3044
Joined: Sun Apr 14, 2002 7:22 pm
Location: lafayette, la

Sun Nov 09, 2003 2:24 am

dgoba wrote:
fc34, do you have a lot of experience programming?? I ask because I'm not sure that I'd recommend assembly before you understand a high level language.

Uh oh. i suggested this when he was using pointers out the wazoo in another thread & he got pretty mad :roll:
 
muyuubyou
Grand Gerbil Poohbah
Posts: 3222
Joined: Wed Aug 28, 2002 6:19 am
Location: London, UK or Tokyo/Yokohama, Japan or Madrid, Spain

Sun Nov 09, 2003 6:16 pm

I don't think starting off with ASM is a bad idea... if it's a rather simple instruction set and something else is taking care of the OS management (interruptions used to be enough under OS, CP/M and Unix).
no sig
 
BigMadDrongo
Gerbil Elite
Posts: 909
Joined: Mon Apr 29, 2002 12:57 pm
Location: London, UK
Contact:

Sun Nov 09, 2003 7:52 pm

Depends what kind of programming he's trying to learn really. If he wants to learn to hack (not meaning break into FBI computers, meaning write small, very efficient bits of code that target specific problems) then ASM might not be bad. If he wants to learn to write software, it's probably a terrible starting language, since I'd think you'd learn all kinds of bad habits (not having any looping constructs?! Pointer arithmetic the only way to do function calls?). Not that I'm either an experienced software engineer or hacker myself, so I'm probably talking out of my *rse here.
 
fc34
Minister of Gerbil Affairs
Topic Author
Posts: 2816
Joined: Wed May 08, 2002 8:39 am
Location: Somewhere

Mon Nov 10, 2003 6:56 am

dgoba wrote:
fc34, do you have a lot of experience programming?? I ask because I'm not sure that I'd recommend assembly before you understand a high level language.


I began with C++, but I like the idea or writing in ASM.
Windows XP - The 64-bit wannabe with a 32-bit graphics interface for 16-bit extensions to a 8-bit patch on a 4-bit operating system designed to run on a 2-bit processor by a company that can't stand 1-bit of competition
 
moog
Gerbil Elite
Posts: 868
Joined: Wed Jun 11, 2003 9:10 am

Mon Nov 10, 2003 11:12 am

I'm not familiar with FASM, so I don't know why it would complain about not having the $ char separately at the end.

Is this the case for all strings in FASM? Is there a difference between doing db 'Hello', 24h and db 'Hello', '$'? (you should test it out)

Go ahead and learn assembler, a programmer isn't complete without it. But master C (and C++), it's probably more important (people usually use assembler just to optimize for space/speed, write I/O sw [device drivers etc.], or use mmx/sse instr.).
 
fc34
Minister of Gerbil Affairs
Topic Author
Posts: 2816
Joined: Wed May 08, 2002 8:39 am
Location: Somewhere

Tue Nov 11, 2003 8:56 am

OK...However, I heard some people say that Python is a good language for beginners to learn because its a high language and simple to use yet powerful.
Windows XP - The 64-bit wannabe with a 32-bit graphics interface for 16-bit extensions to a 8-bit patch on a 4-bit operating system designed to run on a 2-bit processor by a company that can't stand 1-bit of competition
 
muyuubyou
Grand Gerbil Poohbah
Posts: 3222
Joined: Wed Aug 28, 2002 6:19 am
Location: London, UK or Tokyo/Yokohama, Japan or Madrid, Spain

Tue Nov 11, 2003 9:05 am

Python is probably the way to go.

OTOH, most people starting off from high level scripting languages rarely learn lower level stuff properly. Some scripting dudes in my office just can't learn decent C or even Pascal. I guess once you get things done without much effort, it's unnatural to go for a more tedious language.
no sig
 
fc34
Minister of Gerbil Affairs
Topic Author
Posts: 2816
Joined: Wed May 08, 2002 8:39 am
Location: Somewhere

Thu Nov 20, 2003 6:04 am

Dunno, ASM just seems much simpler if you bother to remember all those Interrupts. Afterall, there are only like 10 commands which are commonly used.
Windows XP - The 64-bit wannabe with a 32-bit graphics interface for 16-bit extensions to a 8-bit patch on a 4-bit operating system designed to run on a 2-bit processor by a company that can't stand 1-bit of competition
 
muyuubyou
Grand Gerbil Poohbah
Posts: 3222
Joined: Wed Aug 28, 2002 6:19 am
Location: London, UK or Tokyo/Yokohama, Japan or Madrid, Spain

Thu Nov 20, 2003 6:20 am

Errr... the problem is there are much more, and you need complex sequences of them to do even the most trivial stuff. It's pretty frustrating in the beginning. I think I would have never learnt it if I had to do it by myself and coming from higher level languages like Pascal or C. I learnt it because I had to pass the exams clear and simple. I came to like it when I started getting things done.
no sig

Who is online

Users browsing this forum: No registered users and 1 guest
GZIP: On