1

Ok, I first take two numbers from the text fields and convert them to numbers.

mulCode:
    mov EDX, 0
    push OFFSET zmB
    call ScanInt
    mov EBX, EAX
    push OFFSET zmA
    call ScanInt

Then I multiply the variable zmA by the variable zmB

    mul EBX
    mov zmA, EAX

And when I put a breakpoint, and look at the value of the variable, then it stores the result of the multiplication, so far everything is fine. But then I again need to convert this result to a string. I am trying to do this with the wsprintfA function.

    mov array + 0, eax
    push    OFFSET buforVar
    push    OFFSET array
    call    wsprintfA

    jmp printResultMul


    printResultMul:
    INVOKE TextOutA,hDC,250,120,OFFSET buforVar, rr
    mov EAX,0

To do this, I first place the result in the 'array' table, and then in 'buforVar' I want to get it as a string. And somewhere in this place I have a problem. Or am I writing incorrectly first writing the variable to 'array' or something is wrong with the wsprintfA function (also in the code I cannot write its prototype 'wsprintfA PROTO C :VARARG').

Here is what this piece of code looks like together:

mulCode:
    mov EDX, 0
    push OFFSET zmB
    call ScanInt
    mov EBX, EAX
    push OFFSET zmA
    call ScanInt
    mul EBX
    mov zmA, EAX

    mov array + 0, eax
    push    OFFSET buforVar
    push    OFFSET array
    call    wsprintfA

    jmp printResultMul

printResultMul:
INVOKE TextOutA,hDC,250,120,OFFSET buforVar, rr
mov EAX,0

Data segment:

wybor   DD 0

zmA DD 0
zmB DD 0
zmC DD 2
zmD DD 0
zmE DD 0
zmF DD 0
zmG DD 0

buforVar    DD  128 dup(?)
buforVar2   DD  128 dup(?)
buforVar3   DD  128 dup(?)

array dd 20 dup(?)

np.
  • 109
  • 1
  • 11
  • To answer the title question, it's not hard to do it yourself: [How do I print an integer in Assembly Level Programming without printf from the c library?](https://stackoverflow.com/a/46301894) Although calling some form of sprintf may be even easier. – Peter Cordes Jan 31 '22 at 18:21
  • it doesn't work for my case – np. Jan 31 '22 at 18:25
  • I don't see a format string anywhere in your code. `sprintf` needs one as the 2nd arg, including MS's `wsprintfA`: Check the C docs: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-wsprintfa and https://en.cppreference.com/w/c/io/fprintf has an example of what args it takes. – Peter Cordes Jan 31 '22 at 18:31
  • you are writing hints that are not related to my question at all, I am programming in masm assembler and your answers are referring to nasm assembler. they are completely different things – np. Jan 31 '22 at 18:39
  • 2
    They're both Intel-syntax, and the instructions themselves in my answer would work almost unchanged in MASM. Only difference is `0Ah` instead of `0xa`. (The other major difference between MASM and NASM is how symbol names work when used not with registers, and `byte ptr` vs. `byte`, but neither of those occur in my code). Obviously the directives around the instructions would be different, and the calling convention, but that's part of why I just linked it as a comment, not closed as a duplicate. And most importantly, the answer explains the algorithm so anyone can adapt / reimplement it. – Peter Cordes Jan 31 '22 at 19:01
  • 1
    And I linked C stuff because your bug isn't in asm details, but rather what args you chose to pass. – Peter Cordes Jan 31 '22 at 19:01

0 Answers0