Reputation: 35
I wish to have 2 user inputs. For example 8 and 3. Then I would to multiply them with the variable f1 and f2 so 8 x f1 and 3 x f2. Then I would like to add them so (8 x f1) + (3 x f2). I do not know how to multiply the user input with the variable and finally adding them together
;TITLE Multiply input with number then add them
.model small
.stack 100
.data
f1 DB 10
f2 DB 20
msg1 DB 13,10,"First input = $" ;--ask user to input 1 digit. Example = 8
msg2 DB 13,10,"Second input = $" ;--ask user to input 1 digit. Example = 3
msg3 DB 13,10,"Product = $" ;--multiply the first and second input with f1 and f2. So 8x10 and 3x20
msg4 DB 13,10,"Addition = $" ;--Add those numbers that have been multiplied to 80 + 60 = 140
q1 DB ? ;user inputs
q2 DB ?
.code
main proc
mov ax,@data
mov ds,ax
mov ah,09h
lea dx, msg1
int 21h
mov ah,01h
int 21h
sub al,30h
mov q1,al
;--multiplication of 1st user input with f1 here but idk how
mov ah,09h
lea dx, msg2
int 21h
mov ah,01h
int 21h
sub al,30h
mov q2,al
;--multiplication of 2nd user input with f2 here but idk how
mov ah,09h
lea dx, msg4
int 21h
;--Addition of those 2 multiplied numbers here
mov ah, 4Ch
int 21h
main endp
end main
Upvotes: 0
Views: 1899
Reputation: 39166
In the 8086 processor, you can choose between the byte-sized multiplication (result in AX
) and the word-sized multiplication (result in DX:AX
). Because your numbers are small you should choose:
The AL
register gets multiplied by the byte-sized operand that you specify in the mul
instruction. The product will get stored in the AX
register.
mov al, q1
mul f1 ; -> AX is product
Here you need to store the product somewhere safe, because the second multiplication will mandatory have to use that same AX
register!
Addition of both products should not be too difficult...
In case you need to display the outcome of the calculation on the screen, you can read Displaying numbers with DOS.
Upvotes: 1