News:

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

sval, what is this instruction exactly?

Started by l46kok, March 26, 2012, 12:35:12 PM

Previous topic - Next topic

l46kok

I searched the forum and looked through the documentation but found zero explanation for what the instruction "sval" does.

I did find an example of a usage:

mov     eax, sval(input("Number 2: "))

But I'm still left clueless on what the instruction sval is for. Help would be greatly appreciated.

qWord

sval is macro, which can be found in macros.asm.
It is also documented in \masm32\help\hlhelp.chm under the category "String macros":

Quotesval


mov value, sval(lpString)


Description

Convert a signed string value to a 32 bit integer.


Parameters

1. lpString The address of the signed numerical string value


Return Value

The return value is the 32 bit integer value.


Comments

The macro will recognise either leading sign notation for the negative values or no leading notation for a positive value. This macro is __UNICODE__ aware.


FPU in a trice: SmplMath
It's that simple!

l46kok

Ah that makes a lot of sense. Thanks for the clarification.

Although when I try to assemble my code, I get a weird error:

1>.\Assembly2.asm(18) : error A2006:undefined symbol : crt_atol



.386
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
include \masm32\macros\macros.asm

includelib \masm32\lib\masm32.lib
includelib \masm32\lib\kernel32.lib

.code

start:

    push    esi
    mov     esi, sval(input("Number 1: "))
    mov     eax, sval(input("Number 2: "))
    add     esi, eax
    print   str$(esi)
    pop     esi
    invoke  ExitProcess,0

END start


That error occurs everywhere I use the sval macro.

Any advice on how to fix this?

MichaelW

The macro depends on the CRT ( C Runtime Library) atol function so to use the macro you need to add the include file and import library for the MSVCRT DLL that contains the CRT. You can add these separately:

include \masm32\include\msvcrt.inc
includelib \masm32\lib\msvcrt.lib


Or just use the all in one include, so your source would then look like this:

include \masm32\include\masm32rt.inc

.code

start:

    push    esi
    mov     esi, sval(input("Number 1: "))
    mov     eax, sval(input("Number 2: "))
    add     esi, eax
    print   str$(esi)
    pop     esi
    invoke  ExitProcess,0

END start



Here is a link to the Microsoft CRT reference:

http://msdn.microsoft.com/en-us/library/59ey50w6(vs.71).aspx


eschew obfuscation