• No results found

8086 Software Programs

N/A
N/A
Protected

Academic year: 2021

Share "8086 Software Programs"

Copied!
29
0
0

Full text

(1)

A.

1 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

MICROPROCESSOR LAB

MANUAL (SOFTWARE

PROGRAMS)

Note: Only programs have been given. The method of writing the programs and designing of 8086 program using algorithms is explained in the text book:

“Introduction to microprocessors – 8086”

(2)

A. 2 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

APPENDIX- LAB PROGRAMS

APPENDIX- LAB PROGRAMS

Problem 1.(a): Search a key element in a list of 'n' 16-bit numbers using the binary

search algorithm (Detailed design r efer section 8.10.3, page 8.77)

; Program Name: BINARY SEARCH (BSRCH.ASM) ; Author : A.M. Padma Reddy and YJ

; Purpose : To search for the key in a given list using binary search

; Inputs : List of elements, number of elements, key

; Outputs : Success if key found, Unsuccessful if key not found .MODEL SMALL

; Macro definitions

; Macro definition to display the message

PRINTF MACROMSG ; Here, MSG is the parameter to the macro

MOV AH, 09H

MOV DX, OFFSET MSG INT 21H

ENDM

; Macro to terminate the program (return control to DOS)

EXIT MACRO

MOV AH, 4CH INT 21H

ENDM

;- ---- --- -- Data segment starts- --- --- ---- ---.DATA

A DW 1111H, 2222H, 3333H, 4444H, 5555H N DW ($-A)/2 ; Number of terms of N

KEY DW 5555H ; Key to be searched LOW_ DW ?

HIGH_ DW ? MID DW ?

MSG1 DB “SUCCESSFUL SEARCH”, 0AH, 0DH, 24H MSG2 DB “UNSUCCESSFUL SEARCH”, 0AH, 0DH, 24H

(3)

ends---A.

3 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

;--- --- --Code segment starts---.CODE

begin: ; Initialization of data segment register MOV AX, @DATA

MOV DS, AX

;Initialization for the loop MOV LOW, 0 ; low 0 MOV AX, N ; AX N MOV HIGH_, AX

DEC HIGH_ ; high N -1 ;Search using binary search L1: MOV SI, LOW_ CMP SI, HIGH_

JG L4 ;if ( low > high ) L4

; mid (low + high ) / 2

ADD SI, HIGH_ ; SI low + high SHR SI, 1 ; SI (low + high)/2

; mid (low + high ) / 2

MOV MID, SI ;if ( key != a[mid] ) L2

MOV AX, KEY MOV SI, MID

SHL SI, 1 ; SI should be twice mid

CMP AX, A[SI] JNE L2

PRINTF MSG1 ; print search success EXIT ; Terminate program

L2: CMP AX, A[SI] ; if ( key > a[mid] ) L3

JG L3

; high mid – 1

MOV AX, MID ; AX mid

(4)

A. 4 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

MOV HIGH_, AX ; high mid – 1

JMP L1

; low mid + 1

L3: MOV AX, MID ; AX mid

INC AX ; AX mid + 1

MOV LOW_, AX ; low mid + 1

JMP L1

L4: PRINTF MSG2 ; print search unsuccessful EXIT ; Terminate program

END begin

;--- ---- --- -- Code segment

ends---Note:Since LOW and HIGH are assembler directives in 8086 assembly language, we use the identifiers LOW_ and HIGH_ instead of LOW and HIGH in the above program

(5)

A.

5 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

Problem 2: Write ALP macros:

i) to read a character from the keyboard in the module(1) (in a different file) ii) to display a character in module (2) (from different file)

iii) use the above two modules to read a string of characters from the keyboard terminated by the carriage return and print the string on the display in the next line

Note:Type two programs and save using the names 2A.ASM and 2B.ASMas shown

below:

2A.ASM

.model small .stack

; - Data segment starts --.data

extrn a:byte ;Defines that an array variable a is external to the file msg1 db 0ah,0dh,”Enter the characters:”,24h

msg2 db 0ah, 0dh,”The typed characters:”,24h ;--- --- Data segment ends---;Macro to display the message

