News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Help to understand this code

Started by alzabadani, October 31, 2010, 08:10:15 AM

Previous topic - Next topic

alzabadani

Please help me to know how is this code work  .. I am a beginner and it is critical to know what this code does.

thank a lot




TITLE change the case of letters procedure
.MODEL SMALL
.STACK 64
.DATA
BUFFER DB 40h,00h,40 DUP(?) ;buffer for storing the string
.CODE 
MOV AX,@DATA
MOV DS,AX
MOV DX, OFFSET BUFFER ; at most 40h characters typed in
MOV AH,0Ah
INT 21h
MOV CH,00
MOV BX,DX
MOV CL,[BX+1]
MOV [BX],word ptr 0D0Ah
INC BX
INC BX
21- AGAIN: MOV AL,[BX]
CMP AL,61h
JB NEXT
CMP AL,7Ah
JA NEXT
SUB AL,20h
JMP NEXT1
NEXT: CMP AL,41h
JB NEXT1
CMP AL,5Ah
JA NEXT1
ADD AL,20h
NEXT1: MOV [BX], AL
INC BX
LOOP AGAIN
MOV [BX], BYTE PTR 24h
MOV AH,09h
MOV DX, offset BUFFER
INT 21h
MOV AH,4Ch ; int 21 function number 4Ch
INT 21h ; return to DOS
END


jj2007

Posting twice doesn't help.

Now a serious suggestion: Since this is your first contact to the Masm32 Forum, why don't you introduce yourself, explain what you are doing, and especially where you got this snippet, and what you intend to do it with it?

dedndave

Quote21- AGAIN: MOV AL,[BX]
must be a typo   :P

alzabadani

I am a studient in ISE (information System Engineering) in third year .. I have got a subject called (MicroProcessor) about 8086/8088 comands, I found this code in our last questions (Exam) and want to understand the code.

hope to help me

Tx

dedndave

If you intend to continue writing 16-bit programs, I suggest you download Ralf Brown's Interrupt List:

http://www.cs.cmu.edu/~ralf/files.html

The list is organized in 6 ZIP files (inter61a.zip-inter61f.zip). This is the most complete list of interrupts available.
Most of the information you will need is in the first 2 ZIP files (inter61a.zip and inter61b.zip).

The files are fairly large text files. If you look down the list a little further, there is a program for viewing them.
It is called Ralf Brown Interrupt List Viewer, or simply RBIL Viewer (rbilv21.zip).

The individual text files have names like INTERRUP.A, INTERRUP.B, and so on.
You may want to rename them to something like INT_A.TXT, INT_B.TXT, etc. to make them easier to use.

Ralf's List has a lot of information you may never use, because they try to make it complete.
On the other hand, it is full of useful tables and structure definitions that are hard to find elsewhere.

also - for a quick reference, Randy Hyde's AOA

http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/toc.html

Chapter 13  BIOS, DOS, and File I/O     (includes information on the interrupt services)

dedndave

without discecting the code,
21- AGAIN: MOV AL,[BX]
should probably be
int 21h
AGAIN: MOV AL,[BX]

BogdanOntanu

Also please note that there is a "NO HOMEWORK" rule for MASM forums. In consequence we will not solve you problem and hand you out the predigested results.

Instead you will have to make your own efforts to understand and solve the problem / homework.

You must show us what you did and where and why you have difficulties in this process and we will help you overcome those critical points...

As a set of hints:
a) read the title of the program
b) be sure to know what each ASM instruction does
c) check the constants: 0Dh , 061h, 41h, 5Ah, 20h, 24h, 7Ah that are used in the code in an ASCII chart and try to understand why thy are used.
d) understand why it loops to that "again" label

For eaxmple  5Ah is ASCII code for "Z" and 41h is ASCII code for "A" ... does this ring a bell?
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

Neil

Basically it's a case converter, i.e. lower to upper & upper to lower. As dave says you need to study the interrupts and also learn about Ascii characters.

alzabadani

Thank for all.

is it to swap between upper and lower case ?? or to convert from askii to letters ?

Magnum

Quote from: BogdanOntanu on October 31, 2010, 09:10:26 AM
Also please note that there is a "NO HOMEWORK" rule for MASM forums. In consequence we will not solve you problem and hand you out the predigested results.

Instead you will have to make your own efforts to understand and solve the problem / homework.

You must show us what you did and where and why you have difficulties in this process and we will help you overcome those critical points...

As a set of hints:
a) read the title of the program
b) be sure to know what each ASM instruction does
c) check the constants: 0Dh , 061h, 41h, 5Ah, 20h, 24h, 7Ah that are used in the code in an ASCII chart and try to understand why thy are used.
d) understand why it loops to that "again" label

For eaxmple  5Ah is ASCII code for "Z" and 41h is ASCII code for "A" ... does this ring a bell?


He said he was a beginner, so maybe give him the benefit of any doubt you may have ?

Each one of you should give just as he has decided in his heart, not reluctantly or under compulsion, because God loves a cheerful giver. 2 Corinthians 9:7
Have a great day,
                         Andy

FORTRANS

Quote from: alzabadani on October 31, 2010, 09:49:31 AM
Thank for all.

is it to swap between upper and lower case ?? or to convert from askii to letters ?

Hi,

   It swaps ASCII upper case to lower case and ASCII lower to upper.

Steve

alzabadani

Thank you Magnum and Steve ..  :U I got it . also thank for all who advise or help.
one day you will see me a professional helping in MASM forum  :lol

Thanks guys