Professional Documents
Culture Documents
Ass#2
Ass#2
Ass#2
University Lahore
Computer Organization
and Assembly language
Assignment # 2
Section: BCS-A
Due Date
Sample interface:
Code:
.MODEL SMALL
.STACK 100h
.DATA
MSG DB 'Enter a string: $'
MSG_INV DB 'Inverted string is: $'
MSG_LOWER_COUNT DB 'Lower case count = $'
MSG_UPPER_COUNT DB 'Upper case count = $'
NEW_LINE DB 0xA, 0xD, '$'
INPUT_STRING DB 51,? ; Buffer for user input string (maximum size 50), last byte reserved for input
length
INVERTED_STRING DB 51 DUP(?) ; Buffer for inverted string
LOWER_COUNT DB 0
UPPER_COUNT DB 0
.CODE
MAIN PROC
; Seting up the DS register
MOV AX, @DATA
MOV DS, AX
; Print prompt for user input
MOV AH, 9
LEA DX, MSG
INT 21H
NOT_LOWER:
CMP AL, 'A' ; Compare with 'A'
JB CONTINUE_LOOP ; Jump if below 'A'
; CMP AL, 'Z' ; Compare with 'Z'
; JA CONTINUE_LOOP ; Jump if above 'Z'
ADD AL, 32 ; Convert uppercase to lowercase
MOV [SI], AL ;saving to the same location after converting
INC UPPER_COUNT
CONTINUE_LOOP:
INC SI ; Move to the next character
DEC CL ; Decrement the character count
JMP CONVERT_LOOP ; Continue the loop
PRINT_RESULTS:
; Print new line
MOV AH, 09H
MOV DX, OFFSET NEW_LINE
INT 21H
; Print inverted string
MOV AH, 09H
LEA DX, MSG_INV
INT 21H
MOV AH, 09H
LEA DX, INVERTED_STRING
INT 21H