Display message using DOS interrupts PDF

Title Display message using DOS interrupts
Author Prashant Saini
Course Microprocessor
Institution University of Mumbai
Pages 13
File Size 663.6 KB
File Type PDF
Total Downloads 54
Total Views 142

Summary

The Microsoft Macro Assembler (MASM) is an x86 assembler that uses
the Intel syntax for MS-DOS and Microsoft Windows. Beginning with MASM
8.0 there are two versions of the assembler - one for 16-bit and 32-bit assembly
sources, and another (ML64) for 64-bit sources only.
Asse...


Description

Experiment- 1 Aim: Write a program to display message using DOS interrupts. Theory: The Microsof Macro Assembler (MASM) is an x86 assembler that uses the Intel syntax for MS-DOS and Microsof Windows. Beginning with MASM 8.0 there are two versions of the assembler - one for 16-bit and 32-bit assembly sources, and another (ML64) for 64-bit sources only. Assembler Directives helps the assembler to correctly understand the assembly language program to prepare the codes. Some of the assembler directives are given below. . DB: Define Byte: The DB directive is used to reserve byte or bytes of memory locations in the available memory. . DW: Define Word: The DW directive serves the same purposes as the DB directive, but it makes the assembler reserves the number of memory words (16bit) instead of bytes. . DQ: Define Quadword: This directive is used to direct the assembler to reserve 4 words (8bytes) of memory for the specified variable and may initialize it with the specified values. . DT: Define Ten Bytes: The DT directive directs the assembler to define the specified variable requiring 10-bytes for its storage and initialize the 10-bytes with the specified values. . ASSUME: Assume Logical Segment Name: The ASSUME directive is used to inform the assembler, the names of the logical segments to be assumed for different segments used in the program. . END: END Of Program: The END directive marks the end of an assembly language program. . ENDP: END Of Procedure: The ENDP directive is used to indicate the end of a procedure. PROCEDURE STAR o : STAR ENDP //indicates the end of procedure STAR

. ENDS: END Of Segment: This directive marks the end of a logical segment. DATA SEGMENT o : DATA ENDS //indicates the end of segment DATA . NAME: Logical Name Of A Module: The NAME directive is used to assign a name to an assembly language program module. . OFFSET: Offset Of A Label: When the assembler comes across the OFFSET operator along with a label, it first computes the 16-bit displacement of the particular label, and replaces the string ‘OFFSET LABEL’ by the computed displacement. . ORG: Origin: The ORG directive directs the assembler to start the memory allotment for the particular segment, block or code from the declared address in the ORG statement. . PROC: Procedure: The PROC directive marks the start of a named procedure in the statement. Also the types FAR and NEAR specifies the type of the procedure. . PTR: Pointer: The POINTER operator is used to declare the type of a label, variable or memory operand. The operator PTR is prefixed by either BYTE (8-bit quantity) or WORD (16-bit quantity). . SEGMENT: Logical Segment: The SEGMENT directive marks the starting of a logical segment. The started segment is also assigned a name, i.e. label, by this statement. . SHORT: The SHORT operator indicates the assembler that only one byte is required to code the displacement for a jump. This method of specifying jump address saves memory. . TYPE: The TYPE operator directs the assembler to decide the data type of the specified label and replaces the TYPE label by the decided data type. . GLOBAL: The labels, variables, constants or procedures declared GLOBAL may be used by other modules of the program. . FAR PTR: This directive indicates the assembler that the label following FAR PTR is not available within the same segment and the address of the bit is of 32 bits i.e. 2 bytes offset followed by 2 bytes. . NEAR PTR: This directive indicates that the label following NEAR PTR is in the same segment and need only 16 bit i.e. 2 byte offset to address it. A NEAR PTR label is considered as default if a label is not preceded by NEAR PTR or FAR PTR.

DOS service routines tend to operate at a higher level and are primarily concerned with disk operations. DOS INT 21H is the main DOS INT type and is made up of over 100 functions. Common DOS I/O INT type 21H functions used in program are: Function 09h: Display character string. Register AH=09h. DS=segment address of string. DX=offset address of string. Returns nothing. Operation: DOS INT 21h, function 09h displays character strings pointed to by DS:DX. The string must end in a $ character for function to work properly. The $ is not displayed, but serves to tell the function when to stop displaying characters in string. Function 4Ch: Return control to DOS. Register AH=4Ch. Returns nothing. Operation: DOS INT 21h, function 4Ch halts the execution of an application program and returns control of the computer to DOS. List of DOS INT21H function are: AH Description 01 Read character from STDIN 05 Write character to printer 02 Write character to STDOUT 06 Console Input/Output 07 Direct char read (STDIN), no echo 08 Char read from STDIN, no echo 09 Write string to STDOUT 0B Get STDIN status 0D Disk reset 0A Buffered input 0C Flush buffer for STDIN 0E Select default drive 25 Set interrupt vector 2B Set system date 2D Set system time 30 Get DOS version 39 Create subdirectory 3B Set working directory 3D Open file 19 Get current default drive 2A Get system date 2C Get system time 2E Set verify flag 35 Get Interrupt vector