printf macro msg

mov ah, 09h ; function to display the text lea dx, msg ; offset value of text to be displayed int 21h

endm

;macro to terminate the program exit macro

mov ah, 4ch ; function to terminate the program int 21h

endm

;--- Code segment starts---.code

extrn getchar:far ;Function getchar is a defined in another file extrn putchar:far ;Function putchar is defined in another file

(6)

A. 6 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

begin: mov ax,@data

mov ds,ax ; Initialization of data segment register printf msg1 ; printf(“Enter the characters”);

mov si, 00 ; Initialize the index si to 0

next: call getchar ; Read a character cmp al, 0dh ; Is character read is end of line

je over

mov a[si], al ; Store the character in the array inc si ; point to next location in array a jmp next ; Read the next character

over: mov cx, si ; Numer of characters to be displayed printf msg2 ; printf(“The typed characters are:”);

mov si, 00 ; Initialize si to point to beginning of a up: mov al,a[si] ; Obtain the character from array call putchar ; Display the current character

inc si ; Point si to next character loop up

mov ah,4ch int 21h end begin

;end of the program

Note: After typing 2A.ASM, Give the following commands:

C:\>MASM 2A; C:\>EDIT 2B.ASM

(7)

A.

7 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

2B.ASM

.model small .stack

; --- --- Start of data segment ---.data

public a ;The data array is being made public allocating

a db 10H dup(?) ; Reserved 10 locations. external function can access a ;--- -- End of data segment ---;--- --Start of code

segment---.code

public getchar ; External program can access getchar() public putchar ; External program can access putchar() ;Procedure to read key is made public

getchar proc far

mov ah,01 ; Function to read a character

int 21h ; Character read is copied to AL register ret

getchar endp

;Procedure to write a character putchar proc far

mov ah,02 ; Function to display the character mov dl,al ; Character to be displayed

int 21h ; Display the character ret

putchar endp end;

;--- --- End of code segment

---Note: After typing 2B.ASM, Give the following commands:

C:\>MASM 2b;

If no errors, type the following command C:\>LINK 2A + 2B

C:> 2A

Enter the characters: PADMAREDDY The typed characters:PADMAREDDY

(8)

A. 8 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

Problem 3: Sort a given set of 'n' numbers in ascending and descending orders using the

bubble sort algorithm. (Refer section 8.10.4, page 8.81)

; Program Name: BUBBLE SORT (BSORT.ASM) ; Author : A.M. Padma Reddy and YJ

; Purpose : To sort the given elements using bubble sort

; Inputs : List of elements to sort

; Outputs : Sorted array .MODEL SMALL

;- ---- --- -- Data segment starts- --- --- ---- ---.DATA

A DW 5555H, 4444H, 3333H, 2222H, 1111H N DW ($-A)/2 ; Number of terms of N

I DW ? J DW ? TEMP DW ?

;--- ---- --- -- Data segment ends---;--- ---- --- -- Code segment starts---.CODE

begin: ; Initialization of data segment register MOV AX, @DATA

MOV DS, AX

MOV J, 1 ; Initial pass MOV CX, N

DEC CX ; CX N-1

L1: MOV SI, 0 ; Index to the first item ; of array A

MOV DX, N

SUB DX, J ; DX = N – J is the ; counter for inner loop

L2: MOV AX, A[SI] ; AX a[si]

(9)

A.

9 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

JLE L3 ; goto L3

MOV TEMP, AX ; temp a[si]

MOV BX, A[SI+2] ; a[si] a[si+2]

MOV A[SI], BX

MOV A[SI+2], AX ; since AX contains ; temp

ADD SI, 2 ; Point to next word

L3: DEC DX ; decrement inner loop JNZ L2 ; if (DX !=0) goto L2

LOOP L1 ; if (CX !=0) goto L1 ; i.e., goto next pass

INT 3H ; Stop execution at this ; point

END begin

(10)

ends---A. 10 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

Problem 4: Read an alphanumeric character and display its equivalent ASCII code at the

center of the screen. (See section 9.3.1, page 9.12)

.MODEL SMALL ; Macro defintions

; Macro to read a character GETCHAR MACRO

