0

Hi I am beginner in assembly language , can any one help me to understand how to deal with numbers in assembly language x86. I face difficulty when I handle any task related with numbers, I can't execute programs like shl, shr , mul, div two digit addition if any one can explain or share code for the following I will be very thankful

Like :

Mov Al 2
Mov Bx 2
mul bx

mov dx,bx
mov ah,2
int 21h 

But it can not show correct output it was shown in symbols if I covert it through subtracting 30h even that cant show correct answer.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
sahar
  • 25
  • 1
  • 1
  • In assembly, you read and write *characters*. If you need the numeric values, you must convert the character value to a number and then combine the numbers to whatever type you are trying to create. See [ASCIITable](http://asciitable.com) – David C. Rankin Nov 22 '17 at 07:06
  • 1
    Two digit number on screen consists of two ASCII characters. like `mov dl,'2' mov ah,2 int 21h mov dl,'5' mov ah,2 int 21h` will output "25" on screen. No actual value `25` was used at all in that example. DOS has no service to output numbers. You will have to convert the numbers to characters first. See: https://stackoverflow.com/tags/x86/info ... if you are just learning assembly basics, skip the string stuff completely, and use debugger to verify your numeric values are ok. Work with strings later, when you will have experience with arithmetic and memory manipulation. – Ped7g Nov 22 '17 at 07:09

1 Answers1

1

I can't execute programs like shl, shr , mul, div

shl, shr , mul, div are instructions. Please don't refer to them as programs.

... I covert it through subtracting 30h ...

See in the code below that the conversion requires you to add 30h instead of subtracting 30h.

Mov Al 2
Mov Bx 2
mul bx
mov dx,bx
mov ah,2
int 21h 

You can correct this program that multiplies 2 single digit numbers.

Error 1 : Choose the correct size multiplication. Using mul bx, you've calculated DX:AX = AX * BX which is overkill in this case. Moreover since you forgot to zero AH, you got random results!

mov al, 2
mov bl, 2
mul bl       ; -> AX = AL * BL

Error 2 : Convert the result which is the number 4 ( 2 * 2 ) into the character "4".
Also notice that the result of the mul instruction is not to be found in the BX register, like your code is thinking (mov dx, bx).
mul bl leaves its result in AX, and since the value is so small, we need only use AL (the low half of AX)

add al, "0"  ;"0" = 30h
mov dl, al
mov ah, 02h
int 21h

It's important to see that this very simple way of displaying the result can only work for results varying from 0 to 9.

To display numbers that are outside this [0,9] range take a look at Displaying numbers with DOS. The text explains in great detail how you can convert any number into its textual representation and output that to the screen.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76