Lesson no.5 ASM:Diffrent approach
.STACK 100h ;Stack will be explained later ;it is beyond the scope of this ;tutorial .CODE ;This is the code segment jmp start ;Jump to "start" no matter ;what. message db 'Hello world!', 0d, 0a, '$' start: mov dx,OFFSET message ;Get the message pointer mov ax,cs ;put code segment in ax mov ds,ax ;put code segment in data segment mov ax,0900h ;Use function 9 int 21 ;DOS service 21 (explained later) mov ax,4c00h ;Returns to DOS function int 21 ;DOS ExitWhat did that do? Run it and see. Ah there we go it printed out "Hello World". But how the heck did that happen? Simple if you follow what I say.
First by saying "jmp start" we are jumping to the label called "start". Labels behave much like they do in QB as the do in asm. Except, as you'll find out, you can do a bit more with them. Now that we are in the start, we notice we skiped a line of code up there.
message db 'Hello world!', 0d, 0a, '$'First the "message" part is actually a label. But that's a neat way of writing it. db means a integer or a string to put it in simple terms. Then we have the text the 0d 0a (Enter). At the end we have a $. This is actually to terminate the string.
So by saying that we get a label called message pointing to a string that say "Hello world".
Ok lets go back to buisness, after the start label there is a command that says:
mov dx,OFFSET messageWhat's offset you say? before you continue I suggest reading the segments and offsets tutorial that I've included. Done? About time =) Now that we know what segments and offsets are you should now understand that what we are doing is locating the offset of the data block after the label message, then puting that value in DX. Why DX? We will get to that shortly.
After that we have this pretty peice of code:
mov ax,cs mov ds,axFirstly, CS is a pointer to the segment of the program's code thats running at the momment. DS is the pointer to the DATA segment. In the case of our little program, both the Data Segment and the Code segments are the same, thus we need to make the value of the data segment, the same value of the code segment. Why not just say MOV DS,CS? Well some smart ass jerk making the computer chipset model decided that MOV DS,CS is a illegal command combination (OK OK that's not the real reason but to tell you the truth I don't know ;) ) Ofcourse there is a way out of this chocking limit.
First mov the value of CS to AX, then mov the value of AX to DS!
mov ax,cs ;mov value of cs to ax mov ds,ax ;mov value of ax to ds, therefor moving cs to ds.Aha! After we done that we see this weird part:
mov ax,0900h ;Use function 9 int 21 ;DOS service 21 (explained later)This simply says to use function 9 of the DOS service int. Remeber when we turned on the mouse? Well This int prints out a string.
First you put the string's offset in DX
mov dx,OFFSET message ;Get the message pointerThen you put the string's segment in DS
mov ax,cs ;put code segment in ax mov ds,ax ;put code segment in data segmentThen you call INT 21 with 900 in AX
mov ax,0900h ;Use function 9 int 21 ;DOS service 21 (explained later)Now we must bravely exit out of our little homemade program. There is an int perfect for this. int 21 function 4C!
mov ax,4c00h ;Returns to DOS function int 21 ;DOS ExitIf you don't get all this, read it agian, still don't get it, read it agian, still don't get it? Email me at firstname.lastname@example.org =)
Next month we look at more registers more commands and more asm. Don't miss out =)© Copyright 1999 Nightwolf Productions