2081 5

CSC167 ยท 2081 ยท 5 marks

Write an ALP to convert the string 'computer science' to upper case using 16 bit microprocessor.

Write an ALP to convert the string 'computer science' to upper case using 16 bit microprocessor. [5]

MicroprocessorChapter 4: Assembly Language ProgrammingSimple sequence programs

Quick answer

In ASCII, lowercase letters range from 61H ('a') to 7AH ('z') and uppercase letters range from 41H ('A') to 5AH ('Z'). To convert lowercase to uppercase, we subtract 20H from the ASCII value of each lowercase character.

ALP to Convert String 'computer science' to Upper Case (16-bit Microprocessor / 8086)

Concept

Spaces and other non-alphabetic characters are left unchanged.


Assembly Language Program

.MODEL SMALL
.STACK 100H

.DATA
    STRING DB 'computer science', '$'   ; Define the string with $ terminator
    LEN    DW 16                        ; Length of the string (16 characters)

.CODE
MAIN PROC
    MOV AX, @DATA          ; Load address of DATA segment into AX
    MOV DS, AX             ; Initialize Data Segment register

    MOV SI, OFFSET STRING  ; SI points to the start of the string
    MOV CX, LEN            ; CX = loop counter = length of string

BACK:
    MOV AL, [SI]           ; Load current character into AL

    CMP AL, 'a'            ; Compare AL with 'a' (61H)
    JB  SKIP               ; If AL < 'a', not a lowercase letter, skip

    CMP AL, 'z'            ; Compare AL with 'z' (7AH)
    JA  SKIP               ; If AL > 'z', not a lowercase letter, skip

    SUB AL, 20H            ; Convert lowercase to uppercase by subtracting 20H
    MOV [SI], AL           ; Store the converted character back into memory

SKIP:
    INC SI                 ; Move SI to point to next character
    LOOP BACK              ; Decrement CX and repeat if CX != 0

    ; Display the converted string
    MOV DX, OFFSET STRING  ; Load address of converted string into DX
    MOV AH, 09H            ; DOS function 09H: display string
    INT 21H                ; Call DOS interrupt

    MOV AX, 4C00H          ; DOS function 4CH: terminate program
    INT 21H

MAIN ENDP
END MAIN

Step-by-Step Explanation

StepInstructionPurpose
1MOV AX, @DATA / MOV DS, AXInitialize the Data Segment
2MOV SI, OFFSET STRINGSI points to first character of string
3MOV CX, LENSet loop counter to string length (16)
4MOV AL, [SI]Load each character one by one
5CMP AL, 'a' and CMP AL, 'z'Check if character is lowercase
6SUB AL, 20HConvert to uppercase (e.g., 'c' = 63H - 20H = 43H = 'C')
7MOV [SI], ALWrite converted character back
8INC SI / LOOP BACKAdvance to next character and repeat
9INT 21H (AH=09H)Display the final uppercase string

Example Conversion

CharacterASCII (Hex)After SUB 20HResult
'c'63H43H'C'
'o'6FH4FH'O'
' ' (space)20HSkipped' '
's'73H53H'S'

Output: COMPUTER SCIENCE

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.