MOV AH, 01 ; Function to read a character INT 21H ; AL has the character read ENDM

; Macro display a character PUTCHAR MACRO char

MOV AH, 02 ; Function to display a character MOV DL, char ; Character to be displayed INT 21H

ENDM

;Macro to display the message PRINTF MACRO MSG

MOV AH, 09H ; Function to display the text

LEA DX, MSG ; Offset value of text to be displayed INT 21H

ENDM

;Macro to ternminat the program EXIT MACRO

MOV AH, 4CH ; Function to terminate the program INT 21H

ENDM

;--- ---- --- -Data segment starts--- --- ---- ---- ---.DATA

MSG1 DB "Enter a character",0ah, 0dh, 24h MSG2 DB "The ASCII value: ",24h

(11)

ends---A.

11 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

;--- ---- --- -Code segment starts---.CODE

begin: MOV AX, @DATA ; Initialization of data segment register MOV DS, AX

PRINTF MSG1 ; DISPLAY "Enter a character"

GETCHAR ; Read a character from keyboard

MOV BH, AL ; Character in AL is copied to BL MOV BL, AL ; Copy into BL register also ; Convert the lower nibble into ASCII

AND BL, 0FH ; Mask the higher nibble CMP BL, 0AH

JL L1

ADD BL, 07H ; If greater than 9, ADD 7

L1: ADD BL, 30H ; Convert into ASCII by adding 30H ; Obtain ASCII value of higher nibble

AND BH, 0F0H ; Mask the lower nibble MOV CL, 04

SHR BH, CL ; Move to higher nibble to lower nibble CMP BH, 0AH

JL L2

ADD BH, 07H ; If greater than 9, add 7

L2: ADD BH, 30H ; Conver into ASCII by adding 30H PRINTF MSG2 ; Display "The ASCII Value ="

PUTCHAR BH ; display higher nibble of ASCII value PUTCHAR BL ; display lower nibble of ASCII value EXIT

(12)

A. 12 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY) Problem 5: Reverse a string and check whether it is a palindrome or not

(see section 8.9.4, page 8.62)

; Program Name: PALINDROME(PALI.ASM) ; Author : A.M. Padma Reddy and YJ

; Purpose : To check whether the string is palindrome

; Inputs : Give the string

; Outputs : Palindrome or not a palindrome .MODEL SMALL

; Macro definitions

; Macro definition to display the message

PRINTF MACROMSG ; Here, MSG is the parameter to the macro

MOV AH, 09H

MOV DX, OFFSET MSG INT 21H

ENDM

; Macro to terminate the program (return control to DOS)

EXIT MACRO

MOV AH, 4CH INT 21H

ENDM

;--- Data segment starts--- --- - ; Memory representation .DATA

STR1 DB “LIRIL” ; Given string

N DW $ – STR1 ; Length of given string

STR2 DB 10 DUP(?) ; Storage space for reversed string MSG1 DB “String is palindrome”, 0AH, 0DH, 24H

MSG2 DB “String in not a palindrome”, 0AH, 0DH, 24H ;--- Data segment

ends---;--- ---- --- -- Code segment starts---.CODE

begin: ; Initialization of data segment register MOV AX, @DATA

(13)

A.

13 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

;Initialization for reversing

MOV SI, 0 ; STR1[SI] points to first character of STR1 MOV DI, 0 ; STR2[DI] point to first character of STR2 MOV CX, N ; where N = 5

ADD SI, CX DEC SI

L1: MOV AL, STR1[SI] ; Copy STR1[SI] to MOV STR2[ DI], AL ; STR2[DI]

DEC SI ; Point to previous character INC DI ; Point to next character

LOOP L1 ; Copy all characters of STR1 ; Reversing of string is complete

; Check for the palindrome ; Initialization

MOV SI, 0 ; SI points to beginning of STR1 MOV CX, N ; No. of characters to compare

L2: MOV AL, STR1[SI] ; Compare STR1[SI] with STR2[DI] CMP AL, STR2[SI]

JE L3

PRINTF MSG2 ; String is not a palindrome EXIT ; Terminate the program

