Hi I am new to ASM;

I need some help, I am trying to write a program that takes two strings as input and compair them then gives a message.

I wrote the program but I have a porbelm I will explain what I wrote then I will write the problem:

-first I ask for the lengh of the string and I save it on cx( done)
-then I input the first string and save it using push (done)
-second I input the second string and save it on memory location (here I have the problem ) I will write the code for this one
  mov  AH, 9           ;
  mov  DX, OFFSET Now  ;Display the message ""enter your name""
  int  21h 
   
  mov si,400h
  mov cx,di                  ; I get the value of the counter to match
                                  ;the lengh of the ref string lengh
    mov bx,2h                  ; I set the value of bx to 2 to use it in mem shift
num:   
    mov ah,01h                  ; now we enter the name from keyboard
    int 21h
   
    mov ,ax                ; the data on ax from keyboard is saved on mem
                                    ; on mem location of SI
    push                     ; another try of me to get the start address of the string
    lea si,[800h+bx]          ; I saved the effective address in SI
    add bx,02h                  ; we need to shift the mem addres two byte       
    dec cx
    jnz num                      ; keep getting more charaters till cx is zero

----------------------------------------------------------------------
so far its good now I have two strings one saved using push and the other one is saved by mem location saved on SI (after using pop command )or the last charater of the string is saved on memory locatoin SI (the current value of SI)
------------------------------------------------------------------------
for some reason I can not make the pointer to point to the first charater of the string I saved on the memory location neither using pop or I made a small commads to try to decrement the pointer to point first charater
here is what i have done
I tried to decrement twice
did not work....

I need your help on understand how to make the pointer points to the first charater I have saved on the memory ... the probelm I can not push IP or CS ?

any help is really appriated this is my first programe and I spend 3 days try to solove this problem but no use

Regards,
Alan





Posted on 2007-03-20 09:41:42 by mimime
by the way I am not allowred to buffer the input
Posted on 2007-03-20 09:47:34 by mimime

by the way I am not allowred to buffer the input


Smells like homework. Don't expect any direct answers from this community when it comes to homework, only more questions that inspire you to solve the problem yourself :)

Anyhow...

Do you mean you are not allowed to save the input of the stream to a simple memory location instead of being forced to use stack memory as a buffer via PUSH/POP??? Then you are not allowed to simply and efficiently use CMPSB to check if both strings are equal??? If so, tell your instructor that there are better and more useful ways to demonstrate DOS assembly language programming.

Well...

1) Where *exactly* are you trying to store the string? As I see references to 400h and 800h.
2) Why are you using BX instead of simply incrementing SI?
3) Why are you copying the input character to the address referenced by SI and then PUSHing that same value by referencing SI again? Which one is ultimately going to hold the input string???
4) Give many specifics as you possibly can.
Posted on 2007-03-20 10:13:01 by SpooK
Spook,

I did not expect a direct answer, and yes its my homework but I was not asking for a solution I did the software by my self and planning to finish it by my self .... that why I did not post the whole code.

I am facing a problem and was seeking help, I am not asking for a code I just need to understand how to :

if I save to a memory location a chrater then increment the adrdress by two and do this process x number of times. at the end I end up with the pointer at the top of the memory location which is my last charater, what want is to be able to know how to move to the first memory location I mean the first charater I inputed.
-I tired to save the efficeted address at the start (did not work )
-I can not push the (IP)
-I tried dectrement the address I have also did not work.

I am not sure where I am going worng.... I AM NOT ASKING FOR A CODE , i just need to know how to go back to the first memory location where I save the first charater.


1) Where *exactly* are you trying to store the string? (just charaters like a name ) As I see references to 400h and 800h , 400h and 800h I was just shifitng the memory to seek for empty location on the memory
2) Why are you using BX instead of simply incrementing SI? I need to shift the address 2 each time I save, this is the way when i tested and I found it works
3) Why are you copying the input character to the address referenced by SI and then PUSHing that same value by referencing SI again? Which one is ultimately going to hold the input string??? i push the address at the start to see if i can retrive the address of the first charater, but it did not work
4) Give many specifics as you possibly can.

All I want is how to :
when you save data on memory, and you incrementing the address how on the end to go back to the start address of the first charater you have saved ? this is the porblem.
Posted on 2007-03-20 12:49:32 by mimime
I will try to explain the problem in another way:

- I already wrote a program using int 21,0A which buffer the keyboard but now the treacher think that was kind of playing smart.
- I have two inputs lets say NameA and NameB

