]> 4ch.mooo.com Git - 16.git/blob - 16/PCGPE10/ASM1.TXT
modified: 16/DOS_GFX.OBJ
[16.git] / 16 / PCGPE10 / ASM1.TXT
1 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\r
2     ASM1.ASM - print a string\r
3 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\r
4 \r
5     Well, here's the classic example for the first program in just about\r
6 every language.  It prints a message to the screen by using a DOS function.\r
7 More specifically, it uses function 9 of interrupt 21h.  Here's the mock\r
8 specification for the function:\r
9 \r
10 þ-\r
11 |IN:     ah = 9      ;ah tells INT 21h which function you want\r
12 |        DS:DX = FAR pointer to the string to be printed.\r
13 |                    ;the string must terminate with a dollar sign ($)\r
14 |\r
15 |OUT:    Prints the string to the screen\r
16 þ-\r
17 \r
18     Other than that function, there's nothing new that can't easily be\r
19 figured out.  The directive SEG, as you might have guessed, returns the \r
20 segment that the specified label is in.  OFFSET returns the offset from \r
21 the begining of the segment to the specified label.  Together, you can\r
22 form a FAR pointer to a specified label.\r
23 \r
24     Another thing you might wonder about is why I put the SEG Message into\r
25 AX and THEN Put it in DS.  \r
26 \r
27     The answer is:  You have to.  An immediate value cannot be put into a \r
28 segment register, but a register or an indexed value can.  For instance:\r
29 \r
30 These are legal:\r
31 \r
32 :   mov     DS,AX\r
33 :   mov     DS,[TheSegment]\r
34 \r
35 But these are not:\r
36 \r
37 :   mov     DS,50\r
38 :   mov     DS,0a000h\r
39     \r
40     One last piece of info: in the lines:\r
41 \r
42 :Message     db  "This was printed using function 9 " \r
43 :            db  "of the DOS interrupt 21h.$"\r
44 \r
45     The DB is just a data type.  Its the same as a CHAR in C, which is 1 byte\r
46     in length.\r
47 \r
48     Other common data types are:\r
49 \r
50     DW  same as an INT in C - 2 bytes\r
51     DD  same as a double int or long int or a FAR pointer - 4 bytes\r
52 \r
53 \r
54     Well, that's pretty much it for this short section...  Try playing around\r
55 with the 'print' function... Ya learn best by playing with it.\r
56 \r
57 \r
58 One last side note:\r
59     I COULD have put the message in the CODE segment instead, by doing this:\r
60     \r
61 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\r
62 \r
63     DOSSEG\r
64     .MODEL SMALL\r
65     .STACK 200h\r
66     .CODE\r
67 \r
68 Message     db  "Hey look! I'm in the code segment!$" \r
69             \r
70 START:\r
71     mov     ax,cs   ;since CS already points to the same segment as Message,\r
72     mov     ds,ax   ;I don't have to explicitly load the segment that message\r
73                     ;is in..\r
74 \r
75     mov     dx,offset Message\r
76     mov     ah,9\r
77     int     21h\r
78 \r
79     mov     ax,4c00h    ;Returns control to DOS\r
80     int     21h         ;MUST be here! Program will crash without it!\r
81 \r
82 END START\r
83 \r
84 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\r
85 \r
86     The advantage to having all your data in the CODE segment is that DS and\r
87 ES can be pointing anywhere and you can still access your data via a segment\r
88 override!  \r
89 \r
90     Example:\r
91         say I'm in the middle of copying one section of the screen memory to\r
92     another and I need to access the variable "NumLines" I'd do it like this:\r
93 \r
94 ÄÄÄÄÄÄÄÄ\r
95 \r
96     mov ax,[CS:NumLines]    ;this is in IDEAL mode\r
97             ^^^\r
98 ÄÄÄÄÄÄÄÄ    Code Segment override\r
99 \r
100     Pretty flexable, eh?\r
101 \r
102 \r
103 ÚÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\r
104 ³ ASM1.ASM ³\r
105 ÀÄÄÄÄÄÄÄÄÄÄÙ\r
106 \r
107     DOSSEG\r
108     .MODEL SMALL\r
109     .STACK 200h\r
110     .DATA\r
111 \r
112 Message     db  "This was printed using function 9 " \r
113             db  "of the DOS interrupt 21h.$"\r
114                   \r
115     .CODE\r
116     \r
117 START:\r
118     mov     ax,seg Message  ;moves the SEGMENT that `Message' is in into AX\r
119     mov     ds,ax           ;moves ax into ds (ds=ax)\r
120                             ;you cannot do this -> mov ds,seg Message\r
121 \r
122     mov     dx,offset Message   ;move the OFFSET of `Message' into DX\r
123     mov     ah,9        ;Function 9 of DOS interupt 21h prints a string that\r
124     int     21h         ;terminates with a "$".  It requires a FAR pointer to\r
125                         ;what is to be printed in DS:DX\r
126 \r
127     mov     ax,4c00h    ;Returns control to DOS\r
128     int     21h         ;MUST be here! Program will crash without it!\r
129 \r
130 END START\r
131 \r