Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

i'm learning assembly and here is m 2

Status
Not open for further replies.

turborob

Programmer
Dec 10, 2000
51
GB
i'm learning assembly and here is my program, no need to explain what it does' but what can i add to the program that will display a letters to the screen to show the program works on each comparison to 10?.
thanx in advance....ROB.

MODEL Small
STACK 100h
.DATA

nta1 db 5
nta2 db 4
nta3 db 7

.CODE
mov ax,@data
mov ds,ax
mov al,nta1
add al,nta2
cmp al,10
je finish
add al,nta3
cmp al,10
je finish
finish: mov ah,4ch
int 21h
END
 
add this to the data section of your program:

message1 db "Sum is 10!!!!$"
;program section ends

add this to the code section:
je finish
;add these 3 lines
mov ah,09h
mov dx,offset message1
Int 21h
;end added lines
finish:
;program section ends


What you're doing here is to define a message in the data section. Then, the three lines you added call a "DOS function." In assembly a DOS function is a service rendered by DOS for application programs. One function is called Function 09h "Display $-terminated string." The function number (here, 09h) is loaded in ah. However, some functions (such as DOS's display string function) need to have other information. For example, Function 09h needs to know the address of the message. It expects the dx register to contain the address, so we load dx using "mov dx, offset message1". The "offset" here is an assembler operator which gives the address of a label (kinda like & in C, although different context).

Note that DOS's Function 09h is "Display $-terminated string." While you can't use it to output dollars and cents, it is very simple and is commonly used even in commercial programs (although most commercial programs use it only for certain error messages)

Note that you will also encounter &quot;BIOS Functions,&quot; &quot;NetWare Functions,&quot; &quot;Mouse Functions,&quot; etc. Most of them are called by loading ah with a function number and issuing an Int <somenumber> where <somenumber> is dependent on what set of functions you are interested in.

With a bit of work you can add other messages, such as:
message2 db &quot;Checking sum of nta1 and nta2$&quot;
message3 db &quot;Checking sum of nta1, nta2, and nta3$&quot;
;program section ends

of course you need to add code to handle these... but hey, it ain't so hard! &quot;Information has a tendency to be free. Which means someone will always tell you something you don't want to know.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top