3 Hello there, this is Draeden typing this wonderful document. This is
\r
4 an explanation of the basic assembler frame. This document assumes that you
\r
5 know what hexdecimal is and somewhat how it works, that you have a copy of
\r
6 TASM and TLINK, that you know what AX is, and how it relates to AL and AH,
\r
7 and you know the commands:
\r
13 I'm also making the rash assumption that you want to learn ASSEMBLER. :)
\r
14 To assemble ASM0.ASM into an executable do the following:
\r
19 Now you can exececute this wonderful program. Go ahead. Try it. In
\r
20 case you are having problems figuring out how to execute this, just type:
\r
22 ASM0 (followed by the enter key)
\r
24 No, you did nothing wrong. This code (ASM0.ASM) does nothing. All it
\r
25 does is return control to DOS. It is the basic frame for an assembler
\r
26 program. All of the programs that I write use this frame. If you want to
\r
27 know what each part does, read on. If you already know, just go read
\r
30 The number followed by the colon means that this is from ASM0.ASM and
\r
31 tells which line it is from.
\r
35 DOSSEG Sorts the segment using DOS standard, which is:
\r
37 1) 'code' segments (in alphabetical order)
\r
38 2) 'data' segments (in alphabetical order)
\r
39 3) 'stack' segments (again, in alphabetical order)
\r
41 Although it may not seem clear what this does, don't worry about it. Just
\r
42 have it as the first line in your assembler programs, until you understand it.
\r
46 MODEL ONLY needs to be used if you use the simplified segments, which I
\r
49 In a nutshell, .MODEL Selects the MODEL to use. This is used so that this
\r
50 code can be linked with C, PASCAL, ADA, BASIC, other ASSEMBLER program, and
\r
51 other languages with ease. It also tells the compiler how to treat your
\r
52 code and data segments.
\r
54 NEAR means that the data/code can be reached using a 16bit pointer (offset)
\r
55 FAR means that a SEGMENT:OFFSET pair must be used to access all the data/code
\r
57 Possible MODELS are:
\r
59 TINY: Code and Data must fit in same 64k segment.
\r
60 Both Code and Data are NEAR.
\r
62 SMALL: Code & Data have seperate segment, but must be each less than 64k
\r
63 Both Code and Data are NEAR.
\r
64 For most applications, this will suffice.
\r
66 MEDIUM: Code may be larger than 64k, but Data has to be less than 64k
\r
67 Code is FAR, Data is NEAR.
\r
69 COMPACT: Code is less than 64k, but Data may be greater than 64k
\r
70 Code is NEAR, Data is FAR.
\r
72 LARGE: Both Code & Data can be greather than 64k. Both are FAR, but a
\r
73 single array cannot be greater than 64k. Note that max array size
\r
74 means nothing if you are just writing in assembler. This only
\r
75 matters when you link to C or another high level language.
\r
77 HUGE: Same as LARGE, but arrays can be greater than 64k.
\r
78 What that means is that the array index is a far pointer, instead
\r
80 LARGE and HUGE are identicle to the assembler programmer.
\r
84 Tells the compiler to set up a 200h byte stack upon execution of the
\r
85 program. NOTE: the size you choose for the stack does not change the size
\r
86 of the file on disk. You can see what I mean by changing the 200h to, say,
\r
87 400h and then recompiling. The file sizes are identicle.
\r
89 This could be replaced with:
\r
91 : MyStack SEGMENT PARA PUBLIC STACK 'STACK'
\r
95 BUT, doing it this way makes your executable 512 bytes bigger. If you
\r
96 were to double to 400h, the executable would be another 512 bytes bigger.
\r
97 I think it's pretty obvious why the simplified version is preferred.
\r
101 Simplified, unnamed 'data' segment. This is where those simplified
\r
102 segments become very handy. If you were to write out the segment declaration
\r
103 the regular way, you'd have to write something like this:
\r
105 : MyData SEGMENT PARA PUBLIC 'DATA'
\r
107 : ... ;your data goes here...
\r
111 Where 'MyData' is the name of the segment, public means that its, well,
\r
112 public, and PARA is the alignment of the start of the segment. 'DATA'
\r
113 specifies the type of the segment. Instead of PARA, WORD or BYTE could
\r
114 have been used. (PARA = segment will start on an adress that is a multiple
\r
115 of 16, WORD = even addresses, BYTE = where ever it lands.)
\r
119 Pretty much the same story as above, but this is for the code segment.
\r
120 Could be replaced with:
\r
123 : MyCode SEGMENT PARA PUBLIC 'CODE'
\r
128 : SEGMENT MyCode PARA PUBLIC 'CODE'
\r
130 : ENDS MyCode ;the 'MyCode' is optional in IDEAL mode
\r
134 This is just a label. Labels just provide a way of refencing memory
\r
135 easily. Like I could say "JMP START" which would jump to the label START and
\r
136 execute the code immediatly after it. Or I could say MOV AX,[Start], which
\r
137 would grab the WORD that was immediatly after the label START.
\r
142 This bit of code calls DOS function # 4ch, which returns control to DOS
\r
143 and sends back the error level code that is in AL (which is zero).
\r
144 Note that for all int 21h DOS functions, AH contains the function number.
\r
146 THIS MUST BE AT THE END OF THE CODE! If it isn't, the code will continue to
\r
147 run... right out of the end of your program and will execute whatever code
\r
148 is there! The program will crash with out it!
\r
152 This tells the compiler that we are all done with our program and that it can
\r
153 stop compiling, now. And it tells the compiler to put the entry point at
\r
154 the label START. This means that DOS is effectivly starting your program by
\r
159 As you would probably guess, if you just put `END' instead of `END START'
\r
160 and you compiled and linked the program, when you went to execute the code,
\r
161 the computer will probably freeze because it does not know where to start
\r
164 Ok, now that you know what the frame is/does, lets actually make the
\r
165 program do something. Lets be wild and crazy, and PRINT A MESSAGE!
\r
168 CONTINUED IN ASM1.TXT
\r
171 ÚÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
\r
184 ; Your code goes here...
\r
191 ; THIS CODE DOES ABSOLUTLY NOTHING EXCEPT RETURN CONTROL TO DOS!
\r