News:

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

Help me please

Started by dgonzalez, September 16, 2005, 03:27:32 PM

Previous topic - Next topic

dgonzalez

Hello friends I am new in this version of asembler, I have a problem with the following code, I want to make a program that receives two numbers and conducts operation logica AND, until now I have managed to enter both numbers, but when I want to show the result, it shows very rare values to me. Somebody can help me please.


.486                                   
    .model flat, stdcall                   
    option casemap :none                   

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

  ; -----------------------------------------------------------------
  ; 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

  ; --------------------------------------------------------------
  ; This is a prototype for a procedure used in the demo. It tells

  ; --------------------------------------------------------------
    show_text PROTO :DWORD

    .data
      txtmsg db "Entre el segundo numero (un solo digito y enter) : ",0


    .code                       

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

start:                          ; The CODE entry point to the program

    call main                   ; branch to the "main" procedure

    exit

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

main proc

    LOCAL txtinput:DWORD            ; a string handle for the input data

    LOCAL txtinput1:DWORD            ; a string handle for the input data

    mov txtinput, input("Entre el primer numero (un solo digito y enter) : ")
    mov eax, sval(txtinput)   

    mov txtinput1, input("Entre el segundo numero (un solo digito y enter) : ")
    mov edx, sval(txtinput1)

    and eax, edx

    mov ecx, eax

    print chr$("Este es el resultado",13,10,"     *** ")
    print str$(ecx)
    print chr$(" ***",13,10)

    ret

main endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start                       

Infro_X

and eax, edx
mov ecx, eax


and != add,

anding the following:
4,2 would produce 0,,, 0000 0100 and 0000 0010 = 0000 0000
5,4 would produce 4,,, 0000 0101 and 0000 0100 = 0000 0100

and-ing is a bit by bit opperation. if both bits are 1, the result is 1, if either of the bits are 0, the result is 0
xor-ing is a bit by bit opperation. if both bits are the same, the result is 0, if both bits are opposite, the result is 1,    0 xor 0=0, 1 xor 1=0, 1 xor 0=1, 0 xor 1=1
or-ing is a bit by bit opperation, if either bit is one, the result is 1, if both bits are 0, the result is 0

add should be used too add, and is different

dgonzalez

Hello Infro X, I want to thank for your aid, and what you say to me in your message is clear and I understand it, but my problem is that when I'm doing logica operation AND between two number and I want to show result in screen, shows very rare values.

mov txtinput, input("Type the first number: ")
mov eax, sval(txtinput)   

mov txtinput1, input("Type the second number: ")
mov edx, sval(txtinput1)


and eax, edx

mov ecx, eax

print chr$("The result is:",13,10,"     *** ")
print str$(ecx)
print chr$(" ***",13,10)

P1

Quote from: dgonzalez on September 16, 2005, 04:34:22 PM
mov ecx, eax

print chr$("The result is:",13,10,"     *** ")
print str$(ecx)
print chr$(" ***",13,10)
You have not converted the value of ecx to a string yet.

Regards,  P1  :8)

AeroASM

Quote from: dgonzalez on September 16, 2005, 04:34:22 PM
I'm doing logica operation AND between two number
Quote from: Infro_X on September 16, 2005, 03:59:43 PM
and eax, edx
mov ecx, eax


and != add,

anding the following:
4,2 would produce 0,,, 0000 0100 and 0000 0010 = 0000 0000
5,4 would produce 4,,, 0000 0101 and 0000 0100 = 0000 0100

and-ing is a bit by bit opperation. if both bits are 1, the result is 1, if either of the bits are 0, the result is 0
xor-ing is a bit by bit opperation. if both bits are the same, the result is 0, if both bits are opposite, the result is 1, 0 xor 0=0, 1 xor 1=0, 1 xor 0=1, 0 xor 1=1
or-ing is a bit by bit opperation, if either bit is one, the result is 1, if both bits are 0, the result is 0

add should be used too add, and is different

but he wants to AND not add!

Quote from: P1 on September 16, 2005, 05:09:17 PM
Quote from: dgonzalez on September 16, 2005, 04:34:22 PM
mov ecx, eax

print chr$("The result is:",13,10,"     *** ")
print str$(ecx)
print chr$(" ***",13,10)
You have not converted the value of ecx to a string yet.

Regards, P1 :8)

But he has! with str$(ecx)!!

Why do people post replies to newbies without reading the post properly!

The real problem is that your values in eax, edx and ecx get overwritten when you use functions like chr$, str$ and input. The standard convention is for each function to preserve only ebx, esi, edi, esp and ebp. Therefore either do this:


mov eax,input("blah")
push eax
mov edx,input("blah")
pop eax


or


mov ebx,input("blah")
mov esi,input("blah")


P1

Quote from: AeroASM on September 16, 2005, 06:26:05 PM
But he has! with str$(ecx)!!

Why do people post replies to newbies without reading the post properly!
Ok, My Bad. 

I drop in on and off during my job, when I'm waiting for some computer to do a task.  I will admit, that could lead to errors.  With great members like you to point them out.  A newbie is not in too much trouble.

My blessing to you is that you eat your humble pie with Gladness and Honesty.

Mis Disculpas Infro_X.

Regards,  P1  :8)