News:

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

Need a push in the right direction.

Started by tibbar_eht, May 11, 2007, 02:32:11 AM

Previous topic - Next topic

tibbar_eht

Ok my problem is getting a display of a forward string and a backwards string. It should display
USS KITTY HAWK
    KWAH YTTIK USS


I cleaned up the code so the extra lines are gone. 


TITLE Reverse

.model small
.stack 64

.data

tibbar1 db 'USS KITTY HAWK', '$'
tibbar2 db 14 dup ('*'), '$'
.code

main PROC far

mov ax, @data
mov ds, ax
mov es, ax

  ; REVERSE THE STRING WHILE COPYING IT


  MOV CX, 14

lea si, tibbar1

  ;lea di, tibbar2

  ; THE "- 2" IS NECESSARY TO AVOID THE '$'
  MOV DI, OFFSET tibbar2 + SIZEOF tibbar2 - 2

A10:
mov al, [si]
mov [di], al
inc si

  ;inc di

  DEC DI

dec cx
jnz A10  ;JUMP AND DO THE LOOP AGAIN!!



COMMENT | THEN YOU HAVE NO NEED FOR THIS LOOP
A20:

mov al, [si]
mov [di+0dh], al
inc si
dec di
dec cx
jnz A20  ;JUMP AND DO THE LOOP AGAIN!!
|

mov ah, 06h
mov al, 00h
mov bh, 00bch
mov cx, 0000h
mov dx, 184fh
int 10h

mov ah, 09h
lea dx, tibbar2
int 21h
mov ax, 4c00h
int 21h


MAIN ENDP
END MAIN


I tried to have it display the string forward in the second loop by changing:
mov [di+0dh], al
inc si
dec di

to
mov [di], al
inc si
inc di


But that didn't work.

Cheers,
Jay

MichaelW

The modified code I posted correctly reverses the string, and displays the reversed string. The purpose of terminating strings with a '$' is normally so they can be displayed with Interrupt 21h, function 9. The code that displays the reversed string is:

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

So code to display the original string would be:

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


eschew obfuscation

tibbar_eht

Ok I figured out why the second loop was not working.  I was not familiar with the pipe's function .  Now when it displays I get KWAH YY HAWK.  So it looks like it is reversing and printing forward but printing it over each other. 

Cheers,
Jay

Tedd

Run through it by hand on paper and you'll see why it's happening - and that you need to swap two characters at the same time (if you have to do it in-place.)
No snowflake in an avalanche feels responsible.

tibbar_eht

Just thought I would post the code that finially worked.


TITLE try1

.model small
.stack 64

.data

tibbar1 db 'USS KITTY HAWK', '$', 0
tibbar2 db 14 dup ('*'), '$', 0
tibbar3 db 14 dup ('*'), '$', 0
.code

main PROC far

mov ax, @data
mov ds, ax
mov es, ax

  ; REVERSE THE STRING WHILE COPYING IT


mov cx, 0eh

lea si, tibbar1
lea di, tibbar2


A10:
mov al, [si]
mov [di+0dh], al
inc si
    dec di
dec cx
jnz A10  ;JUMP AND DO THE LOOP AGAIN!!

mov ah, 06h
mov al, 00h
mov bh, 00bch
mov cx, 0000h
mov dx, 184fh
int 10h
mov ah, 02h
mov dh, 11
mov dl, 34
int 10h

mov ah, 09h
lea dx, tibbar2
int 21h
mov cx, 0eh
lea si, tibbar2
lea di, tibbar3

A20:

mov al, [si+0dh]
mov [di], al
dec si
inc di
dec cx
jnz A20  ;JUMP AND DO THE LOOP AGAIN!!



mov bh,00h
mov ah, 02h
mov dh, 14
mov dl, 34
int 10h
mov ah, 09h
lea dx, tibbar3
int 21h
mov ax, 4c00h
int 21h


MAIN ENDP
END MAIN


Cheers,
Jay

eek

You can run up and down on the string using a video offset and the direction flag.
(I put an int16 in there to stop it going bonkers)

ZONE                       S L
org cs:100
;print.reverse.print forever
PRP
nop  ;ZRS
mov bp,B800 ;video
mov,es,bp
mov di,722  ;mid screen
mov si,USS  ;start of string
Start
mov cx,E
Print
movsb
inc di
loopnz Print
dec si
inc di
inc di
std
mov cx,E
tnirP
movsb
inc di
inc di
inc di
loopnz tnirP
cld
inc si
inc di
inc di
int 16
jmp Start
ret
USS ch10 USS KITTY HAWK
END
______________


Dont unzip it.
Rename the file extension from "zip" to "com", click it to start in DOS and hit any key to print out the output.



[attachment deleted by admin]