flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Macro to display string |
Author |
|
shutdownall 18 Feb 2013, 18:29
The message is displayed in the compile window if you press CTRL-F8 in the IDE (FASMW.EXE).
|
||||||||||
18 Feb 2013, 18:29 |
|
deathmood 18 Feb 2013, 18:40
So 'display' is useless in DOS? (because it is my target platform)
And what about function to display the string? |
|||
18 Feb 2013, 18:40 |
|
baldr 19 Feb 2013, 07:26
deathmood,
Console compiler displays these messages along its output. FASMD can put them into its clipboard. About prints macroinstruction: mov dx, [.bytes] in this context is equivalent to mov dx, 0x168B (because it actually loads dx with contents of memory at .bytes instead of that address itself), so I doubt it'll work even for short strings. Moreover, call pushes address of that string on stack and you never (explicitly) pop it off (or use in any other way). Code: macro prints [str*] { common local ..code call ..code db str, 24h ..code: pop dx mov ah, 9h int 21h } Code: macro prints [str*] { common local ..code, ..data jmp ..code ..data: db str, 24h ..code: mov dx, ..data mov ah, 9h int 21h } |
|||
19 Feb 2013, 07:26 |
|
deathmood 19 Feb 2013, 07:54
baldr,
I get some raw characters while using both your methods, e. g. for Code: prints "hi there)))) !!!!!" I get this:
|
||||||||||
19 Feb 2013, 07:54 |
|
Dex4u 19 Feb 2013, 08:13
See here: http://board.flatassembler.net/topic.php?t=7961
See below, as i do not think he as a print string Last edited by Dex4u on 19 Feb 2013, 08:25; edited 1 time in total |
|||
19 Feb 2013, 08:13 |
|
Dex4u 19 Feb 2013, 08:23
Something like this:
Code: macro PRINT String{ local .Done local .a mov dx, .a mov ah, 9h int 21h jmp .Done .a db String,24h .Done: } |
|||
19 Feb 2013, 08:23 |
|
deathmood 19 Feb 2013, 08:33
Dex4u,
I do not understand why, but it also prints many 'raw' characters as it was in my previous post...((( even more... |
|||
19 Feb 2013, 08:33 |
|
revolution 19 Feb 2013, 09:28
deathmood: Post your code.
|
|||
19 Feb 2013, 09:28 |
|
deathmood 19 Feb 2013, 09:41
Code: format MZ use16 stack 0x100 entry _CODE@16:_start ; macro prints str { local .bytes call .bytes db str, 0x24 .bytes: pop dx mov ah, 9 int 0x21 } segment _DATA@16 use16 msg db 'hi!', 0xd, 0xa, 0x24 segment _CODE@16 use16 _start: mov ax, _DATA@16 mov ds, ax prints 'hi there))) !!!!' mov ax, 0x4c00 int 0x21 ret I have found the strange thing: if I do not define any variables in my _DATA@16 segment macro 'prints' works fine. But after defining some variables raw symbols begin to appear((( Why??(( |
|||
19 Feb 2013, 09:41 |
|
deathmood 19 Feb 2013, 10:54
Hey! Maybe I've chosen wrong way to achieve that?
Maybe there are some other ways? Any sujestions? |
|||
19 Feb 2013, 10:54 |
|
baldr 19 Feb 2013, 15:58
deathmood,
Yep, you're getting offset in _CODE@16 segment as a value of dx, while int21/09 expects offset in ds segment (_DATA@16), which is one paragraph below. There are many ways to handle this, probably easiest one of them is to use tiny memory model, when cs == ds (pure tiny memory model assumes cs == ss too, but MZ executable places stack elsewhere by default). Put code and data in single segment (or forget about segments altogether for a while and use .COM executable output format). |
|||
19 Feb 2013, 15:58 |
|
deathmood 19 Feb 2013, 16:42
baldr,
Maybe there is another way to do that (using different macro features or else) ? because I do not want to use .com file neither having one segment... |
|||
19 Feb 2013, 16:42 |
|
AsmGuru62 19 Feb 2013, 18:10
COM file code has ~560Kb of data at its disposal.
|
|||
19 Feb 2013, 18:10 |
|
deathmood 19 Feb 2013, 18:16
So there is NO way to solve that ???
|
|||
19 Feb 2013, 18:16 |
|
AsmGuru62 19 Feb 2013, 23:09
Why? There is always a way - I just forgot how to do it!
Try to create an MZ file and print a string without using any macros. Make it work and then move on to doing it with macro. At least you will have a working starting point. |
|||
19 Feb 2013, 23:09 |
|
deathmood 20 Feb 2013, 08:46
So for .com files my macro can look like this:
Code: use16 org 0x100 macro prints [str*] { pusha if str in <0xd, 0xa, 9>\ | str eqtype '' call @f db str, 0x24 @@: pop dx else mov dx, str end if mov ah, 9 int 0x21 popa } _start: prints 0xd, 0xa, 9 prints 'hi!', 0xd, 0xa mov ax, msg prints ax, 0xd, 0xa prints msg int 0x20 ret msg db 'hey there!', 0x24 it can accept strings directly, addresses of strings in registers and variables it can also handle 3 special characters - 0xd (CR), 0xa (LF) and 9 (TAB) it is good because of its simplicity comparing to other samples here (on forums). |
|||
20 Feb 2013, 08:46 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.