News:

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

Data type problem ?

Started by Valente, September 28, 2008, 03:22:29 PM

Previous topic - Next topic

Valente

Hi community,

I'm new here in the forums but I've been reading some things since a week ago and today I decided to register so I could expose my beginner doubts' here. Anyway, I'm wrtiing this topic because I wrote a basic program in Assembly that doubles up the number the user introduce on the prompt.

Here is the 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 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

    .data

  Txt db "Introduza o numero:  ", 0
  Num db " ", 8
  final DWORD ?

    .code                       ; Tell MASM where the code starts

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

start:                          ; The CODE entry point to the program

invoke StdOut, ADDR Txt         ; imprime a mensagem da variavel Txt
invoke StdIn, ADDR Num, LENGTHOF Num
invoke StripLF, ADDR Num
invoke atodw, ADDR Num

mov final, eax
add final, eax

invoke dwtoa, final, ADDR final
invoke StdOut, ADDR final

invoke ExitProcess,0

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start                       ; Tell MASM where the program ends




The problem is that it only doubles up numbers from 1 to 9. If a user introduces '10' on the prompt it doesn't work. What can I do to make it work right now ?

Jimg

The problem is you are not leaving enough room for the input and conversion.  Try-

Num db 10 dup (0)

Valente

Quote from: Jimg on September 28, 2008, 04:04:26 PM
The problem is you are not leaving enough room for the input and conversion.  Try-

Num db 10 dup (0)


Yeah it worked fine. I know what means Num db (Num is the variable name and db means double byte) but I don't know what is the rest of the variable definition. Can you explain in the detail the instruction ?

Thank you for helping.

Neil

db   stands for DATA BYTE  i.e.  one single byte

10 dup (0)   stands for repeated 10 times & initialised to zero

Mark Jones

Hello Valente, welcome to the forums. Please look at the \MASM32\help\asmintro.chm file, that help file is absolutely essential in understanding the basics of assembler. :U
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Jimg

Like Valente said, but for me, db means define byte(s).

You should get a copy of the Masm Programmers Guide, it's available as a .chm help file someplace here I the board that I can't find at the moment.  Anyone?


GregL

Here's a link to the 'MASM Programmer's Guide' in CHM format.

http://www.box.net/shared/qkpzlg42hf




Jimg

Thanks Greg.  For myself, I've never been able to download from site, I always get "This user is not allowed to use direct links.
Please email support@box.net for support ".

I just found a link that works for me at ghirhi's site - http://ghirai.com/hutch/mmi.html

GregL

Jimg,

That's weird, it should work. That link is not for my box.net account. andrejus took the HTML Help Project I created and added in some better graphics. So that link is his, it should work though, you just put stuff you want to share in a public folder. It's 1 GB free storage. Glad to hear you were able to get it at ghirai's site. He's got a good collection of stuff there.