0

I have made a procedure that multiplies 2 numbers using add and shift method and stores the result in a buff variable.

Here, buff1 and buff2 are initialised in the data section of the code as word type.

buff1 dw 0AH

buff2 dw 03H

And buff is declared in .bss section as 4 byte.

buff resb 4

Here is the procedure that does the multiplication :

shift_add:
    movzx eax,word[buff1]     ;2byte
    movzx ebx,word[buff2]
    mov edx,0H
    mov rcx,16  ;integer
    backs:
        shr bl,1
        jnc haha
        add edx,eax
    haha:
        shl eax,1
    loop backs  
    mov dword[buff],edx
    print buff,4
ret

Why is the above code giving me garbage output ?enter image description here

5
  • Because you forgot to convert to text for printing. Note it printed the character 0x1e which is in fact the correct answer. Commented Mar 30, 2018 at 18:05
  • Yes, but why is 001E printed in a small box Commented Mar 30, 2018 at 18:11
  • 1
    Because you didn't convert it to text. If you look at an ascii table you will see it's unprintable character, and the terminal is trying its best to display it. Commented Mar 30, 2018 at 18:12
  • Many a times when I print it like that, then it works but not now !! Also 001E will be of 2 bytes but I have passed 4 as 2nd argument with buff as 1st argument in the print buff,4 instruction. Why are other 0s not getting printed ? Commented Mar 30, 2018 at 18:16
  • Presumably your terminal simply ignores zero bytes. It is printed though. You can see it if you pipe it into a hex dump for example. print only works if you provide it text. Your "many a times" probably involved text not binary. Commented Mar 30, 2018 at 18:25

1 Answer 1

1

try shr ebx,1 instead of shr bl,1.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.