Interrupts, Memory Models & Simple Instructions
Interrupts, Memory Models & Simple Instructions
Interrupts, Memory Models & Simple Instructions
1
Memory Allocation
Directive is .data for data segment. All variables must be declared and memory space for each
allocated. Different data definition directives are used for different size types of memory:
a) DB => define byte (8 bits)
b) DW => define word (16 bits)
c) DD => define double word (32 bits)
d) DQ => define quadword (64 bits)
Code Segment
Directive is .code for code segment. The program resides here.
Example = > message db "Hello world", 13, 10, ‘$’
The string message contains ‘Hello world’ followed by Return (ASCII 13), Line-feed (ASCII 10)
and the ‘$’character. This method is very useful if we wish to include control characters (such as
Return) in a string. We terminate the string with the ‘$’ character because there is an MS-DOS
subprogram (number 9h) for displaying strings which expects the string to be terminated by the ‘$’
character.
Points to Remember:
-You need to start all assembly languages programs in a particular format (not necessarily that given
above.
-Your program must also finish in a particular format the end directive indicates where your program
finishes.
-In the middle comes the code that you write yourself.
-You must also specify where your program starts, i.e. which is the first instruction to be executed.
This is the purpose of the label, start. (Note: We could use any label, e.g. begin in place of start).
This same label is also used by the end directive.
-When a program has finished, we return to the operating system. Like carrying out an I/O operation,
this is also accomplished by using the int instruction. This time MS-DOS subprogram number 4c00h
is used.
2
DOS Display Functions/Interrupts
These are DOS functions 02 and 06 for single character display, and 09 for string display.
The character code may be the ASCII code of the character or the character itself written between the
quotes.
DOS function 09
This function is used to display a string of characters ended with a ‘$’ sign.It’s syntax is as follows:
message DB “This is the message to be displayed”, “$”
.code
mov dx,offset message ;Copy address of message to dx
mov ah, 09h
int 21h
3
DOS Input functions/Interrupts
These include reading a single character, with or without echo, functions 01 and 08, and reading a
whole string.
DOS function 01 and 08
To read single character and have it echoed (displayed) on the screen, use the following code:
mov ah,01h
int 21h
;AL contains now the ASCII code of the character read from the keyboard
If the character is to be read without echo, such as reading a password, use the following code:
mov ah,08h
int 21h
;AL contains now the ASCII code of the character read from the keyboard
The following table summarizes the main I/O functions. These functions are mainly used to read and
display characters and/or strings read from the keyboard.
Examples:
1) Reading a character from the keyboard and displaying it on the screen:
4
Output: AA
Debug It:
5
Task: Change Lower case to upper case & display
6
Home Tasks:
a)Write code to display your
NAME :
ROLLNO :
SEMESTER :
b) Write a code to print input char from user in the next line like the following:
A
A
c) Write a program that inputs two numbers, adds them and shows the result.
Limitation: The maximum sum can only be upto 9