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

Cse 316 (Lab - 3) Ibm Character Display and First and Last Capitals

This document contains two assembly language programs. The first program displays all ASCII characters from 0 to 255 on the screen. The second program reads a line of text from the user and identifies the first and last capital letters, displaying the results. It initializes data segments, displays a prompt, reads characters in a loop until carriage return, tracking the first and last capital letters, and finally displays the results or a "no capitals" message.

Uploaded by

Mehedi Al Masum
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Cse 316 (Lab - 3) Ibm Character Display and First and Last Capitals

This document contains two assembly language programs. The first program displays all ASCII characters from 0 to 255 on the screen. The second program reads a line of text from the user and identifies the first and last capital letters, displaying the results. It initializes data segments, displays a prompt, reads characters in a loop until carriage return, tracking the first and last capital letters, and finally displays the results or a "no capitals" message.

Uploaded by

Mehedi Al Masum
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

CSE 316 (Lab -3) IBM CHARACTER

DISPLAY and FIRST AND LAST CAPITALS

TITLE PGM6_1: IBM CHARACTER DISPLAY


.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH,2 ;display char function
MOV CX,256 ;no. of chars to display
MOV DL,0 ;DL has ASCII code of null char
PRINT_LOOP:
INT 21h ;display a char
INC DL ;increment ASCII code
DEC CX ;decrement counter
JNZ PRINT_LOOP ;keep going if CX not 0
;DOS exit
MOV AH,4CH
INT 21h
MAIN ENDP
END MAIN

TITLE PGM6_2: FIRST AND LAST CAPITALS


.MODEL SMALL
.STACK 100H

.DATA
PROMPT DB 'Type a line of text',0DH,0AH,'$'
NOCAP_MSG DB 0DH,0AH,'No capitals $'
CAP_MSG DB 0DH,0AH,'First capital = '
FIRST DB ']'
DB ' Last capital = '
LAST DB '@ $'

.CODE
MAIN PROC
;initialize DS
MOV AX,@DATA
MOV DS,AX
;display opening message
MOV AH,9 ;display string function
LEA DX,PROMPT ;get opening message
INT 21H ;display it
;read and process a line of text
MOV AH,1 ;read char function
INT 21H ;char in AL
WHILE:
;while character is not a carriage return do
CMP AL,0DH ;carriage return?
JE END_WHILE ;yes, exit
; if character is a capital letter
CMP AL,'A' ;char >= 'A'?
JNGE END_IF ;not a capital letter
CMP AL,'Z' ;char <= 'Z'?
JNLE END_IF ;not a capital letter
;then
;if character precedes first capital
CMP AL,FIRST ;char < FIRST?
JNL CHECK_LAST ;no, >=
;then first capital = character
MOV FIRST,AL ;FIRST = char
;end_if
CHECK_LAST:
;if character follows last capital
CMP AL,LAST ;char > LAST?
JNG END_IF ;no, <=
;then last capital = character
MOV LAST,AL ;LAST = char
; end_if
END_IF:
;read a character
INT 21H ;char in AL
JMP WHILE ;repeat loop
END_WHILE:
;display results
MOV AH,9 ;display string function
;if no capitals were typed
CMP FIRST,']' ;FIRST = ']'
JNE CAPS ;no, display results
;then
LEA DX,NOCAP_MSG ;no capitals
JMP DISPLAY
CAPS:
LEA DX,CAP_MSG ;capitals
DISPLAY:
INT 21H ;display message
;end_if
;dos exit
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN

You might also like