L3: INC SI ; Point to next character of STR1&2 LOOP L2 ; Compare N times

PRINTF MSG1 ; String is a palindrome EXIT ; Terminate the program

END begin

(14)

---A. 14 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY) Problem 6 : Read two strings, store them in locations STR1 and STR2.check whether

they are equal or not and display appropriated messages. Also display the length of the

stored strings. (see section 9.3.2, page 9.14)

.MODEL SMALL ; Macro definitions

; Macro to read a character SCANF MACRO BUFFER

MOV AH, 0AH ; Function to read a string LEA DX, BUFFER ; Address of the buffer INT 21H ; AL has the character read ENDM

;Macro to display the message PRINTF MACRO MSG

MOV AH, 09H ; Function to display the text

LEA DX, MSG ; Offset value of text to be displayed INT 21H

ENDM

;Macro to display a character PUTCHAR MACRO CHAR MOV AH, 02

MOV DL, CHAR INT 21H

ENDM

;Macro to terminate the program EXIT MACRO

MOV AH, 4CH ; Function to terminate the program INT 21H

ENDM

;--- ---- --- -Data segment starts--- --- ---- ---- ---.DATA

MSG1 DB 0AH, 0DH,"Enter the first string",0ah, 0dh, 24h MSG2 DB 0AH,0DH,"Enter the second string”, 0ah, 0dh,24h MSG3 DB 0AH,0DH“The two strings are equal”, 0AH, 0DH, 24H

(15)

A.

15 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

MSG4 DB 0AH,0DH“The two strings are not equal”, 0AH, 0DH, 24H MSG5 DB 0AH,0DH“No. of characters in first string :”, 24H

MSG6 DB 0AH, 0DH, “No. of characters in second string :”, 24H BUFFER1 DB 10 N1 DB ? A1 DB 10 DUP(?) BUFFER2 DB 10 N2 DB ? A2 DB 10 DUP(?)

;--- ---- --- -Data segment ends---;--- ---- --- -Code segment starts---.CODE

begin: MOV AX, @DATA ; Initialization of data segment register MOV DS, AX

MOV ES, AX ; Intialization of extra segment r egister ; It is must for string manipulation

PRINTF MSG1 ; printf(“Enter the first string”); SCANF BUFFER1 ; scanf(“%s”,a1);

PRINTF MSG2 ; printf(“Enter the second string”); SCANF BUFFER2 ; scanf(“%s”,a2);

; Check length of two strings MOV AL, N1

CMP AL, N2

JE L1 ; If lengths are equal compare strings

PRINTF MSG4 ; printf(“Two strings are not equal”); JMP L3

; Initialization before comparing

L1: LEA SI, A1 ; Offset value of first string LEA DI, A2 ; Offset value of second string MOV CL, N1 ; No of characters to be compared CLD ; To increment increment index registers REPE CMPSB ; Compare as long as they are equal

(16)

A. 16 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

JCXZ L2 ; If CX is zero, two strings are equal PRINTF MSG4 ; printf(“Two strings are not equal”); JMP L3

L2: PRINTF MSG3 ; printf(“Two strings ar e equal”);

L3: PRINTF MSG5 ; printf(“No. of characters in first string:”); ADD N1, 30H ; Convert to ASCII by adding 30h

PUTCHAR N1 ; display no of characters of first string PRINTF MSG6 ; printf(“No. of charas in second string:”) ; ADD N2, 30H ; Convert to ASCII by adding 30h

PUTCHAR N2 ; display no. of characters of second string EXIT ; Terminate the program

END begin

; - - --End of code segment-- ---

(17)

---A.

17 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

Problem 7 : Read your name from the keyboard and display it at a specified location on

the screen in front of the message WHAT IS YOUR NAME? you must clear the entire

screen before display. .model small

;Macro to clear the screen clrscr macro

mov bh,07 ;Attribute of character

mov ah,06 ;Activity is to scroll

mov al,0 ;No. of lines to scroll-0 blank screen

mov ch,00 ;y-coordinate of upper left corner

mov cl,00 ;x-coordinate of upper right corner mov dh,24 ;Number of rows; Lower right row

