Click to See Complete Forum and Search --> : am confused


king-gideon
April 3rd, 2009, 07:31 PM
i have to write a program in assembly language an d i need to change all the lower case characters in a string to upper cases.it shud b working like this
input string:abcHUfg
output:ABCHUFG

i tried this but it is not working:(
;Описание макросов
CLEAR MACRO COLOR ;Очистка экрана цветом
MOV AX, 0600H ;Прокрутка всего экрана
MOV BH, COLOR
XOR CX, CX
MOV DX, 184FH
INT 10H
ENDM

TEXTOUT MACRO TEXT ;Вывод текста через функцию 9 прерывания 21H
MOV AH, 09
LEA DX, TEXT
INT 21H
ENDM

TEXTIN MACRO BUF ;Ввод текста через
MOV AH, 0AH
LEA DX, BUF
INT 21H
ENDM

StackS SEGMENT PARA STACK 'STACK'
DW 32 DUP(?)
StackS ENDS


MAX_TEXT EQU 80
DATA SEGMENT PARA PUBLIC 'DATA'
MESS1 DB 0AH,0DH,"Введите строку: $"
MESS2 DB 0AH,0DH,"В маленьких букв: $"


BUF1 DB MAX_TEXT
QNT1 DB 0
TEXT1 DB MAX_TEXT DUP(?)


DATA ENDS

CODE SEGMENT PARA PUBLIC 'CODE'
ASSUME CS:CODE, DS:DATA, SS:StackS

START: MOV AX, DATA ; загрузить в DS
MOV DS, AX ;селектор сегмента данных
MOV ES, AX

CLEAR 30
TEXTOUT MESS1
TEXTIN BUF1



XOR CH, CH ;Обнуление старшего байта счетчика
MOV CL, QNT1 ;Загрузка количества символов в строке
LEA DI, TEXT1 ;Адрес основной строки в источник
CLD



Convert2Lower: lodsb ;Get next char in str.
repe cmp al, "A" ;Is it upper case?
jb NotUpper
repe cmp al, "Z"
ja NotUpper
or al, 20h ;Convert to lower case.
call puts ; display result message
mov dl, bl
call putc ; display lowercase letter
mov ax, 4c00h
int 21h ; return to ms-dos


NotUpper: stosb ;Store into destination.
loop Convert2Lower

puts: ; display a string terminated by $
; dx contains address of string
Mov dx,ax
mov ah, 9h
int 21h ; output string
ret
putc: ; display character in dl
mov dl,al
mov ah, 2h
int 21h
ret


EXIT: XOR AL, AL ; выход в OS
MOV AH, 4CH
INT 21H
CODE ENDS
END START

can u help me out pls:))))))))))))))))))))))))))))))))))

rxbagain
April 3rd, 2009, 09:37 PM
Hi gideon,

I'm also confused :D, you said you want to make it upper case but the code does the lower case conversion. Anyway I just made it upper case based on your statement and sample output. Here's the code beginning from the "CLEAR 30"


CLEAR 30
TEXTOUT MESS1
TEXTIN BUF1
TEXTOUT MESS2 ; output the message "output: "

XOR CH, CH ;Îáíóëåíèå ñòàðøåãî áàéòà ñ÷åò÷èêà
MOV CL, QNT1 ;Çàãðóçêà êîëè÷åñòâà ñèìâîëîâ â ñòðîêå
LEA SI, TEXT1 ;Àäðåñ îñíîâíîé ñòðîêè â èñòî÷íèê
CLD

print_upper: lodsb ; Get next char in str. *
cmp al, "a" ; if < 'a', just print it
jb print_it
cmp al, "z" ; if > 'z' just print it
ja print_it
sub al, 20h ; if lower case a - z, make it upper
print_it:
call putc ; display the letter
loop print_upper

mov ax, 4c00h
int 21h ; return to ms-dos

putc: ; display character in dl
mov dl,al
mov ah, 2h
int 21h
ret

CODE ENDS
END START

Note that I used SI register since LODSB reads from DS:[SI] not [DI]. ES:[DI] is used for storing data (STOSB, STOSW, STOSD).