0% found this document useful (0 votes)
15 views12 pages

Bsef24m040 # 4

Uploaded by

crackingmyself58
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views12 pages

Bsef24m040 # 4

Uploaded by

crackingmyself58
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Name: Muhammad Muwahid Cheema

Roll No: BSEF24M040

Subject: Computer Organization & Assembly Language

Pre lab # 4
1. Write a program to display a “?”, read two capital letters, and display them on the next

line in alphabetical order.

.MODEL SMALL

.STACK 100H

.DATA

.CODE

MAIN PROC

;PRINT ?

MOV DL,'?'

MOV AH,02

INT 21H

;INPUT # 1

MOV AH,01

INT 21H

MOV BL,AL

;INPUT # 2

MOV AH,01

INT 21H

MOV BH,AL
;COMPARISON OF ALPHABETS

CMP BL,BH

JNLE DISPLAY_2ND

;DISPLAY_1ST_FIRST

DISPLAY_1ST:

MOV DL,10

MOV AH,02

INT 21H

MOV DL,13

MOV AH,02

INT 21H

MOV DL,BL

MOV AH,02

INT 21H

MOV DL,BH

MOV AH,02

INT 21H

JMP END_

;DISPLAY_2ND_FIRST

DISPLAY_2ND:

MOV DL,10

MOV AH,02
INT 21H

MOV DL,13

MOV AH,02

INT 21H

MOV DL,BH

MOV AH,02

INT 21h

MOV DL,BL

MOV AH,02

INT 21H

;END_PROGRAM

END_:

MOV AH,4CH

INT 21H

MAIN ENDP

END MAIN

2. Write a program to display the extended ASCII characters (ASCII codes 80h to FFh).

Display 10 characters per line, separated by blanks. Stop after the extended characters

have been displayed once.


.MODEL SMALL

.STACK 100H

.DATA

INCR DB 80H

SPACE DB ' ','$'

.CODE

MAIN PROC

MOV AX,@DATA

MOV DS,AX

WHILE:

;CHECK IF IT REACHES FFH

CMP INCR,0FFH

JE EXIT

;PRINTS CHARACTER

MOV DL,INCR

MOV AH,02

INT 21H

;PRINTS SPACE

MOV DL,OFFSET SPACE

MOV AH,09H

INT 21H

;INCREASE CHARACTER

INC INCR

;JUMPS TO WHILE

JMP WHILE
EXIT:

MOV AH,4CH

INT 21H

MAIN ENDP

END MAIN

3. Write a program that will prompt the user to enter a hex digit character ("0"..."9" or

"A"..."F"), display it on the next line in decimal, and ask the user if he or she wants to do

it again. If the user types "y" or "Y", the program repeats; if the user types anything else,

the program terminates. If the user enters an illegal character, prompt the user to try

again.

4. Do programming exercise 3, except that if the user fails to enter a hex-digit character

in three tries, display a message and terminate the program.

.MODEL SMALL

.STACK 100H

.DATA

PEND DB 'YOU HAVE ENTERED 3 IN-VALID SYMBOLS!$'

ENTRY DB 'ENTER A HEX-DIGIT: $'

DECI DB 'IN DECIMAL IT IS: $'

VAR DB 'DO YOU WANT TO ENTER ANOTHER NUMBER? $'

CHOICE DB 0AH

.CODE

MAIN PROC

;MOVES DATA TO DS
MOV AX,@DATA

MOV DS,AX

;SET COUNTER FOR INPUT VALIDATION

MOV CX,03

;STARTS THE PROCESS

START:

;TAKES CURSOR TO NEXT LINE

MOV DL,10

MOV AH,02

INT 21H

;TAKES CURSOR TO LEFT

MOV DL,13

MOV AH,02

INT 21H

;ENTRY PRINTER

MOV DL,OFFSET ENTRY

MOV AH,09

INT 21H

;TAKES INPUT

MOV AH,01

INT 21H

MOV BL,AL

;CHECKS HEXA-DIGIT

