Lab SoftwarePrg
Lab SoftwarePrg
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
.MODEL SMALL
.DATA
STR1 DB 100,?,100 DUP ('$')
STR2 DB 100,?,100 DUP ('$')
LEA DX,STR1
MOV AH,10
INT 21H
DISP MSG2
LEA DX,STR2
MOV AH,10
INT 21H
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.
.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.
.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
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
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
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,
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
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
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
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
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