0% found this document useful (0 votes)
42 views

Lab SoftwarePrg

This document contains code to: 1. Read two 8-bit hex numbers from keyboard and store in locations str1 and str2 2. Compare the strings and display if they are equal or not equal 3. Also display the length of each string It also contains code to: 1. Read a password from the user and validate it against a predefined password 2. Display if the password is correct or wrong 3. Also display the character count of the password Finally, it contains code snippets to: 1. Read a 4-digit hex number from the user 2. Convert the hex number to decimal 3. Display the decimal number

Uploaded by

Rajiv Seth
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Lab SoftwarePrg

This document contains code to: 1. Read two 8-bit hex numbers from keyboard and store in locations str1 and str2 2. Compare the strings and display if they are equal or not equal 3. Also display the length of each string It also contains code to: 1. Read a password from the user and validate it against a predefined password 2. Display if the password is correct or wrong 3. Also display the character count of the password Finally, it contains code snippets to: 1. Read a 4-digit hex number from the user 2. Convert the hex number to decimal 3. Display the decimal number

Uploaded by

Rajiv Seth
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Part A – Software Programs

Write an 8086 ALP to read two strings, store them in locations str1, str2, check
whether they are equal or not and display appropriate messages. Also display the
length of the stored strings

DISPSTR MACRO MSG


MOV DX,OFFSET MSG
MOV AH,09H
INT 21H
ENDM

.MODEL SMALL
.DATA
STR1 DB 100,?,100 DUP ('$')
STR2 DB 100,?,100 DUP ('$')

MSG1 DB 10,13,"Enter the String1$"


MSG2 DB 10,13,"Enter the String2$"
MSG3 DB 10,13,"Strings Equal$"
MSG4 DB 10,13,"Strings Not Equal$"
MSG5 DB 10,13,"length of the string1 ="
POS DB "$$$"
MSG6 DB 10,13,"length of the string2 ="
POS1 DB "$$$"
.CODE
MOV AX,@DATA
MOV DS,AX
MOV ES,AX
DISP MSG1

LEA DX,STR1
MOV AH,10
INT 21H

DISP MSG2

LEA DX,STR2
MOV AH,10
INT 21H

;check for lenth of strings..equal or not equal


MOV AL,STR1+1
CMP AL,STR2+1
JNE NOTEQUAL
;compare the strings at str1+2 and str2+2

LEA SI,STR1+2
LEA DI,STR2+2
MOV CH,00
MOV CL,STR1+1 ;length of the string
CLD ;clear the direction flag
REPE CMPSB ;compare two strings pointed by SI& DI
JNE NOTEQUAL
DISP MSG3
JMP EXIT
NOTEQUAL:
DISP MSG4
EXIT:
MOV AL,STR1+1
AAM
ADD AX,3030H
MOV POS,AH
MOV POS+1,AL
DISP MSG5

MOV AL,STR2+1
AAM
ADD AX,3030H
MOV POS1,AH
MOV POS1+1,AL
DISP MSG6

MOV AH,4CH
INT 21H
END
;reading the string using function 0Ah,INT 21h
;i/p - DX contains address of memory buffer reserved
; let say, STR1 DB 10,?,10 DUP(?) means
; MOV DX,offset STR1
; MOV AH,0Ah
; INT 21H
; -first location of the buffer indicates the function, max no. of chars
; to be read by the user, terminated by CR
;o/p -
; -second location will be filled by the function, no.of chars. entered
; -ascii codes of the chars entered are stored from STR1+2 address
;string is terminated by enter key, the count donot includes enter key(0dh)
;if u enter more chars then specified, it will generate beep
Write an 8086 ALP to read password and validate the user and display appropriate
message, also display the count of characters in the password.

DISPSTR MACRO MSG


MOV DX,OFFSET MSG
MOV AH,09H
INT 21H
ENDM