mov dl,80 ;Number of columns; Lower right column int 10h ; clear the screen

endm

;Macro to set the cursor ;

setcursor macro row, col ; row and col are the parameters mov ah, 02 ; Function to set the cursor

mov bh, 0 ; Current page mov dh, row ; Which row mov dl, col ; Which column int 10h ; Set the cursor endm

;Macro equvivalent to ; printf()

; scanf()

pri_scn macro val, msg ; val – function to read or display ; msg is the parameter to be displayed

mov dx, offset msg ; DX holds offset of message to be displayed mov ah, 09 ; Function to display the message

int 21h ; Display the message endm

(18)

A. 18 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

;Macro terminate the program ;Return control to dos

;

stop macro

mov ah, 4ch ; Function to terminate int 21h ; Terminate the program endm

;

;Macro display the character ; putchar() function of C ;

putchar macro val ; val is the parameter to be displayed mov dl,val ; Character to be displayed

mov ah,02 ; Function to write a character int 21h ; Display the character

endm

;---Start of the data segment---.data

name1 db "What is your name?",24h msg db "Enter the name",0ah,0dh,24h

buffer db 10 ; Max. no. of charcters in the name n db ? ; Space to store length of name a db 20 dup(?) ; Space to store the name row db 10 ; Display at this row

col db 20 ; Display at this column ;----Start of code segment ---.code

mov ax, @data mov ds, ax

prn_scn 09, msg ;printf("Enter the numbers"); prn_scn 0ah, buffer ;scanf("%s",a);

(19)

A.

19 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

setcursor row, col ; Set the cursor

prn_scn 09, name1 ; printf(“What is your name?”); mov cl,n

mov ch,0 ; CX: no. of characters to displayed mov si,00 ; initial offset value w.r.t. array a top: putchar a[si] ; Display the character inc si ; Point to next character

loop top ; If not over go to top stop ; Terminate the program end begin

(20)

A. 20 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

Problem 8 : Compute nCr using recursive procedure. Assume that 'n' and 'r' are

non-negative integers (See section 9.5.1.2, page 9.32 for details)

.MODEL SMALL .STACK 64

;--- ---- --- ---- -Start of data segment---.DATA

N DB 6 K DB 3 RES DB 0

;--- ---- --- --- --Start of data ;--- ---- --- ---- -Start of code segment---.CODE

NCK PROC CMP BL, 0

JNE L1 ; if k = 0

ADD RES, 1 ; return 1; RET

L1: CMP BL, AL JNE L2 ; if k = n

ADD RES, 1 ; return 1; RET

L2: CMP BL, 1 JNE L3 ; if k = 1

ADD RES, AL ; return n RET L3: DEC AL ; n = n -1 CMP BL, AL JNE L4 ; if k = n INC AL ; return n+1 ADD RES, AL RET

(21)

A.

21 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

L4: PUSH AX ; Compute n-1C k PUSH BX CALL NCK POP BX POP AX DEC BX ; k = k -1 PUSH AX ; Compute n-1C k-1 PUSH BX CALL NCK POP BX POP AX RET NCK ENDP

begin: MOV AX,@DATA ; Initialization of DS register MOV DS,AX

MOV AL,N ;Compute nCk MOV BL,K

CALL NCK

INT 3H ; Terminate the program END begin

;--- ---- --- ---- --end of the code segment

---Output: Give the following commands

C:\> MASM NCK; C:\> LINK NCK;

C:\> DEBUG NCK.EXE -G

-D DS:0000

The following memory dump is obtained:

14D4:0000 D8 A0 0C 00 8A 1E 0D 00-E8 B5 FF CC 06 03 148F n k nCk = 14H

6C = (20)

(22)

A. 22 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

Problem 9 : Read the current time from the system and display it in the standard format

on the screen. .model small .stack

;Macro display the character putchar macro val

push ax

mov dl,val ; Character to display

mov ah,02 ; Function to display the character int 21h ; Display the character

pop ax endm

;---Start of the code segment ---.code

; Procedure to convert from HEX to ASCII and display hex_asc proc

mov ah,00

