News:

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

using jmp or compare instead of 'or'

Started by bcddd214, December 24, 2011, 02:52:45 AM

Previous topic - Next topic

bcddd214

line 47 and 50 have an 'or' statement, is it possible to use jmp or cmp instead?



Title               flipTest
INCLUDE Irvine32.inc

;################################################

SwapIt           PROTO :DWORD,:DWORD
stringLengthProc PROTO :DWORD

;################################################

.data

mes1      BYTE "Enter a 5 digit string: ",0
inName      DWORD         3 dup(0)
math1      BYTE         2
lpString:DWORD
dwLength:DWORD

;################################################

.code

;************************************************

getNameProc PROC

   push   edx
   mov      edx,offset      mes1
   call               WriteString
   mov      edx,offset      inName
   mov     ecx, sizeof      inName
   call               ReadString
   pop      edx
   ret

getNameProc ENDP

;************************************************

stringLengthProc PROC lpString:DWORD

;returns the string length in EAX

        push    ecx
        push    edi
        mov     al,0
        or      ecx,-1
        mov     edi,lpString
        repnz   scasb
        or      eax,-2
        sub     eax,ecx
        pop     edi
        pop     ecx
      call   SwapIt offset inName,eax
        ret

stringLengthProc ENDP

;************************************************

SwapIt  PROC

   push   ecx
   push   edx
    mov     ecx,dwLength
    mov     edx,lpString
    dec     ecx
    add     ecx,edx
    jmp short SwpIt1

SwpIt0: mov     al,[edx]
    mov     ah,[ecx]
    mov     [ecx],al
    mov     [edx],ah
    dec     ecx
    inc     edx

SwpIt1: cmp     ecx,edx
    ja      SwpIt0
   pop      edx
   pop      ecx
    ret

SwapIt  ENDP

;************************************************

main PROC

        call    getNameProc
        INVOKE  stringLengthProc,offset inName
;        INVOKE  SwapIt,offset inName,eax
        mov     edx,offset inName
        call    WriteString
        call    Crlf
        exit

main    ENDP

;################################################

END main

dedndave

actually, they are shortcuts for MOV
i should not have used those shortcuts for a beginner - sorry about that

;************************************************

stringLengthProc PROC lpString:DWORD

;returns the string length in EAX

        push    ecx
        push    edi
        mov     al,0
        mov     ecx,-1
        mov     edi,lpString
        repnz   scasb
        mov     eax,-2
        sub     eax,ecx
        pop     edi
        pop     ecx
        ret

stringLengthProc ENDP

;************************************************


and please - remove the call to swapit from the stringlength routine   :P

bcddd214

 Assembling: flipTest2.asm
flipTest2.asm(16) : error A2108: use of register assumed to ERROR
flipTest2.asm(16) : error A2008: syntax error : dword
flipTest2.asm(17) : error A2108: use of register assumed to ERROR
flipTest2.asm(17) : error A2008: syntax error : dword
flipTest2.asm(40) : error A2005: symbol redefinition : lpString
flipTest2.asm(40) : error A2111: conflicting parameter definition
flipTest2.asm(54) : error A2008: syntax error : ,
flipTest2.asm(61) : error A2111: conflicting parameter definition
Press any key to continue . . .

c:\Users\WUZAMA~1\Desktop\asm\ASM-PR~1>make16 flipTest2
Assembling: flipTest2.asm
flipTest2.asm(16) : error A2108: use of register assumed to ERROR
flipTest2.asm(16) : error A2008: syntax error : dword
flipTest2.asm(17) : error A2108: use of register assumed to ERROR
flipTest2.asm(17) : error A2008: syntax error : dword
flipTest2.asm(40) : error A2005: symbol redefinition : lpString
flipTest2.asm(40) : error A2111: conflicting parameter definition
flipTest2.asm(54) : error A2008: syntax error : ,
flipTest2.asm(61) : error A2111: conflicting parameter definition
Press any key to continue . . .

donkey

