flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
MaaSTaaR 09 Aug 2005, 07:41
Hello
![]() i am new with Assembly , now i study it from http://www.xs4all.nl/~smit/asm01001.htm , i try to compile this code with flat assembler Code: ;-- ----------------------------------------------------------------------- ;- Written by Ferdi Smit for use with the "ASM Tutorial Part 1" - ;------------------------------------------------------------------------- ; To compile: TASM examp1.asm - ; TLINK examp1.obj - ;---------------------------------------------------------------------------- .model small .stack .data message db "Hello world, I'm learning Assembly !!!", "$" .code main proc mov ax,seg message mov ds,ax mov ah,09 lea dx,message int 21h mov ax,4c00h int 21h main endp end main but it's show this error "illegal instruction" when i try to compile it ![]() |
|||
![]() |
|
tom tobias 09 Aug 2005, 09:28
Thank you Vid, for that succinct and lucid clarification. I would only add, to maastaar, that in general one should select instructions, ESPECIALLY when first writing programs (NOT CODING), that are as SIMPLE as possible. There is no substitute for clarity and readability. The author of your site:
http://www.xs4all.nl/~smit/asm01001.htm has done a fine job. HOWEVER, with regard to his statement: "Well, I'll start with the basics, like instruction format and some simple instructions to manipulate registers. I don't know how much you know about coding, so I'll explain even the most simple stuff. Please note, that I explain 8086 assembly coding. That means NO 32-bit registers and instructions and NO protected-, real- and virtual 86 mode for now...." I would submit that it is MORE DIFFICULT for debutants to commence with real mode "coding", than with protected mode PROGRAMMING, in which all segments disappear, (i.e. all assigned the same value), so as to make assembly language PROGRAMMING just like programming in any other language. I am sure many folks on this forum would dispute my point of view! ![]() ![]() |
|||
![]() |
|
smiddy 09 Aug 2005, 10:13
Hi maaSTaar,
This bit of code has to be rewritten in FASM syntax in order to work: Code: ;------------------------------------------------------------------------- ;- Written by Ferdi Smit for use with the "ASM Tutorial Part 1" - ;------------------------------------------------------------------------- ;- ReWritten for FASM by -smiddy - ;------------------------------------------------------------------------- ;- To Compile: FASM Hello.asm - ;------------------------------------------------------------------------- format MZ ; For FASM EXE format main: mov ax,cs ; Move CS into AX mov ds,ax ; Put CS into DS mov ah,09 ; Function 9 from DOS lea dx,[message] ; Load effective address into DX int 21h ; Call DOS functions mov ax,4c00h ; Function 4C00h (exit to DOS) int 21h ; Call DOS functions message db "Hello world, I'm learning Assembly !!!", "$" Getting this to compile: Code: C:\smiddy>fasm hello.asm flat assembler version 1.58 2 passes, 88 bytes. C:\smiddy>hello Hello world, I'm learning Assembly !!! C:\smiddy> Instead ot the Code: . . . LEA DX,[message] . . . most people use: Code:
. . .
MOV DX,message
. . .
I hope this helps a little. It will take a little time in order to make the jump to FASM, but to me it is very rewarding! |
|||
![]() |
|
THEWizardGenius 09 Aug 2005, 17:51
I see your tutorial used MASM or TASM syntax. If you want to use FASM you should find a tutorial that uses FASM syntax. There aren't too many, but since you're using DOS you can luckily try the TAJGA tutorial: http://www.decard.net/article.php?body=tajga
BTW, using LEA where MOV can be used is something a lot of old assembly books used. I guess they thought it was more readable, or maybe because you had to use the OFFSET keyword with MOV in MASM (There is no OFFSET keyword in FASM, you use the name of the variable to find the offset and the variable in "[" "]" to get the value). Anyways, good luck learning assembly! |
|||
![]() |
|
MaaSTaaR 11 Aug 2005, 13:47
Hello ..
thanks very much for all ![]() it's work now but i have question why we change Code:
mov ax,seg message
to Code:
mov ax,cs
and why we copy CS value to AX ? now i am study from this http://www.decard.net/article.php?body=tajga , thank you very much THEWizardGenius ![]() this is my first code , is this great work ? ![]() Code: ;======================= ; Codded by MaaSTaaR |
|||
![]() |
|
THEWizardGenius 11 Aug 2005, 17:23
CS tells which segment the code is located. "seg message" is MASM/TASM for "the segment that the variable message is located in". FASM has no such word. However, since your data and code are in the same segment, CS is the same. If you had data and code in different segments, the data would probably be in DS (which tells which segment the data is in, when data and code are in different segments) so you would type
Code:
mov ax, ds
to do it that way. Your code is good, but too complex. You print one character at a time. You can write the whole string at once. Use INT 21h with AH=9 to do this. A reference about the DOS system calls, http://spike.scu.edu.au/~barry/interrupts.html#ah09 says this: Quote:
So you copy CS to DS (since the data is in CS) and DX points at the string. Then put 9 into AH and call INT 21h. Remember, the string must end with "$" or DOS will just keep printing gibberish until it crashes or something. Here's example code that does the same thing as your code: Code: mov dx, hwstring ;You can't do "mov ds, cs" so you have to do it in two steps. mov ax, cs mov ds, ax mov ah, 9 int 21h int 20h hwstring db 'Hello, ASM!$' Much better, right? But that's OK, you didn't know. So what happens is when you call INT 21h and AH=9, DOS starts at DS:DX and starts checking each character. If the character is "$" it stops. If not, it prints the character and checks the next one. What if you have to have a "$" in your string, such as "Only costs is $19.99!!!"? Then you print the first part of the string, then print a "$" with AH=2, then print the rest of the string: Code: ;Copy CS to DS mov ax, cs mov ds, ax mov dx, coststringa mov ah, 9 int 21h ;Now print a single character mov ah, 2 mov dl, '$' int 21h mov dx, coststringb mov ah, 9 int 21h int 20h ;Note that INT 21h AH=9 does NOT print the "$", we have to do that ;with INT 21h AH=2 in between the two strings. Thus the strings ;must be split into two. coststringa db 'Only costs is $' ;Stops at "$", does not print "$" coststringb db '19.99!!!$' Do you understand? Now if you don't know what a segment is, tell me. I can tell you. |
|||
![]() |
|
Tomasz Grysztar 11 Aug 2005, 17:37
THEWizardGenius: actually to code it more analogously to TASM version it would be better to do:
Code: format MZ entry codeseg:main segment dataseg message db "Hello world, I'm learning Assembly !!!", "$" segment codeseg main: mov ax,dataseg mov ds,ax mov ah,09 mov dx,message int 21h mov ax,4c00h int 21h |
|||
![]() |
|
El Tangas 11 Aug 2005, 18:12
You can also use function 40h to print the string, it can also print dollar signs and print to files instead of the screen.
Check this link: http://www.uv.tietgen.dk/staff/mlha/PC/Prog/asm/INT/index.htm To learn assembly for DOS, you should be familiar with BIOS interrupts and DOS functions. Code: format MZ entry codeseg:main segment dataseg ;In MS-DOS, the 13,10 byte sequence means "change line" message db "Hello world, I'm learning Assembly !!!", 13, 10, "Look, I can print $$$$ signs !!!" ;in Fasm syntax, $ means "this location", so this returns the lengh of the string lenght = $-message segment codeseg main: mov ax,dataseg mov ds,ax mov ah,40h mov bx,1 ;handle of standard output mov cx,lenght mov dx,message int 21h mov ax,4c00h int 21h |
|||
![]() |
|
THEWizardGenius 12 Aug 2005, 01:21
I don't know TASM so I did it the FASM way. Since he's apparently trying to use FASM, that makes more sense anyways.
El Tangas: that page doesn't tell about INT 21h, but it links to this page (which does): http://www.uv.tietgen.dk/staff/mlha/PC/Prog/asm/INT/21/index.htm |
|||
![]() |
|
vid 15 Aug 2005, 09:49
anyway int 21h/ah=9 is described further in tutorial
|
|||
![]() |
|
zoijar 22 Aug 2005, 18:04
tom tobias wrote: Thank you Vid, for that succinct and lucid clarification. I would only add, to maastaar, that in general one should select instructions, ESPECIALLY when first writing programs (NOT CODING), that are as SIMPLE as possible. There is no substitute for clarity and readability. The author of your site: I stumbled on this topic via a google on my name ![]() While I fully agree with you _now_, this wasn't the case when I wrote these texts. One should note that I wrote most of this in 1995-1996, a time when protected mode was fairly uncommon and new (and I was only 15-16 years old, and not a phd student yet...quite a change ![]() ![]() For the topic starter: while my tutorials seem to be easy to understand for many people, and a decent introduction, I would still urge you to buy a modern book on assembler programming: 1996 is ancient history in the world of computing... |
|||
![]() |
|
vid 22 Aug 2005, 21:02
to zoijar
1. why buy? there are many good online 2. I think starting from beginning is good thing. modern ways start with prot. mode ring 3 programming (win32/linux) which causes people just don't understand many things and also they don't understand reason of changes in histrocial context |
|||
![]() |
|
zoijar 23 Aug 2005, 09:41
vid wrote: to zoijar 1 - Because it's better to learn from a consistent, coherent whole, than from bits and pieces scrapped from the net. 2 - You're partially correct: the understanding of historical changes is nice. However, none of the modern operating systems really allow you to work in realmode (I'm not sure about virtual 8086 mode). So you would need an old DOS partition or something similar. Besides that most people want to learn something that can be used now. However, learning the historical context and evolution of hardware can be a significant insight; it sure helped me a great deal in university... C pointers? Hah, piece of cake.... Computer architecture? Puh. ![]() |
|||
![]() |
|
UCM 23 Aug 2005, 17:26
Windows lets you run MZ exe's and COMs. (Not mine though! It just won't work. It worked before but not now anymore.
![]() _________________ This calls for... Ultra CRUNCHY Man! Ta da!! *crunch* |
|||
![]() |
|
vid 23 Aug 2005, 19:08
zoijar wrote:
i disagree here. from one source you are limited by limitations of one single author, you should have multiple sources to overcome such problems. no one, even authors of commercial books, is 100% genius and everyone doesn't explain everything in full (and even if he would no one would read it anyway). if you are stuck, some other source can help you. also learning one-thing-at-time is getting boring after some time, you should work on more things at same time and switch them when one of them gets boring. This way it's more fun and thus you spend more time learning and advance faster. zoijar wrote:
sorry, but if somebody wants just to learn something useful then he should stick with PHP, not assembly. (X86) assembly is for people who are interested in how-things-work (eg. hackers ![]() |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.