mov bl,0ah ; Divide by 10 to obtain unpacked BCD div bl ; Obtain the unpacked BCD in AH and AL ; Higher nibble in AL

; Lower nibble in AH

add ax,3030h ; Convert to ASCII value putchar al ; Display the character in AL putchar ah ; Display the character in AH ret

disp endp

begin: mov ah, 2ch ; Function to read the system time int 21h ; Read the system time

: CH:CL contains hours:minutes ; DH:DL contains second:millisec

(23)

A.

23 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

mov al, ch ; Display the hour call disp

putchar ':'

mov al,cl ; Display the minute call disp

putchar ':'

mov al,dh ; Display the second call disp

exit ; Terminate the program end begin

(24)

A. 24 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY) Problem 10 : Program to simulate a decimal up-counter to display 00-99

.model small .stack

;Macro to display a character putchar macro val

push dx push ax

mov dl,val ; Character to be displayed mov ah,02 ; Function to read character int 21h ; Read a character

pop ax pop dx endm

;Code segment starts .code

;Procedure to convert packed BCD to ASCII and display the character dec_asci proc

mov cl,04

mov bh,al ; AL has the packed bcd

shr bh,cl ; Move the higher nibble to lower nibble mov bl,al

and bl,0fh ; Mask the higher nibble add bx,3030h ; Convert to ASCII putchar bh ; Display higher nibble putchar bl ; Display lower nibble putchar 0ah ; Move cursor to next line

putchar 0dh ; Move cursor to beginning of current line ret

(25)

A.

25 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

; Main program starts from here begin: mov al,00

top: daa ; convert to decimal

call dec_asci ; convert to ASCII and display cmp al,99h ; Have you reached 99

je down ; If yes go down add al,01 ; Increment count by 1 jmp top ; perform earlier task down:

mov ah,4ch ; Function to terminate the program int 21h ; Terminate the program

(26)

A. 26 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

Problem 11 : read a pair of input co=ordinates in BCD and move the cursor to the

specified location on the screen. .model small

; Cursor to set at the specified row and column setcursor macro row, col

mov ah, 02 ; Function to set cursor mov bh, 00 ; page number

mov dh, row ; Set at this row mov dl, col ; Set at this column int 10h

endm

;Macro to terminate the program exit macro

mov ah, 4ch ; Function to terminate the program int 21h ; Terminate the program

endm

;Macro to read a character getchar macro

mov ah,01h ; Function to read a character int 21h ; AL contains the character typed endm

;Macro to display the message

printf macro msg ; msg is the parameter to be displayed mov ah, 09 ; Function to display the message

mov dx, offset msg ; DX hold offset of message to be displayed int 21h ; Display the message

endm .data

row db ? ; Space to store row value col db ? ; Space to store column value msg1 db "Enter the row value :",0ah,0dh,24h msg2 db "Enter the col value :",0ah,0dh,24h .code

(27)

A.

27 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

; Procedure to read a byte and convert it to packed BCD read proc

getchar ; Get an ASCII value

sub al, 30h ; Convert into unpacked BCD mov cl, 4

shl al, cl ; Make it higher nibble mov bl, al ; Save higher nibble in BL

getchar ; Get next ASCII value

sub al, 30h ; Convert into unpacked BCD

add al, bl ; Convert 2 unpacked BCD to packed BCD ret

read endp

begin: mov ax, @data ; Initialization of DS register mov ds, ax

printf msg1 ; printf("Enter row value"); call read ; scanf("%d",&row); mov row, al ; Save the row value

printf msg2 ; printf("Enter col value"); call read ; scanf("%d",&col);

mov col, al ; Save the column value

setcursor row,col ; Set the cursor at specified row, column

getchar ; Read a character

exit ; Terminate the program end begin

C:\MASM615>cursor Enter the row value :10 Enter the col value :20

(28)

A. 28 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY) Problem 12 : program to create a file (input file) and to delete an existing file

.model small .stack

; Macro to display the message and read the string

prn_scn macro val,msg ; val = 09 display the message msg ; val = 09 read into msg

mov ah,val ; Function to read or print

mov dx,offset msg ; Offset value of message or buffer int 21h ; Read or write