CMP BL,'9'

JBE IS_DIGIT

CMP BL,'F'
JBE IS_ALPHABET

;CONFIRMS VALIDATION

DEC CX

CMP CX,0

JE TERMINATOR

JMP START

;CHANGE DIGIT TO DECIMAL

IS_DIGIT:

SUB BL,30H

ADD BL,30H

JMP DISPLAY

;CHANGE ALPHABET TO DECIMAL

IS_ALPHABET:

;TAKES CURSOR TO NEXT LINE

MOV DL,10

MOV AH,02

INT 21H

;TAKES CURSOR TO LEFT

MOV DL,13

MOV AH,02

INT 21H

;DECIMAL STRING PRINT

MOV DL,OFFSET DECI

MOV AH,09

INT 21H

;PRINTS DECIMALS
MOV DL,31H

MOV AH,02

INT 21H

SUB BL,11H

;DISPLAY DECIMAL

MOV DL,BL

MOV AH,02

INT 21H

JMP GET_CHOICE

DISPLAY:

;TAKES CURSOR TO NEXT LINE

MOV DL,10

MOV AH,02

INT 21H

;TAKES CURSOR TO LEFT

MOV DL,13

MOV AH,02

INT 21H

;DECIMAL STRING PRINT

MOV DL,OFFSET DECI

MOV AH,09

INT 21H

;PRINTS DECIMALS

MOV DL,BL

MOV AH,02

INT 21H
GET_CHOICE:

;TAKES CURSOR TO NEXT LINE

MOV DL,10

MOV AH,02

INT 21H

;TAKES CURSOR TO LEFT

MOV DL,13

MOV AH,02

INT 21H

;DISPLAY CHOICE MSG

MOV DL,OFFSET VAR

MOV AH,09

INT 21H

;GET CHOICE

MOV AH,01

INT 21H

MOV CHOICE,AL

;CHECK CHOICE VALIDATION

CMP CHOICE,'Y'

JE START

CMP CHOICE,'y'

JE START

CMP CHOICE,'N'

JMP END_

CMP CHOICE,'n'

JMP END_
JMP END_

;PRINTS MESSAGE IN CASE OF 3 WRONG TRIES

TERMINATOR:

;TAKES CURSOR TO NEXT LINE

MOV DL,10

MOV AH,02

INT 21H

;TAKES CURSOR TO LEFT

MOV DL,13

MOV AH,02

INT 21H

;STRING PRINTER

MOV DL,OFFSET PEND

MOV AH,09

INT 21H

;END THE PROGRAM

END_:

MOV AH,4CH

INT 21H

;END THE PROGRAM

MAIN ENDP

END MAIN

5. (hard) Write a program that reads a string of capital letters, ending with a carriage

return, and displays the longest sequence of consecutive alphabetically increasing capital

letters read.
.MODEL SMALL

.STACK 100H

.DATA

BUFFER DB 50

DB ?

DB 50 DUP(?)

MSG1 DB 'Enter a string: $'

MSG2 DB 'You entered: $'

.CODE

MAIN PROC

MOV AX, @DATA

MOV DS, AX

;Display "Enter a string:"

MOV AH, 09H

MOV DX, OFFSET MSG1

INT 21H

;Input string

MOV AH, 0AH

MOV DX, OFFSET BUFFER

INT 21H

;TAKES CURSOR TO NEW LINE

MOV DL,10

MOV AH,02

INT 21H

;TAKES CURSOR TO LEFT

MOV DL,13
MOV AH,02

INT 21H

;Display "You entered:"

MOV AH, 09H

MOV DX, OFFSET MSG2

INT 21H

;Print the string entered

MOV SI, OFFSET BUFFER + 2

MOV CL, [BUFFER + 1]

MOV CH, 0

PRINT_LOOP:

MOV DL, [SI]

MOV AH, 02H

INT 21H

INC SI

LOOP PRINT_LOOP

; Exit program

MOV AH, 4CH

INT 21H

MAIN ENDP

END MAIN

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy