Hey, I'm new to assembly 8086 progamming and don't know much of the code.

How do you change the input string to all caps and show the number of characters without counting the spaces?

Enter a string: Doraemon rules!!!

Output: DORAEMON RULES!!!

Number of characters: 16

Dani AI

Generated

A few notes for : the snippet in post #2 reads the input but the lowercase-to-uppercase code runs only once and the program exits immediately, so only the first character ever gets converted. The correct approach is to read the whole line into a buffer, loop every character, convert any lowercase letter to uppercase, copy it to an output buffer terminated with '$' (so DOS function 9 can print it), and increment a counter only when the character is not a space. The example below uses DOS buffered input (int 21h, AH=0Ah) so the returned length is available in the buffer header.

TITLE UppercaseAndCount

.model small
.stack 100h

.data
prompt     db "Enter a string: $"
outLabel   db 0dh,0ah,"Output: $"
countLabel db 0dh,0ah,"Number of characters: $"
MAXLEN     equ 80
inBuf      db MAXLEN
           db 0
           db MAXLEN dup(?)
outBuf     db MAXLEN+1 dup(?)
numStr     db 3 dup(?), '$'

.code
main proc
    mov ax,@data
    mov ds,ax

    mov dx,offset prompt
    mov ah,9
    int 21h

    lea dx,inBuf
    mov ah,0Ah
    int 21h

    lea si,inBuf+2         ; first character
    mov cl,[inBuf+1]       ; length returned by DOS
    lea di,outBuf
    xor bx,bx              ; non-space count

    cmp cl,0
    je .print

.convert_loop:
    mov al,[si]
    cmp al,'a'
    jl .no_conv
    cmp al,'z'
    jg .no_conv
    sub al,20h
.no_conv:
    mov [di],al
    cmp al,' '
    je .skip_count
    inc bx
.skip_count:
    inc si
    inc di
    dec cl
    jnz .convert_loop

    mov byte ptr [di],'$'

.print:
    mov dx,offset outLabel
    mov ah,9
    int 21h

    mov dx,offset outBuf
    mov ah,9
    int 21h

    mov dx,offset countLabel
    mov ah,9
    int 21h

    ; convert BX (0..MAXLEN) to ASCII (handles 0..99)
    mov ax,bx
    mov bl,10
    div bl                ; AL=quotient (tens), AH=remainder (units)
    cmp al,0
    je .one_digit
    add al,'0'
    mov [numStr],al
    add ah,'0'
    mov [numStr+1],ah
    mov byte ptr [numStr+2],'$'
    jmp .print_num
.one_digit:
    add ah,'0'
    mov [numStr],ah
    mov byte ptr [numStr+1],'$'

.print_num:
    mov dx,offset numStr
    mov ah,9
    int 21h

    mov ah,4Ch
    mov al,0
    int 21h
main endp
end main

Notes: DOS buffered input (AH=0Ah) returns the length in byte [inBuf+1] (CR is not included). The conversion checks 'a'..'z' and subtracts 0x20 to get uppercase; only ASCII space (0x20) is excluded from the count—add extra checks if tabs or other whitespace should be ignored. Assemble with MASM/TASM and run under DOS or an emulator (DOSBox) if running on a modern system.

TITLE   LAB TUTORIAL 1

.model  small
.stack  100h

.data
msg1    db  "Enter a string: $"
msg2    db  "Output: $"
msg3    db  "Number of characters: $"
blank   db  0dh,0ah,'$'
string  db  99 dup(?)

.code
main    proc
    mov     ax, @data
    mov     ds, ax  
    mov dx, offset msg1
    mov ah, 9
    int 21h

    mov     si, offset string
top:    mov     ah, 1
    int     21h
    cmp     al, 13
    je  stop
    mov     [si], al
    inc     si

    jmp     top
stop:   mov     al, '$'
    mov [si], al
    mov dx, offset blank
    mov ah, 9
    int 21h
    mov dx, offset msg2
    mov ah, 9
    int 21h

    mov si, offset string
    mov     al, [si]
    cmp     al, 'a'
    jl  noconvert
    cmp     al, 'z'
    jg  noconvert
    sub     al, 32


    mov ax, 4c00h
    int 21h

main    endp
end main

Please help, I cannot do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.