Posted on 2005-09-25 21:02:35 by chola
You have to convert string to binary before div instruction.
Ofcourse div uses binary data NOT strings.
Posted on 2005-09-26 01:14:19 by s5vi
how can i do this ??

change the string to binary and viceversa ???

Posted on 2005-09-26 09:57:26 by chola
can anybody help me with the division, i don't have any clue to do the algorithm. using atodw (ascii to doubleword) and dwtoa (doubleword to ascii) functions.


  xor edx,edx
  mov ecx, str1
  mov eax, str2
  div ecx ; HACE: str2 / str 1
  mov rslt, eax

Thanxx .......... ;)
Posted on 2005-09-26 22:51:22 by chola
Algo así, supongo (no lo probé pero debería funcionar):


invoke atodw, offset str1
push eax
invoke atodw, offset str2
pop ecx
xor edx, edx
div ecx
mov rslt, eax
Posted on 2005-09-27 10:36:02 by QvasiModo
MUCHAS GRACIAS, NO SABES LOS PROBLEMAS QUE HE TENIDO PARA RESOLVER ESTE "SIMPLE" ALGORITMO.

:oops:


Algo así, supongo (no lo probé pero debería funcionar):


invoke atodw, offset str1
push eax
invoke atodw, offset str2
pop ecx
xor edx, edx
div ecx
mov rslt, eax

Posted on 2005-09-27 11:57:25 by chola

:sad:
I'm have the same problem, i try to many ways to fix the code, but nothing happends. can anybody fix my code to work propertly.



ESTE PROGRAMA LO QUE DEBE DE HACER ES DIVIDIR DOS NUMEROS PERO LE HE INTENTADO DE MIL FORMAS Y NO DIVIDE LOS NUMEROS, HE INTENTADO CAMBIAR DE STRING A BINARIO PARA HACER LA DIVISION, HACER AJUSTES, DE TODO Y NO ME FUNCIONA, SI ALGUIEN POR FAVOR ME AYUDA CORRIGIENDOME EL ERROR QUE YO NO ENCUENTRO SE LOS AGRADECERIA.




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

    .486                                   ; Directiva indicando uso de instrucciones del 80486
    .model flat, stdcall                   ; Directiva indicadora del modelo de memoria 32 bits
    option casemap :none                   ; Directiva para el reconocimiento de mayusculas 
                                           ; y minusculas

    include \masm32\include\windows.inc    ; Siempre debe ser inicializado de primero
    include \masm32\macros\macros.asm      ; Instrucción para la utilización de macros

  ; -- ---------------------------------------------------------------
  ; Librerias que deben ser utilizada para utilizar funciones
  ; -----------------------------------------------------------------
    include \masm32\include\masm32.inc
    include \masm32\include\gdi32.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc

    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\gdi32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib

    .code                       ; Directiva que indica el inicio el código

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

start:                          ; Inicio del programa

    call main                   ; Invocado el procedimiento main

    exit

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

main proc


    LOCAL str1:DWORD
    LOCAL str2:DWORD
    LOCAL var1:DWORD
    LOCAL var2:DWORD
    LOCAL rslt:DWORD
    LOCAL text:DWORD
    LOCAL resi:DWORD
    LOCAL rsltvalue:DWORD
   

; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
    LOCAL eax1:DWORD
    LOCAL ebx1:DWORD
    LOCAL ecx1:DWORD
    LOCAL edx1:DWORD
; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤



    LOCAL buffer1[32]:BYTE
    LOCAL buffer2[32]:BYTE
    LOCAL buffer3[32]:BYTE

    mov str1, ptr$(buffer1)
    mov str2, ptr$(buffer2)
    mov rsltvalue, ptr$(buffer3)


    cls
    loc 10, 6
    print "PROGRAM THAT DIVIDE TWO NUMBERS"

    loc 10, 8
    mov str1, input("NUMBER 1: ")
    mov var1,sval(str1)
    cmp var1,100
    jg mayor1
   
    loc 10, 100
    mov str2, input("NUMBER 2: ")
    mov var2,sval(str2)
    cmp var2,10
    jg mayor2

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
;Procedimiento para realizar la división

   
    sub  sval(str1),30H
    sub  sval(str2),30H
    loc  1,19
    print str1
    loc  1,20
    print str2
    push eax
    mov  eax, sval(str1)
    mov  ebx, sval(str2)
    xor  edx,edx     ;prepare for division
    div  ebx
    add  eax,30h      ;convert to an ascii character
    add  ebx,30h
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    mov rslt,sstr$(eax)
    mov resi,sstr$(ebx)
    pop esi

    loc 10, 12
    print "Result = "
    print rslt
    loc 10,14
    print "Residuo = "
    print resi

; ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤
    jmp salida

mayor1:
    cls
    loc 10,12
    mov text, input("EL NUMERO DEBE SER DE UN BIT....")
    mov str1,"   "
    jmp main

mayor2:
    cls
    loc 10,12
    mov text, input("EL NUMERO DEBE SER DE UN BIT....")
    mov str2,"   "
    jmp main

salida:
    loc 10, 20
    mov str1, input("Digite enter para Terminar ....")

    cls

    ret

main endp

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

end start
Posted on 2005-09-27 23:54:29 by chola
chola,
    Included as an attachment is a HEX calculator from Charles Petzold's book, Programming Windows, 5th edition.  The listing is in the C programming language, but if you still have trouble, I can convert it to MASM for you. Ratch
Attachments:
Posted on 2005-09-28 09:17:33 by Ratch
Restar o sumar 30H no convierte cadenas a números binarios, ni números a cadenas. Como es un poquito más complicado ;) hay que usar las funciones atodw y dwtoa respectivamente.

Translation: Substracting or adding 30H does not convert strings to numbers nor numbers to strings. It's a little more complicated than that ;) so you have the atodw and dwtoa functions respectively to do it.
Posted on 2005-09-28 10:30:42 by QvasiModo
BTW, I just noticed str1 and str2 are LOCALs, so change it to this:


invoke atodw, addr str1
push eax
invoke atodw, addr str2
pop ecx
xor edx, edx
div ecx
mov rslt, eax

Posted on 2005-09-28 10:32:43 by QvasiModo
Chola, try to include such long code as attachments to post (like Ratch did), this will keep the thread much clean and easy to read. Plus, you don't need the scrolling marquee stuff, that tends to annoy people more than it grabs their attention to help you. Just be simple and straight to the point when you post and people will help you.
Posted on 2005-09-28 16:12:40 by SpooK
STR1 and STR2 Are locals.
I do that, but when run this line invoke atodw, addr str1 the result of eax is a number different to the conversion of the number that i enter.

for ex: if i enter 4 in str1, when i run the first line the number in eax must be 4 in hex. but it's convert to a different number 18316. and i don't know why. can anybody explain to me, and help me.

thanxx


BTW, I just noticed str1 and str2 are LOCALs, so change it to this:


invoke atodw, addr str1
push eax
invoke atodw, addr str2
pop ecx
xor edx, edx
div ecx
mov rslt, eax


Posted on 2005-10-03 10:57:31 by chola
THANXXX TO ALL THE PEOPLE WHO HELP ME !!

:D
;)

THANK YOU !
Posted on 2005-10-05 08:22:32 by chola