flat assembler
Message board for the users of flat assembler.
Index
> DOS > Hello World Help :? (MZ EXE, 16-vs-32-bit, segments) |
Author |
|
JohnFound 18 Feb 2013, 16:45
It is 16bit program. And it will not work because you didn't set properly DS.
Better use COM format following way. In this format the OS (DOS) sets the segment registers for you: Code: org 100h mov dx, msg mov ah, 09h ; Write string to STDOUT int 21h mov ax, 4Ch ; Exit program int 21h msg db "Hello, World!", 13, 10, "$" _________________ Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9 |
|||
18 Feb 2013, 16:45 |
|
clonemaster 18 Feb 2013, 16:51
JohnFound wrote:
Is it better to put msg db after mov dx, msg? If so, why? |
|||
18 Feb 2013, 16:51 |
|
JohnFound 18 Feb 2013, 17:51
Because in the COM file, the execution goes from the first address ( 100h) down. You don't want to execute "Hello, World" string. It is data. So, I put it where it will be never executed, because the program terminates earlier.
|
|||
18 Feb 2013, 17:51 |
|
clonemaster 18 Feb 2013, 19:13
Okay, got it! Is this how I add more lines to msg db?
Code: org 100h use16 mov dx, msg mov ah, 09h ; Write string to STDOUT int 21h mov ax, 4Ch ; Exit program int 21h msg db "Hello, World!", 13, 10, "$" db "Hello, World!", 13, 10, "$" db "Hello, World!", 13, 10, "$" |
|||
18 Feb 2013, 19:13 |
|
AsmGuru62 18 Feb 2013, 21:13
If you want to write all three lines in one operation - you need to remove the extra '$'.
Like so: Code: msg db "Hello, World!", 13, 10 db "Hello, World!", 13, 10 db "Hello, World!", 13, 10, "$" ; <-- Only final '$' matters! |
|||
18 Feb 2013, 21:13 |
|
freecrac 19 Feb 2013, 07:02
The next lesson is to write a string to the textscreen without using software interrupts.
Code: org 100h use16 mov ax, 0B800h ; Segmentaddress of the textscreen mov es, ax mov si, msg mov di, 17*160 ; target position inside of the textscreen(screensize of 80 rows and 25 lines: ASCII,color,ASCII,color, etc...) mov cl, Mlen ; number of ASCIIs P1: mov al, [si] ; load an ASCII from DS:SI inc si mov es:[di], al ; write an ASCII to ES:DI add di, 2 ; next ASCII + next color dec cl ; decrease our counter and if it is zero, then the zero-Flag will be set jnz P1 ; conditional jump if the zero-flag is not set mov ax, 4Ch ; Exit program int 21h msg db "Hello, World!" Mlen = ($-msg) ; $ = placeholder/substituent of the current offset address (for to calculate the number of bytes between the address above) A small variation of the code (with using some of the string instructions): Code: org 100h use16 mov ax, 0B800h ; Segmentaddress of the textscreen mov es, ax mov si, msg mov di, 17*160 ; target position mov cl, Mlen ; number of ASCIIs cld ; clear direction flag P1: lodsb ; load an ASCII from DS:SI + increase SI by one stosb ; write an ASCII to ES:DI + increase DI by one inc di ; step over color dec cl jnz P1 mov ax, 4Ch ; Exit program int 21h msg db "Hello, World!" Mlen = ($-msg) An other variation is to replace lodsb + stosb with movsb. And if we add to each ASCII a color-attribut, then it is possible to use a repeat instruction in combination with the string-instruction: "mov cx, (Mlen/2)" ....."repz movsw".....msg db "H", 7 , "e" ,7, "l", 7, "l", 7, "o" ,7.... Dirk |
|||
19 Feb 2013, 07:02 |
|
clonemaster 19 Feb 2013, 14:46
It's going to take me awhile to assimilate all this Dirk
|
|||
19 Feb 2013, 14:46 |
|
freecrac 20 Feb 2013, 19:52
clonemaster wrote: It's going to take me awhile to assimilate all this Dirk This is no problem. I hope that a found a balance of information in the remarks trying to prevent an overload. But if you think there is something to much obscure, please ask again. Dirk |
|||
20 Feb 2013, 19:52 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.