In stringLengthProc you have defined lpString as a parameter, you also define it as a global in your data section, you can't do that. You must also declare some value for it in the .DATA section, you can't just use lpString :dword. Also, I'm not sure what the rules for CALL are in MASM but I'm sure this is not allowed:

call   SwapIt offset inName,eax
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

bcddd214

Well the program was working as it should before, we just change the 'or's too mov?

bcddd214

http://pastebin.com/JzdzQfNs

I removed one of the lpstring definition and not erroring wildly.

:(


Assembling: flipTest2.asm
flipTest2.asm(16) : error A2108: use of register assumed to ERROR
flipTest2.asm(16) : error A2008: syntax error : dword
flipTest2.asm(17) : error A2108: use of register assumed to ERROR
flipTest2.asm(17) : error A2008: syntax error : dword
flipTest2.asm(54) : error A2008: syntax error : ,
flipTest2.asm(57) : fatal error A1010: unmatched block nesting : stringLengthPro
c
Press any key to continue . . .

donkey

Quote from: bcddd214 on December 24, 2011, 03:52:37 AM
Well the program was working as it should before, we just change the 'or's too mov?

I doubt that it worked the way it is written above, the "error A2108: use of register assumed to ERROR" and "error A2008: syntax error : dword" are directly caused by the improper declaration of the lpString and dwLength global variables. The symbol redefinition is directly caused by redefining lpString as a parameter of stringLengthProc. The "call   SwapIt offset inName,eax" is the line where you get the "syntax error : ,". Pretty much covers all of the errors I took the time to find, there may be more.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

dedndave

i went over this program again and again
i write it - then you rearrange it and make a mess out of it - lol
then, you ask all kinds of questions about the messed up code

and - let me tell you a secret.....
QuoteWell the program was working as it should before

and the secret is....
when you assemble with errors, the PREVIOUS EXE file is there - so you think it works
you can write your assembly batch files so that the old EXE is deleted
at the end of many of the batch files, they use something like this...
dir %1.*
i like to change it to
dir %1.* /o-d
that way, when the assembly is done - the newest files show up in the DIR list first
if your EXE isn't at the top of the list, you know right away you had an error

bcddd214

http://pastebin.com/tiNKEPzx

I took the 2 variable out of .data and it did clean up some but everywhere I try to redefine them I get nasty errors. Where should I declare them?

donkey

Found another error in the first code. You have declared SwapIt PROTO :DWORD,:DWORD (2 parameters) however the procedure is defined as SwapIt  PROC (no parameters) this will also throw an error, perhaps MASM exited before the error was encountered though.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

bcddd214

Quote from: dedndave on December 24, 2011, 04:07:08 AM
i went over this program again and again
i write it - then you rearrange it and make a mess out of it - lol
then, you ask all kinds of questions about the messed up code

and - let me tell you a secret.....
QuoteWell the program was working as it should before

and the secret is....
when you assemble with errors, the PREVIOUS EXE file is there - so you think it works
you can write your assembly batch files so that the old EXE is deleted
at the end of many of the batch files, they use something like this...
dir %1.*

do I add that @ the command line or in my asm file?
i like to change it to
dir %1.* /o-d
that way, when the assembly is done - the newest files show up in the DIR list first
if your EXE isn't at the top of the list, you know right away you had an error

bcddd214

Quote from: dedndave on December 24, 2011, 04:07:08 AM
i went over this program again and again
i write it - then you rearrange it and make a mess out of it - lol
then, you ask all kinds of questions about the messed up code

and - let me tell you a secret.....
QuoteWell the program was working as it should before



I know it was working and since I changed the or's to mov, it's been all downhill from there

bcddd214

Quote from: donkey on December 24, 2011, 04:10:14 AM
Found another error in the first code. You have declared SwapIt PROTO :DWORD,:DWORD (2 parameters) however the procedure is defined as SwapIt  PROC (no parameters) this will also throw an error, perhaps MASM exited before the error was encountered though.

should I remove or add parameter to match them up?

dedndave

i am not sure what you are doing there, buddy
it looks as though you are mixing win32 code in a dos16 program

bcddd214