endm

;Macro to terminate the program exit macro

mov ah,4ch ; Function to terminate the program int 21h ; Terminate the program

endm .data

msg1 db "Enter the file :",0ah,0dh,24h

buff db 20 ; Max. no. of characters in the file len db ? ; Length of file name

fname db 20 dup(?) ; Space for storing the file name msg2 db 0ah,0dh,"File successfully deleted",24h

msg3 db 0ah,0dh,"Error in deleting: File may not exist or readonly",24h ;--- --Start of code segment

---.code

mov ax,@data mov ds,ax

prn_scn 09,msg1 ; printf(“Enter the file name”);; prn_scn 0ah, buff; ; scanf( “%s”,fname);

(29)

A.

29 LAB PROGRAMS (SAI VIDYA INSTITUTE OF TECHNOLOGY)

;Attach ASCIIZ at the end of the file mov bx,00

add bl,len ; Length of file name

mov fname[bx] ,0 ; Store ASCIIZ at the end of file name ;Delete the file

mov ah,41h ; Function to delete the file

mov dx,offset fname ; DX contains name of file int 21h ; Delete the file

jc fail ; If Carray is set delete failed prn_scn 09,msg2 ; File deleted successfully exit ; Terminate the program

fail: prn_scn 09h,msg3 ; File not deleted exit ; Terminate the program

References

Related documents

Department of Public Health Basic Nursing Assistant Program.. Approved programs can be

ing of the components of the quality of life according to some set of values is taking place all the time.' In terms of the conceptual scheme we have used, even if

labour and capital, total factor productivity and size of typical fi rm are not ro- bust determinants of emissions from industrial sector but on the other hand, energy intensity,

In order to analyze the impact of alternative forms of communication into the strategy of traditional telecommunication companies it is impossible to draw trends without doing a

Total Asset Turnover Working Capital Inventory Turnover EBITDA Revenue Growth Working Capital Days Sales Outstanding Accounts Receivable Turnover EBITDA Revenue Growth ASSET

Effective deployment of public- access automated external defibrillators to improve out- of- hospital cardiac

Typical enterprise hardware and software to enable public access can cost US $50k+. Internal access can

Typically you configure a port forwarding rule so a host on the external network can access a server on the internal network by using the public IP address (or hostname) of

The Internet users behind your LAN can not access your external public IP address and come back in; the internal users shall access the server on its local private IP address, or

The external firewall can restrict public access to it while allowing the remaining UNSW network (LAN) to access them in order to update records so that the government departments

volve the use of additional applicators in a single treatment, as well as multiple sessions to achieve the patient’s desired aesthetic outcome over time.. “By simply

As miR-containing MV regulate vascular function and disease progression, a detailed exploration of miRs expression in circulating MV in patients with stable CAD,

– Character input/output (getchar and putchar) o Deterministic finite automata (i.e., state machine) o Expectations for programming assignments.. • C

Thus, those with high-math abilities prior to college, as measured by the average SAT Math scores of those graduating within a specific college major, are more likely to graduate

Then we assess the breakdown of religious PVOs (14 types) in terms of the 8 groups that comprise most PVO activity by numbers and dollars: Mainline Protestant, Catholic,

Composites or dispersed phase solid electrolytes have emerged as a good system of multiphase ionic materials for developing solid state ionic devices [1, 2]. This provides

Includes: CHOICE All Included TV Pkg, monthly service & equipment fees for one Genie HD DVR, and standard pro installation.. Additional Fees & Taxes: Price excludes

 Public-Facing/Public Access, with no access to internal systems  Public-Facing/Public Access, with access to internal systems  Public-Facing/Limited Access, requiring login

More specifically, there was a higher percentage of persons with private insurance only all year (78.5 percent), public insurance only all year (84.5 percent), and a combination

getchar returns a special non-ASCII value to indicate there is no input was available.. This non-ASCII value is #defined as EOF

An external vulnerability assessment will assess your environment from an external or public view to identify vulnerabilities that may allow access to confidential areas of a

Any fault detection and diagnosis system for a safety critical system has to fulfill strong safety specifications which can be expressed in terms of different performance criteria