36 3A 3C 3F 3E 41 40 42 43 4C 47 54

Get free disk space Remove subdirectory Create file Read file Close file Delete file Write file Seek file Get/Set file attributes Exit program Get current directory Get verify flag

AH Description

4D Get return code 56 Rename file 57 Get/Set file date The MOV instruction is the most important command in the 8086 because it moves data from one location to another. It also has the widest variety of parameters; so it the assembler programmer can use MOV effectively, the rest of the commands are easier to understand. format: MOV destination,source The possible combinations of operands are as follows : destination Register Register Register Memory Memory Source Example mov ax,bx mov ax,10h mov ax,es:[bx] mov aNumber,10h mov aDigit,ax Register Immediate Memory Immediate Register Algorithm 1. Start. 2. Initialize Data segment. 3. Initialize Code segment. 4. Display message using function 09H with INT 21H 5. Return to DOS. 6. Stop. Conclusion: Using DOS interrupt, INT 21H a message was displayed with use of assembler directives and MOV instruction.

Program data segment msg db 0dh,0ah,"hello$" data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov ah,09h mov dx,offset msg int 21h mov ah,4ch int 21h code ends end start OUTPUT

Experiment-2 Aim: Write a program to verify that the number is even or odd. Theory: Conditional Jump Instructions JNC: (jump if not carry) Syntax – JNC Label Label is the next location where control is to be transferred. This instruction transfers control if carry flag is 1. Other Jump Instructions are: Mnemon ic Description Jump condition JC Carry CF = 1 JNC JE/JZ Not Carry CF = 0 ZF = 1 ZF = 0 Equal or Zero JNE/JNZ Not Equal or Not Zero JP/JPE Parity or Parity Even PF = 1 JNP/JPO Not Parity or Parity Odd PF = 0 JO Overflow Not overflow Sign OF = 1 JNO JS OF = 0 SF = 1

JNS Not sign SF = 0 JL/JNGE Less (SF Ex-Or OF) = 1 (SF Ex-Or OF) = 0 JGE/JNL Greater or equal

JLE/JNG Less or equal

JG/JNLE Greater ((SF Ex-Or OF)+ZF)=1 ((SF Ex-Or OF)+ZF)=0 CF = 1 JB/JNAE Below JAE/JNB Above or equal JBE/JNA Below or equal JA/JNBE Above CF = 0 (CF Ex-Or ZF) = 1 (CF Ex-Or ZF) = 0 Unconditional Jump Instruction JMP: Syntax – JMP Label The program sequence is transferred to the memory location specified by the16bit address given in the operand. Eg: - JMP 2034H ( jump to location 2034H) there is no condition to jump. JMP ABC (jump to ABC label) Rotate instructions ROR: (Rotate all bits of operand to right.) Syntax – ROR destination, count This instruction rotates all of the bits of the specified word or byte some number of bit positions to the right. The data bit moved out of the LSB is copied to the CF during ROR. The destination operand can be register or memory location. Count contains the number bits to be rotated. ROL: (Rotate all bits of operand lef.) Syntax – ROL destination, count This instruction rotates all of the bits of the specified word or byte some number of bit positions to the lef. The data bit moved out of the MSB is copied to the CF during ROL.

The destination operand can be register or memory location. Count contains the number bits to be rotated. RCR: (Rotate operand around to the right through CF.) Syntax – RCR destination, count This instruction rotates all of the bits of the specified word or byte some number of bit positions to the right. The operation is circular because the LSB of the operation is rotated into the carry flag and the bit in the carry flag is rotated around into MSB of the operand. The destination operand can be register or memory location. Count contains the number bits to be rotated. RCL: (Rotate operand around to the lef through CF.) Syntax – RCR destination, count This instruction rotates all of the bits of the specified word or byte some number of bit positions to the lef. The operation is circular because the MSB of the operation is rotated into the carry flag and the bit in the carry flag is rotated around into LSB of the operand. The destination operand can be register or memory location. Count contains the number bits to be rotated.

Algorithm 1. Start 2. Initialize data segment 3. Initialize code segment. 4. Get a number from user by function 01h, Read character from STDIN using INT 21h. 5. Rotate the bits of register by 01h to get the LSB into carry flag. 6. Jump to label even, If carry flag=0, else 7. Display number is odd. 8. Jump to label finish. 9. Label even: Display number is even. 10.Label finish: return control to DOS using function 4Ch, INT 21h 11.Stop. Conclusion Rotate over right (ROR) instruction was used to get the last bit of number to carry flag. Conditional Jump instruction JNC was used to check this carry flag for condition of number been even or odd. Unconditional jump JMP was to skip statements not needed. Program data segment msg1 db 0ah,0dh,"Enter a no: $" msg2 db 0ah,0dh,"Numbers is even $" msg3 db 0ah,0dh,"Numbers is odd $" data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov dx,offset msg1 mov ah,09h int 21h s1: mov ah,01h int 21h ror al,01h jnc even1 mov dx,offset msg3 mov ah,09h int 21h jmp finish

even1: mov dx,offset msg2 mov ah,09h int 21h finish: mov ah,4ch int 21h code ends end start OUTPUT...


Similar Free PDFs