[MASM32] Błąd: sval() - undefined symbol crt wtol

Αvenger

Były Moderator
Dołączył
Grudzień 21, 2012
Posty
243
Witam, tak jak w tytule.
Kod:
.486                              
.model flat, stdcall                     
option casemap :none                 

include E:\masm32\include\windows.inc     
include E:\masm32\macros\macros.asm       
include E:\masm32\include\masm32.inc
include E:\masm32\include\kernel32.inc
include E:\masm32\include\user32.inc
includelib E:\masm32\lib\masm32.lib
includelib E:\masm32\lib\kernel32.lib
includelib E:\masm32\lib\user32.lib

.code                                       

Call Funkcja1  
exit                                       

start:                                   
Funkcja1 proc
LOCAL int1:DWORD
LOCAL int2:DWORD
mov int1,input("Your number: ")
mov int2, sval(int1)
ret
Funkcja1 endp
end start
Co jest nie tak?
Z góry dziękuje.
Pozdrawiam, Avenger.
 

D.F.

Były Moderator
Dołączył
Listopad 4, 2009
Posty
493
Błąd występuje w linijce:
Kod:
mov int2, sval(int1)

Makro sval używa wewnątrz siebie funkcji crt_atol lub crt__wtol, dlatego należy dodać na początku programu:
Kod:
include msvcrt.inc
includelib msvcrt.lib

Kolejna sprawa to na początku należy utworzyć konsolę z której chcesz czytać, czyli:
Kod:
call AllocConsole

Zatem cały kod powinien wyglądać mniej więcej tak:
Kod:
.486                              
.model flat, stdcall                     
option casemap :none                 

include windows.inc     
include C:\masm32\macros\macros.asm
include masm32.inc
include kernel32.inc
include user32.inc
include msvcrt.inc

includelib masm32.lib
includelib kernel32.lib
includelib user32.lib
includelib msvcrt.lib

.code                                       

start:
call AllocConsole
call Funkcja1 
 
push 0
call ExitProcess

Funkcja1 proc
    LOCAL int1:DWORD
    LOCAL int2:DWORD
    
    mov int1,input("Your number: ")
    mov int2, sval(int1)
    
    ret
Funkcja1 endp

end start
 
Ostatnia edycja:

Αvenger

Były Moderator
Dołączył
Grudzień 21, 2012
Posty
243
Teraz działa. Dziękuje ślicznie :)
Mam jeszcze dwa pytania odnośnie wyżej podanego kodu.
1. W jednym z example masma sval() funkcjonowalo prawidlowo bez koniecznosci importu msvcrt.inc, msvcrt.lib. Chyba, że coś przeoczyłem, kod poniżej.
2. Czy Call AllocConsole jest konieczne przy programowaniu konsoli?
Kod:
    .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 files that have MASM format prototypes for function calls
  ; -----------------------------------------------------------------
    include \masm32\include\masm32.inc
    include \masm32\include\gdi32.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc

  ; ------------------------------------------------
  ; Library files that have definitions for function
  ; exports and tested reliable prebuilt code.
  ; ------------------------------------------------
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\gdi32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib

    .code                       ; Tell MASM where the code starts

start:                          ; The CODE entry point to the program

    call main                   ; branch to the "main" procedure

    exit

main proc

    LOCAL var1:DWORD            ; space for a DWORD variable
    LOCAL str1:DWORD            ; a string handle for the input data

  ; test the MOV and ADD instructions

    mov eax, 100                ; copy the IMMEDIATE number 100 into the EAX register
    mov ecx, 250                ; copy the IMMEDIATE number 250 into the ECX register
    add ecx, eax                ; ADD EAX to ECX
    print str$(ecx)             ; show the result at the console
    print chr$(13,10,13,10)

  ; ----------------------------------------
  ; The two following macros can be combined
  ; once you are familiar with how they work
  ; ----------------------------------------
 ;     mov str1, input("Enter a number : ")
 ;     mov var1, sval(str1)        ; convert the result to a signed integer

    mov var1, sval(input("Enter a number : "))

    cmp var1, 100               ; compare the variable to the immediate number 100
    je equal                    ; jump if var1 is equal to 100 to "equal"
    jg bigger                   ; jump if var1 is greater than 100 to "bigger"
    jl smaller                  ; jump if var1 is less than 100 to "smaller"

  equal:
    print chr$("The number you entered is 100",13,10)
    jmp over

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

  smaller:
    print chr$("The number you entered is smaller than 100",13,10)

  over:

    ret

main endp

end start                       ; Tell MASM where the program ends
 

D.F.

Były Moderator
Dołączył
Listopad 4, 2009
Posty
493
Αvenger;143117 napisał:
1. W jednym z example masma sval() funkcjonowalo prawidlowo bez koniecznosci importu msvcrt.inc, msvcrt.lib. Chyba, że coś przeoczyłem, kod poniżej.
Mi ten przykład nie działa, wyświetla się taki błąd jak w temacie. Jak dodam msvcrt.inc i msvcrt.lib to wtedy dopiero działa.

Αvenger;143117 napisał:
2. Czy Call AllocConsole jest konieczne przy programowaniu konsoli?
Teraz dopiero zauważyłem, że testowałem Twój kod z ustawieniem konsolidacji:
Kod:
/SUBSYSTEM:WINDOWS
zamiast:
Kod:
/SUBSYSTEM:CONSOLE
Jak użyjesz /SUBSYSTEM:CONSOLE to konsola się pojawia bez potrzeby wywołania AllocConsole.
 

Αvenger

Były Moderator
Dołączył
Grudzień 21, 2012
Posty
243
Masz rację. Kod z example nie działa, sprawdziłem tylko binarke, dopiero makeit wypluwa w/w błąd.
Jak oni ten kod pisali, że zapomnieli o tych includach :)
 
Do góry Bottom