Hello...

i'm working on :

a program that will take as an input 5 Capital Letters and then

display on next line in small letters and in reverse order.

----------------------------

I want to know how to "Use Logical operator to convert the letters

to small letters"

is it like :


and DL,11111111b


?



and How can I Save the input letters in an array named W ?

is it :

W DW "Than what will come here ? "



how can I  reverse the input letters , without using STACK ?



Posted on 2007-01-04 07:27:42 by Rooro
First things first: you should know that an array must have a length and in Assembly, due to its very nature, you can cross an array?s boundary to its adjacent variable or block in the same segment. For example, if you create a WORD variable which is 16-bits long, you can use its address (OFFSET) to access the next variable which can be of any other sizes. Therefore, you should create a mechanism with which you would realize your array?s real length. A lot of programmers, as per strings that store characters, rather have their array terminated by a null-byte (ASCII Code = 0x00). This allows you to see where your array is terminated. For example, you have a string ?Hello? and then a byte 0x00. When you search in that string, starting from the first character, you can go forward until you reach the character 0x00. There you will realize your string is ended.

About the letters and their case (Upper-case or Lower-case), lower case letters start from the ASCII code 97 (0x61) and end at 122 (0x7A). Upper-case letters start at ASCII code 65 (0x41) and end at 90 (0x5A). You can confirm this by holding the ALT key down and pressing for example 65 on your keypad which would print an ?A? character. Now converting upper-case letters to lower is pretty easy and also trickery. If you take a look at the ASCII code of ?A? which is 65 and also at the ASCII code of ?a? which is 97, you will notice that the difference here is 32 or 0x20. Therefore, if you add this value of 32 to an upper-case letter, that letter would become a lower-case one. For example, let us say that the AL register holds the character ?F? and we need to convert it to ?f?, all we have to do is to perform a logical OR instruction like this:


String1       DB       ?Hello?, 0
This is how I would create a null-terminated string. Now the length is 5 and when divided by 2 would result in 2 (the fraction 1 is gone then). Therefore, if you replace the ending ?o? with the beginning ?H? and the next-to-the-end ?l? with ?e?, you will have the reversed string of ?olleH?. Strings with even number of bytes are reversed in the same order except that you will not have to leave any characters behind in the operations as you should do in strings with odd number of characters.

Note that in the string ?Hello?, we need not reverse the order of the character in the middle ?l? because no matter what you do, you can not reverse that with any other characters and it should always stay in the middle. About the stack, there really is no need to use the stack, you can simply load the OFFSET of your string into index registers such as ?BX?, ?SI? and ?DI? and then navigate through individual bytes inside those. Below is an example I have written in TASM which does this for you:

.DATA
  String1              DB              'Assembly', 0
And then you should invoke this procedure in this way:

Posted on 2007-01-04 09:51:29 by XCHG
Great ! what a useful info !

XCHG  Thanks a lot



can I ask you if I try to  do the same program " but the user will enter the letters  " how can i do it ?




i'm startting my program before i read your program code carfeully :

with some missed code which i do no how can i compleat it !


.MODEL SMALL
.STACK 100H
.DATA

MSG1 DB 'Please Enter Capital letters: $'
MSG2 DB 0DH,0AH,'Small Letters are:  $'

W       DW 0,0,0,0,0

.CODE

MAIN PROC

;--------------------
MOV AX,@DATA ;INTILAIZE DS
MOV DS,AX
;---------------------


;DISPLAY MSG1

LEA DX,MSG1 ;GET MSG1
MOV AH,9 ;DISPLAY STRING
INT 21H ;DISPLAY MSG1


;----------


loop_top:

MOV AH,1  ;READ A CHARACTDR
INT 21h
cmp al,0dh ; end of line?
je Display1 ; yes, then stop



MOV W,AX

and SI,11111111b

loop_end:

jmp loop_top




;-----------

Display1:


XOR SI,SI


LOOOP:

MOV DX,W

INT 21H

ADD SI,2

LOOP LOOOP

;--------------


;DISPLAY MSG2

LEA DX,MSG2 ;GET MSG2
MOV AH,9 ;DISPLAY STRING
INT 21H ;DISPLAY MSG2


;---------------

MOV AH,4CH ; return control to DOS
INT 21H



MAIN ENDP

END MAIN



Posted on 2007-01-04 19:28:51 by Rooro