.MODEL SMALL
.DATA
USRPWD DB 50 DUP(?) ;space for storing password from user
SYSPWD DB "RVCECSE" ;system defined password
MES1 DB "Enter the Password...",13,10,'$'
MES2 DB 10,13,"CorrectPassword...$"
MES3 DB 10,13,"WrongPassword....$"
MES4 DB 10,13,"No.Of.Chars = "
LEN DB "$$$"
.CODE
MOV AX,@DATA
MOV DS,AX
MOV ES,AX
;read the password
DISPSTR MES1
LEA BX,USRPWD
MOV CX,00
CONT:
MOV AH,08H ;function to read the char without echo
INT 21H
CMP AL,13 ; compare with the enter key(CR)
JE SKIP
;store the character entered in memory
INC CX ;count of chars entered
MOV [BX],AL
INC BX
;display the '*' instead of character entered
MOV DL,'*'
MOV AH,02H ;function to display a single character
INT 21H
JMP CONT
SKIP: ;compare the password entered with the actual password
PUSH CX
CMP CX,07 ;check the lengths
JNE NOTEQ
LEA SI,USRPWD
LEA DI,SYSPWD
CLD
REPE CMPSB ;compare the two strings
JNE NOTEQ
DISPSTR MES2
JMP EXIT
NOTEQ: DISPSTR MES3
EXIT: POP AX
AAM
ADD AX,3030H
MOV LEN,AH
MOV LEN+1,AL
DISPSTR MES4
MOV AH,4CH
INT 21H

END
;----------------------------------------------------------
;Dos function call to read the character without echo
;Function no-AH=08H,INT 21h
;i/p
;o/p returns the character read in AL(Ascii code)
;----------------------------------------------------------
Write an 8086 ALP to read the 4 digit hex number and convert 4digit Hex number to
decimal number, and display the decimal number.

DISPSTR MACRO MSG ;macro to diplay the string


LEA DX,MSG
MOV AH,09
INT 21H
ENDM

.MODEL SMALL
.STACK
.DATA
MSG1 DB 13,10, "Enter the 4digit Hex number:>$:"
MSG2 DB 13,10, "Converted DecimalNumber:> $"
.CODE

MOV AX,@DATA
MOV DS,AX
DISPSTR MSG1
;read first 2 digits of 4 digit hex number
CALL READ_8
MOV BL,AL
;read next 2 digits of 4 digit hex number
CALL READ_8
MOV AH,BL
PUSH AX
DISPSTR MSG2
POP AX
;convert and display the result on the screen
CALL DISP_16
;return to dos
MOV AH,4CH
INT 21H

READ_8 PROC NEAR


;i/p- none
;o/p- AL contains the 2 digit hex/dec number
PUSH BX
PUSH CX
;read the first decimal/hex digit

MOV AH,01
INT 21H
SUB AL,30H ;convert ascii to digit
CMP AL,09H
JLE SKIP
SUB AL,07H ;if digit is hex, sub 7 more: 41(ascii of A)-39(ascii of 9)=7
SKIP:MOV CL,4 ;shift 4 bit to make the first digit as MSB digit and keep it
SHL AL,CL
MOV BL,AL ; in BL reg temporarily

;read the second decimal/hex digit

MOV AH,01
INT 21H
SUB AL,30H
CMP AL,09H
JLE SKIP1
SUB AL,07H
SKIP1:OR AL,BL ; combine the MSB digit saved in BL with LSB digit in AL

POP CX
POP BX
RET
READ_8 ENDP

DISP_16 PROC ;displays the decimal equivalent of 4 digit hex number


;i/p- AX contains 4digit hex/binary number
;o/p- none
PUSH BX
PUSH CX
PUSH DX
MOV CX,05 ; max of 5 digits for decimal no, corresponding to 4 digit hex no.
DR1: MOV DX,0000 ;(ex: for FFFF, decimal no- 65535)
MOV BX,10 ;divide by 10 to extract digits of decimal no, from hexadecimal no.
DIV BX ; DX:AX/BX AX-QUOTIENT,DX-REMAINDER
PUSH DX ;push the extracted decimal digits to stack
LOOP DR1

