------>>>>> REVERSING A STRING <<<<<----- 
Author Message
 ------>>>>> REVERSING A STRING <<<<<-----

I have to find some MASM source that inputs a series of characters
from the keboard (terminated by <CR>) and then displays the sequence
in reverse minus the spaces.  Can anyone help?
----------------------------------------------
Chris Howell - Ottawa, ON.

Home Page: http://www.*-*-*.com/ ~cahowell/
"Lead, follow, or get out of the way."
----------------------------------------------


Sun, 27 Sep 1998 03:00:00 GMT  
 ------>>>>> REVERSING A STRING <<<<<-----
Quote:
>I have to find some MASM source that inputs a series of characters
>from the keboard (terminated by <CR>) and then displays the sequence
>in reverse minus the spaces.  Can anyone help?

Well, I'm not going to code it up for you, but:

You can input the string easily using BIOS, very easily in fact.
Reversing the string is also easy, just requires a basic swap aglorithm.
Ie, mov ax,nth character
    mov cx,last character - n +1
    mov [address of nth char],cx
    mov [address of last char - n +1],ax
    inc n
simple loop and test N against the middle ordinal, and presto, a somewhat
ineffiecent but working deal.

--
Nick
--
Dragonball(z) FAQ http://www.eden.com/~nickm/db.html
Proud member, DBZLF.
--
Hell is for very bad people, and the lawyers that defend them.



Sun, 27 Sep 1998 03:00:00 GMT  
 ------>>>>> REVERSING A STRING <<<<<-----

Quote:

> >I have to find some MASM source that inputs a series of characters
> >from the keboard (terminated by <CR>) and then displays the sequence
> >in reverse minus the spaces.  Can anyone help?
> Well, I'm not going to code it up for you, but:

> You can input the string easily using BIOS, very easily in fact.
> Reversing the string is also easy, just requires a basic swap aglorithm.
> Ie, mov ax,nth character
>     mov cx,last character - n +1
>     mov [address of nth char],cx
>     mov [address of last char - n +1],ax
>     inc n
> simple loop and test N against the middle ordinal, and presto, a somewhat
> ineffiecent but working deal.

If you want to be a _little_ fancy, you could use the following
algorithm:

  mov si,sp     ; Save stack pointer!
input_loop:
  xor ax,ax
  int 16h       ; Use int16 to get a keystroke

  cmp al,' '    ; is it a space char?
   je input_loop; if space, get another char

  push ax       ; Save current char on stack top!
  cmp al,13     ; Terminating CR?
   jne input_loop

  pop ax        ; Get rid of last pushed char (terminating CR)
   jmp test_stack

disp_loop:
  pop dx        ; DL will get the pushed char
  mov ah,2
  int 21h
test_stack:
  cmp si,sp     ; Is the stack back where we started?
   jne disp_loop
done:

--
-Terje Mathisen (include std disclaimer)

"almost all programming can be viewed as an exercise in caching"



Tue, 29 Sep 1998 03:00:00 GMT  
 ------>>>>> REVERSING A STRING <<<<<-----
[code snip]
Quote:
>--
>-Terje Mathisen (include std disclaimer)

>"almost all programming can be viewed as an exercise in caching"

Like I said, it was simple. If the guy needs help  inputing strings and
such I'd be willing to place a fair wager he doesn't understand all the
nice concepts like the exact way the stack works, etc. This does
illustrate something interesting though, good thinking! If he can look at
my simple solution, then at your more complex and arguably better
solution, and tell the difference, he may learn a few things about
assembler thinking. Off the top of my head I can't give the exact time it
would take to do either, but with something like this its probably about
the same.

--
Nick
--
Hell is for very bad people, and the lawyers that defend them.



Tue, 29 Sep 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. ><><><><>Heeeeeeeeeeeeeeelp on INT 14!><><><><><>

2. <<<<<YOU MUST CHECK THIS OUT >>>>>>>>>> 2103

3. <><><> FLOODFILL <><><>

4. >>>HELP, DECOMPILER<<<

5. <<<XXX Password>>>

6. <<<XXX Password>>>

7. <<<XXX Password>>>

8. >>>>>>>>>>>>>>>>>>>HEY!<<<<<<<<<<<<<<<<<<<<<<<

9. ??? <<<<<<<<<<<<<<<<<<<< RGB 4 MMX >>>>>>>>>>>>>>>>>>>>>>>?

10. ??? <<<<<<<<<<<<<<<<<<<< RGB 4 MMX >>>>>>>>>>>>>>>>>>>>>>>?

11. >>>>> ADA PROGRAMMERS NEEDED, GOOD PAY <<<<<

 

 
Powered by phpBB® Forum Software