News:

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

New to MASM/MACROs - string problem - please help

Started by Foulone, February 24, 2005, 04:17:08 PM

Previous topic - Next topic

Foulone

The bug with this program is:

when you jmp to label1, the question is appended with the last quess.

i.e. if you guess 37

next time round the question reads "Guess the number : 37"

then if you guess 99

next time round the question reads "Guess the number : 99"


Any ideas?

---------- START OF CODE ----------

.486                                                      ; create 32 bit code
.model       flat, stdcall                                 ; 32 bit memory model
option       casemap :none                                 ; case sensitive
;--------------------------------------------------------------------------------
include    \masm32\include\windows.inc                   ; always first
include    \masm32\macros\macros.asm                     ; MASM support macros
include    \masm32\include\masm32.inc
include    \masm32\include\gdi32.inc
include    \masm32\include\kernel32.inc
;--------------------------------------------------------------------------------
includelib    \masm32\lib\masm32.lib
includelib    \masm32\lib\gdi32.lib
includelib    \masm32\lib\kernel32.lib
;--------------------------------------------------------------------------------
.data

var1      dd 0                                           ; space for a DWORD variable
str1      dd 0                                        ; a string handle for the input data
;--------------------------------------------------------------------------------
.code                                               ; Tell MASM where the code starts

start:                                                     ; The CODE entry point to the program

main proc

    call    main_subroutine
    mov      str1, input(13,10,"End")

    exit
main endp


main_subroutine      proc

    mov     eax, 345                                    ; copy the IMMEDIATE number 100 into the EAX register
    mov     ecx, 250                                    ; copy the IMMEDIATE number 250 into the ECX register
    push    eax
    push    ecx
    push   ecx   
    print   chr$("Start",13,10,13,10)
    pop     ecx
    print   str$(ecx)                                   ; show ecx value
    print   chr$(13,10,13,10)
    pop     ecx
    pop     eax
    add     ecx, eax                                    ; ADD EAX to ECX
    print   str$(ecx)                                   ; show the result at the console
    print   chr$(13,10,13,10)
loop1:
   
      mov    str1, input("Guess the number : ")
       mov    var1, sval(str1)                       ; convert the result to a signed integer
       cmp    var1, 100                              ; compare the variable to the immediate number 100
       jl       smaller                                   ; jump if var1 is less than 100 to "smaller"
       jg       bigger                                 ; jump if var1 is greater than 100 to "bigger"

   equal:
       print    chr$(13,10,"Good human, your starting to learn!",13,10)
       jmp    over

   bigger:
       print    chr$(13,10,"The number you entered is greater than 100",13,10,"TRY AGAIN!",13,10)
       jmp    loop1

   smaller:
       print    chr$(13,10,"The number you entered is smaller than 100",13,10,"TRY AGAIN!",13,10)
       jmp    loop1

over:
    ret

main_subroutine    endp

;----------------------------------------------------------------------------------------------------
end start                                            ; Tell MASM where the program ends

AeroASM

The input macro was coded wrong. Go into your \masm32\macros\macros.asm, find the input macro and change it like this:


...
txt db prompt
buffer db 128 dup (0)
...


becomes...


...
txt db prompt
db 0
buffer db 128 dup (0)
...

Foulone

Thanks a million!

Am I using an out of date macros.asm file?


pbrennick

#3
Foulone,
There is a newer version of the macro.asm file as well as the windows.inc file.  Look in the Projects Support Forums and click MASM32.  Always check there for late breaking changes.  The entire project is a 'work in progress' and Hutch (and others) is always making it better.  You can get the latest version of macros.asm at http://www.masmforum.com/simple/index.php?topic=833.msg5809#msg5809

Enjoy the experience,
Paul

Bieb

btw, it should say "you're starting to learn", not "your"


Titan

Off topic: I like your signature Foulone, I'm a HUGE Tetris fan! :cheekygreen: