I am using x86 bit window 7 in my system and gui turbo assembler in my system. I want to get two numbers from user and multiply it. what is the procedure?
.model small .stack 100h .data num db 2 dup(0) .code main proc mov ax, @data mov dx, ax mov ah, 1 int 21h ;get a number from user mov num, dl ;store number in num[0] int 21h ;get number from user mov ah, 2 int 21h mov ah, 4ch int 21h main endp end main 12 Answers
From , also take a look at Intel IA-32 PRM:
mul or imul
In this case (two one-digit numbers) I would prefer BCD arithmetic:
.MODEL small .STACK 1000h .DATA num db '3', '4' result db '$$$' .CODE main PROC mov ax, @data mov ds, ax ; DS! DS! NOT DX! mov ah, 01h ; Wait for one character int 21h mov num, al ; AL! AL! NOT DL! mov ah, 01h ; Wait for one character int 21h mov num+1, al mov dl, 0Ah ; Linefeed mov ah, 02h ; Cooked output int 21h mov ax, word ptr [num] and ax, 0F0Fh ; Convert ASCII numbers to integers mul ah ; AX = AL * AH aam ; Convert integer in AL to unpacked BCD in AX or ax, 3030h ; Convert integers to ASCII xchg al, ah ; Convert big endian to little endian mov word ptr [result], ax mov dx, OFFSET result mov ah, 09h ; Output until '$' int 21h mov ax, 4C00h ; Exit (0) int 21h main ENDP end main Now you can consider how to disable leading zero's.
EDIT: An attempt of explanation:
1) The two numbers are in [num] and [num+1] as bytes. Two bytes are one word, so I can use the word-register AX to load them. The AX word-register consists of the two byte-registers AH and AL, so in AL is [num] and in AH is [num+1].
2) The two numbers are ASCII coded though as they came in this form from the input. The ASCII codes for the numbers 0d to 9d are 30h to 39h. You see that we can get the integer numbers by setting the first nibble to 0. That can be done by the AND command, e.g. 34 AND 0F is 04. For simplicity and elegance I did this step by ANDing AX (AH and AL in one step). Example: 3234 AND 0F0F is 0204.
3) The MUL command here multiplies AL with another register. MUL AH multiplies AL with AH. The result goes into AX. With AAM I get two decimal numbers from the binary integer in AL which were converted to ASCII Characters by ORing. When I store AX to [result] first AL will be stored and then AH, e.g. a 12 in AX would be stored as 2,1. To avoid this I reverse the number order in AX with XCHG. Now the result can be correctly stored for INT 21h Fn 09h.
You need a book which explains the processor from scratch and in better English. Dr. Paul Carter's tutorial is a good choice:
1