Well I have looked the program up and down, and although something is being read from memory wrong I can't figure out why it happens.

This code works perfectly fine:


title Problem1.asm (Problem1.asm)

.model small

.stack 100h

.data

string   db 'Reversal Power!', '$' ;if no single quotes, then operator is missing
stringSize dw ?

.code

;mov ds, @data Why can't this be done?--Can't move address into segment register apparently
;Setting up data segment
mov ax, @data ;what is this @ syntax
mov ds, ax

;Outputting original string
mov ax,0900h
mov dx,offset string
int 21h


;Positioning address of bx at the null character

mov bx, offset string  ;setting bx equal to offset of string

NULLsearch:

mov ax, ;NOTICE;can't compare indirect address and immediate operand, moved to register
cmp ax, '$' ;comparing contents of bx to the null character
je end_NULLsearch

inc bx

jmp NULLsearch

end_NULLsearch:

mov dl, 0Ah
mov ah, 2
int 21h

mov dl, 0Dh
mov ah, 2
int 21h

print:

cmp bx, offset string
je end_print

dec bx

mov dl,
mov ah, 2
int 21h

jmp print

end_print:




;exiting the program
mov ax, 4C00h
int 21h ;not putting an h here, messes the program up...why

end


But as soon as I try to remove stringSize dw ?, since it's no longer needed with my new algorithm, the program goes to hell:


title Problem1.asm (Problem1.asm)

.model small

.stack 100h

.data

string   db 'Reversal Power!', '$' ;if no single quotes, then operator is missing
;stringSize dw ? ;*************************This guy********************

.code

;mov ds, @data Why can't this be done?--Can't move address into segment register apparently
;Setting up data segment
mov ax, @data ;what is this @ syntax
mov ds, ax

;Outputting original string
mov ax,0900h
mov dx,offset string
int 21h


;Positioning address of bx at the null character

mov bx, offset string  ;setting bx equal to offset of string

NULLsearch:

mov ax, ;NOTICE;can't compare indirect address and immediate operand, moved to register
cmp ax, '$' ;comparing contents of bx to the null character
je end_NULLsearch

inc bx

jmp NULLsearch

end_NULLsearch:

mov dl, 0Ah
mov ah, 2
int 21h

mov dl, 0Dh
mov ah, 2
int 21h

print:

cmp bx, offset string
je end_print

dec bx

mov dl,
mov ah, 2
int 21h

jmp print

end_print:




;exiting the program
mov ax, 4C00h
int 21h ;not putting an h here, messes the program up...why

end




I have no idea why. Hopefully someone can lead me in the right direction here.

Thanks guys.
Posted on 2007-06-08 00:46:29 by WinterMute
This is happening because you're loading a word at a time with "mov ax,", then comparing that word with '$', instead of loading a byte at a time with "mov al,", then comparing that byte with '$'.  Since you're not using stringSize and the default value is usually 0, when it's there, the value of the word at the $ is a byte of '$' followed by a byte of 0, making the value of the word '$'.  Without stringSize there, it may there may not be a 0 after the string, and in that case your code won't find the end there.  I didn't notice any other problems.

Just change:

mov    ax,
cmp    ax,'$'

to:

mov    al,
cmp    al,'$'


Cheers  ;)
Posted on 2007-06-08 01:36:10 by hackulous
mov ax,   ;you're loading 2 bytes
cmp ax, '$'     ;you're comparing 2bytes with one byte, so I presume the
                   ;second is filled in as a zero at assembly time, (as WM says)


The bytecode for $ is 24
try

mov al,
cmp al,'$'

EDIT:
A dubble post really...I get all excited if there's something I might know
the answer to.
Posted on 2007-06-08 04:27:09 by eek