I ask the user to input namea then i save it and I save the lenght of it, then i ask him again to input nameb (i use the lengh of namea to limit the name size)

I first save in namea in a stack uinsg push ( later i will retrive this name using pop)
i saved nameb on a memory location

now I need to compair the two names so for the first one which namea is easy to get the data using pops
for the second nameb my pointer is pointing to the last charater saved of the name lets say its letter b .... now I need to know how get the first address of nameb which lets say letter n ... having the addrees of the last letter which is p..... I tried pushing the effective address when I first start saving nameb (did not work) I tried then decrementing the address that I have also did not work ....

All I need to be able to point to the first charater of the second name whcih is nameb having the address of the last letter whcih letter b
Posted on 2007-03-20 13:11:17 by mimime

All I need to be able to point to the first charater of the second name whcih is nameb having the address of the last letter whcih letter b


Save that address in another register/variable and reference it later. In this case, it would make sense to have 3 variables, start of the first string, end of the first (start of the second) and end of the second. That way, you can also do a quick size calculation to determine if it is even worth bothering to attempt a comparison (if the strings are not even the same length, they won't match). You can also use that same size calculation to fuel the counter for whichever comparison routine you use.
Posted on 2007-03-20 13:36:03 by SpooK
Great, but how to save the address this is my point, what i tried is
push to save the effective address it did not work
I tried lea si,[800h+bx]  which is the current address also did not work
and I can not push the ip to save the address , so how can I save the address ?this is my point what is the command , i tried LEA I tried push , none works ? so my simple question will be how to save the current address at some point ? cause I tried LEA and in asm it does not allow push of ip
Posted on 2007-03-20 13:55:53 by mimime
I found the solution,  :D and by my self
I had to
    push    ds
    push    es                      ;Save these for later
    push    di
    push    ax

to save the current address
Posted on 2007-03-20 14:54:22 by mimime
The state and usage of the segment registers is useful information. For instance, a regular COM file has a program origin of 0x100 and a small program can easily fit all data into that respective 64KB segment. However, with larger programs and EXE files, you run into code that can/will set the segment registers to needed values.

As for the IP (instruction pointer), that is the address of the currently executing instruction in memory. The mere mention of this suggests that what you are doing is quite different from what you *think* you are doing. However, if you are really that interested, look-up the CALL instruction (i.e. how it affects the stack.)

As for the "buffered input" comment, I now realize you are talking about things like INT 0x21/0x0A. It's been ages since I done any real DOS programming :P

Here is a list of suggestions to improve your scanner, assuming that the entire code+data is in one 64KB segment and CS=DS=ES.

1) Set SI to the memory location of the first expected string
2) Set DI to the memory location of the second expected string
3) Copy SI/DI to BX depending on which loop iteration call
4) Call a loop that retrieves input via INT 0x21/0x01 and stores it to the appropriate string location, store character in and increment BX each time through
5) Subtract BX from SI/DI to determine the String Length (store for later)
6) Retrieve String Lengths and compare, fail out if not equal
7) Since SI and DI are already set, simply use them as comparison indexes
8a) Create a loop loading a byte from and comparing it to for equality per iteration
*****OR*****
8b) Use REPZ + CMPSB with the count in CX to do an "automatic" comparison between DS:SI and ES:DI

HtH :)
Posted on 2007-03-20 15:43:05 by SpooK
Thanks a lot spook for you advice ... I understand what you wrote cause I read some advanced chaperters in our book, yet  i am not allowed to do it, since I am not allowed to use the commands that were not explained in the class ( well not yet explaind ), I did that before and the teacher though I am trying to show off  ( although I am not I am just reading and trying to find a solution.

I solved the porblem and the program is running ( still some small things I need to fix).
So far I don't know how to create two stacks so I will need to read about it more ...

I am still new ASM, this is a great place to seek advice from experts and thanks a lot spook, I will not ask for a homework solution for sure, but i will ask for advice on how things works so I can get a better understanding.

Again thanks for you time to reply to my post
Have a nice day
Posted on 2007-03-20 16:10:19 by mimime

I solved the porblem and the program is running ( still some small things I need to fix).
So far I don't know how to create two stacks so I will need to read about it more ...


That is usually the beauty of programming, there is more than one way to do things and it is up-to you to find the most efficient way :)
Posted on 2007-03-20 19:06:11 by SpooK