MOV CX,05
DR2: POP DX ;restore from the stack, decimal digits one by one in the reverse order
ADD DL,'0' ;add ‘0’ is equivalent to adding 30h, i.e to convert to ASCII code for display
MOV AH,02; DOS service to display a character, whose ASCII code is in DL reg
INT 21H
LOOP DR2
POP DX
POP CX
POP BX
RET
DISP_16 ENDP
Write 8086 ALP Procedures to perform the following functions,

i) “read_8” – read 2 digit hex number(8bitNo) from keyboard, and return in


AL reg

ii) “disp_16” - display decimal value of 16 bit BinaryNo given in AX register

Using the above procedures write an ALP to read 8bit number and compute its
factorial and display the result. Store the procedures in different file and link it
with the main program.

7A.ASM
------------
DISPSTR MACRO MSG ;macro to diplay the string
LEA DX,MSG
MOV AH,09
INT 21H
ENDM

;following procedures are declared in other module

EXTRN READ_8:NEAR
EXTRN DISP_16:NEAR

.MODEL SMALL
.DATA
MES1 DB "Enter Number!(LessThan9>...",13,10,'$'
MES2 DB 13,10,"Factorial = $"

.STACK

.CODE
MOV AX,@DATA
MOV DS,AX
DISPSTR MES1
CALL READ_8 ;read 2 digit hex/dec number
MOV AH,00
CALL FACT ;call factorial(recursive procedure)
PUSH AX
DISPSTR MES2
POP AX
CALL DISP_16 ;display the answer(AX) in decimal format
MOV AH,4CH
INT 21H
FACT PROC
;i/p AX-no. whose factorial is to be computed(lessThan 9)
;o/p AX-factorial
CMP AX,00
JNE FNEXT
MOV AX,0001
RET
FNEXT: PUSH AX
DEC AX
CALL FACT
POP BX
MUL BX
RET
FACT ENDP

END

7AB.ASM
--------------
.MODEL SMALL
.CODE
PUBLIC READ_8
PUBLIC DISP_16

READ_8 PROC NEAR


;i/p- none
;o/p- AL contains the 2 digit hex/dec number
PUSH BX
PUSH CX
;read the first decimal/hex digit

MOV AH,01
INT 21H
SUB AL,30H ;convert ascii to digit
CMP AL,09H
JLE SKIP
SUB AL,07H ;if digit is hex, sub 7 more: 41(ascii of A)-39(ascii of 9)=7
SKIP:MOV CL,4 ;shift 4 bit to make the first digit as MSB digit and keep it
SHL AL,CL
MOV BL,AL ; in BL reg temporarily

;read the second decimal/hex digit

MOV AH,01
INT 21H
SUB AL,30H
CMP AL,09H
JLE SKIP1
SUB AL,07H
SKIP1:OR AL,BL ; combine the MSB digit saved in BL with LSB digit in AL

POP CX
POP BX
RET

READ_8 ENDP

DISP_16 PROC ;displays the decimal equivalent of 4 digit hex number


;i/p- AX contains 4digit hex/binary number
;o/p- none
PUSH BX
PUSH CX
PUSH DX
MOV CX,05 ; max of 5 digits for decimal no, corresponding to 4 digit hex no.
DR1: MOV DX,0000 ;(ex: for FFFF, decimal no- 65535)
MOV BX,10 ;divide by 10 to extract digits of decimal no, from hexadecimal no.
DIV BX ; DX:AX/BX AX-QUOTIENT,DX-REMAINDER
PUSH DX ;push the extracted decimal digits to stack
LOOP DR1

MOV CX,05
DR2: POP DX ;restore from the stack, decimal digits one by one in the reverse order
ADD DL,'0' ;add ‘0’ is equivalent to adding 30h, i.e to convert to ASCII code for display
MOV AH,02; DOS service to display a character, whose ASCII code is in DL reg
INT 21H
LOOP DR2
POP DX
POP CX
POP BX
RET
DISP_16 ENDP

END

1. assemble 7A.ASM
>MASM/ZI 7A.ASM;
2. assemble 7AB.ASM
>MASM/ZI 7AB.ASM;
3. link both the object files..
>LINK/CO 7A.OBJ 7AB.OBJ;
4. run 6A, directly/or using CV

You might also like