Click to See Complete Forum and Search --> : Help! reverse string with terminator in assembly


kopkop23
July 22nd, 2008, 06:15 AM
Can you provide any assistance? in X86 assembly programming can anyone help me with my program. It will accept strings of characters and then being terminated by ! and ? if strings is terminated by ! program will just display the entered string else if strings is terminated by ? program will reverse the strings else Error no string terminator else NULL input .

heres sample run.

Enter string (max of 80 characters) = Hello World
Output = Error: No string terminator, please try again

Enter string (max of 80 characters) =
Output = Error: null input, please try again

Enter string (max of 80 characters) = Hello World!
Output = Hello World

Do you want to continue (Y/N)? Y

Enter string (max of 80 characters) = Hello World?
Output = dlroW olleH

Do you want to continue (Y/N)? N

below is the program which i am currently have so far.

Hope you could help. Tnx.

kopkop23
July 23rd, 2008, 04:16 AM
Here's what i have so far....

the program can only invert the inputted strings and theres an ascii when displayin the ouput. Right now im stock with the termination part. if terminated by ! just display the input, if terminated by ? reverse the input.

i pasted the program below...

hope you can help me with this...
Thanks alot. God bless.

======
TITLE my first program
DOSSEG

.model small
.stack 100h

.data
; ALPHA db 0
inputstring db "Enter String (max of 80 Characters) = ", '$'
input db 00ffh, 80 dup(?)
invert db 13,10, "Ouput = ",'$'
.code
Begin:
mov al, 3 ; AL = video mode; 03 = 80*25
mov ah, 00h ; set video mode / clear screen
int 10h ; video interrupt

mov ax, @data ; defines segment registers
mov ds, ax
mov es, ax

lea dx, inputstring ; DSX -> to string terminated w/ '$'
mov ah, 09h ; string output
int 21h ; DOS interrupt


lea dx, input ; input buffer
mov ah, 0ah ; buffered keyboard input
int 21h ; DOS interrupt

mov ah, 09h
lea dx, invert
int 21h

lea si, input
add si, 2
xor cx, cx

loop_a:
lodsb
push ax
inc cx
cmp al, 0dh
jne loop_a
pop ax

loop_b:
pop ax
mov ah, 2
mov bh, 00
mov dl, al
int 21h
loop loop_b


mov ah, 4ch
int 21h
end Begin

iviggers
July 24th, 2008, 01:36 PM
You're doing fine. What is your question?
You should just add the opcode "dec cx" right after "loop_a" block, so you don't display an extra char at the end.
The code you show covers the case of reversing string. So before loop_b compare last byte to ? or !. If you want to omit string terminator, don't forget to "dec cx" again and make another "pop ax" just before loop_b. This you would get rid of byte terminator and handle the counter accordingly. Or in case of normal (non-reverse) display, change byte terminator to $.

You may also want to put a comma between 00 and ffh (see your declaration of "input" variable.

Good luck.

kopkop23
August 12th, 2008, 09:56 PM
Thank you! i'm working on it....

God bless!