flat assembler
Message board for the users of flat assembler.
Index
> DOS > Hello world console program Goto page 1, 2 Next |
Author |
|
cod3b453 08 Dec 2012, 11:35
This is in the DOS release of FASM under examples\exedemo\:
Code: ; fasm example of writing simple EXE program format MZ push cs pop ds mov ah,9 mov dx,hello int 21h mov ax,4C00h int 21h hello db 'Hello world!',24h |
|||
08 Dec 2012, 11:35 |
|
revolution 08 Dec 2012, 11:37
Lucy: You already have the code for hello world included in "examples" folder in the fasm zip file.
There are also examples for Windows if you are using that instead of DOS. Last edited by revolution on 08 Dec 2012, 11:51; edited 1 time in total |
|||
08 Dec 2012, 11:37 |
|
Lucy Berie 08 Dec 2012, 11:39
Thanks you, cod3b453. But the error :
Code: format MZ Error : Narrow instructions are not encodable in I'd like to know what this error says. How to fix it? |
|||
08 Dec 2012, 11:39 |
|
Lucy Berie 08 Dec 2012, 11:41
Sorry, I should post the post to the "Windows" category.
Thanks all! |
|||
08 Dec 2012, 11:41 |
|
JohnFound 08 Dec 2012, 11:47
You made some mistake. The code provided by cod3b453 compiles without errors.
Provide some details about what you are doing and what is your environment - OS, FASM version, etc. |
|||
08 Dec 2012, 11:47 |
|
revolution 08 Dec 2012, 11:50
Lucy Berie wrote: Thanks you, cod3b453. But the error : http://flatassembler.net/download.php |
|||
08 Dec 2012, 11:50 |
|
Lucy Berie 08 Dec 2012, 12:20
Wow, revolution, thanks a bunch!
I redownloaded the latest version of Flat Assembler and it works fine. My old Flat Assembler : 1.70.03 (I think I chose wrong type) Windows : 86x (Win32) Now it worked all right but the console/cmd closes down instantly. Can you tell me why it is closing down? How to fix it? Thanks you. |
|||
08 Dec 2012, 12:20 |
|
revolution 08 Dec 2012, 12:35
I know of three ways to solve this:
|
|||
08 Dec 2012, 12:35 |
|
AsmGuru62 08 Dec 2012, 12:48
Waiting for key press:
Code: mov ah,0 int 16h It should be inserted before that: Code: mov ax,4C00h int 21h |
|||
08 Dec 2012, 12:48 |
|
Lucy Berie 08 Dec 2012, 12:58
Quote:
The console/cmd program closes down instantly, so how to set the console properties? Or anything else? Quote: Wait for a key press So, I'll need to know how to call a function. There are many functions which can do this : getch, getche, scanf etc... Quote: Manually open a console window... Revolution, thanks you so much! 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 Can you explain this code step-by-step? And how does this code print "Hello World" correctly? |
|||
08 Dec 2012, 12:58 |
|
Lucy Berie 08 Dec 2012, 13:04
Thanks AsmGuru62!
I tried your code, but the "Closing" problem still remains... Code: mov ax,4C00h int 21h mov ah,0 int 16h What do these code mean? |
|||
08 Dec 2012, 13:04 |
|
JohnFound 08 Dec 2012, 13:16
Lucy Berie, you are writing more than reading. AsmGuru wrote "It should be inserted before that".
|
|||
08 Dec 2012, 13:16 |
|
ManOfSteel 08 Dec 2012, 13:17
As AsmGuru already said, you should reverse the code: the ... 16h code should come before the ... 21h one.
The first waits for a key press and the second ends the process with an error code of 0 (i.e. no error). Interrupt 0x21 is provided by DOS (function 0x9 to print messages, 0x4C to exit, etc.) Interrupt 0x16 is provided by the BIOS for keyboard processing. |
|||
08 Dec 2012, 13:17 |
|
shutdownall 08 Dec 2012, 14:19
I think it's more convenient for you to write a windows program with message boxes. That's easy and the text (message box) doesn't disappear automatically. Yes - refer to the examples section, load, compile and execute them and try to understand. Use the easiest or nearest example and change it to your needs. That would be a good way to go deeper into it.
The beer example is a nice one to see what you can do with a few lines. I think you don't really want to write old DOS programs. It seems to be easier but you are learning an obsolete technique. That's more for retro programmers. |
|||
08 Dec 2012, 14:19 |
|
AsmGuru62 08 Dec 2012, 15:56
It is nice to see that person tries to learn so fast, that it even causes some trouble! Lucy, welcome to the forums! You asking: "How does it print?" Basically, this is the principle of DOS programming: the interrupts. These commands "INT 16h" or "INT 21h" called the INTerrupts. This is exactly the calls to DOS to do something: print text, work with files, work with keyboard, make simple graphics. What you do is fill registers with the information for DOS. It is like passing parameters in C++ -- they passed in registers. Example: Code: mov ah, 9 mov dx, hello int 21h Here: AH is like the function name -- what is DOS to do with the text passed in DX. DX is a string itself and text must be terminated with a '$' (24h code you see at the end). It is like string in C, just instead of zero termination -- '$' sign is used here. (What if you need to print a dollar sign? DOS has alternative function for this and you can also use colors in that other function) Translated to C it would look like that: Code: #define PRINT_TEXT 9 ... HeyDOS_DoThis (PRINT_TEXT, "Hello World!"); How exactly DOS will do it -- that code is located inside the INT 21h code, which you can see in debugger if you step into that interrupt. This depends on what is text mode is console in and maybe even some hardware coding may be there (writing to ports or directly into video memory) You can find most of what DOS can do here: http://www.ctyme.com/intr/int.htm I suggest to start with: INT 10h -- work with display (setting modes, moving cursor, etc.) INT 16h -- keyboard INT 21h -- DOS functions (files, memory, etc.) And finally: I think DOS is quite outdated (it is however a good start). You can learn Win32 console -- it has all the features (even colors) plus much more memory and you can use 32 bit registers! |
|||
08 Dec 2012, 15:56 |
|
Lucy Berie 09 Dec 2012, 01:18
This is my code :
Code: format MZ push cs pop ds mov ah,9 mov dx,hello int 21h mov ax,4C00h int 21h ;Pause... mov ah,0 int 16h mov ax,4C00h int 21h hello db 'Hello world!',24h But, the problem still stands.... What's wrong? I discovered : format MZ Is this a code which opens up the console screen? db This is variable code definition. It defines a variable, IMO... I see the assembly definition code is reversed... Edit : Code: push cs pop ds Why does the program need these code? (I see if I removed, it would print invalid characters...) And, how to set up a "#define" command (looks like C++), I'd like to write : Code: #define Printf 21h mov ah,9 mov dx,hello ;Call int Printf Last edited by Lucy Berie on 09 Dec 2012, 02:08; edited 1 time in total |
|||
09 Dec 2012, 01:18 |
|
HaHaAnonymous 09 Dec 2012, 01:36
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 22:12; edited 2 times in total |
|||
09 Dec 2012, 01:36 |
|
Lucy Berie 09 Dec 2012, 01:59
Oh I think the value 4c00h is the exit code...
|
|||
09 Dec 2012, 01:59 |
|
revolution 09 Dec 2012, 02:23
Lucy: You have two "exit"s in your code. One exit is before the pause and another exit is after the pause. Of course the pause and the last exit are never reached because the first exit quits immediately.
|
|||
09 Dec 2012, 02:23 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.