如何将 2 个用户输入与两个数字相乘,然后将它们添加到汇编 8086 处理器中? [英] How to multiply a 2 user inputs with two numbers then add them in assembly 8086 processor?

查看:31
本文介绍了如何将 2 个用户输入与两个数字相乘,然后将它们添加到汇编 8086 处理器中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有 2 个用户输入.例如 8 和 3.然后我会将它们与变量 f1 和 f2 相乘,所以 8 x f1 和 3 x f2.然后我想将它们添加为 (8 x f1) + (3 x f2).我不知道如何将用户输入与变量相乘,最后将它们加在一起

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

推荐答案

在 8086 处理器中,您可以选择 byte-sized 乘法(结果为 AX)和 word-sized 乘法(结果为 DX:AX).因为您的数字很小,所以您应该选择:

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:

AL 寄存器乘以您在 mul 指令中指定的字节大小的操作数.产品将存储在 AX 寄存器中.

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

在这里您需要将产品存储在安全的地方,因为第二次乘法必须使用相同的 AX 寄存器!

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...

如果您需要在屏幕上显示计算结果,您可以阅读Displaying numbers withDOS.

In case you need to display the outcome of the calculation on the screen, you can read Displaying numbers with DOS.

这篇关于如何将 2 个用户输入与两个数字相乘,然后将它们添加到汇编 8086 处理器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆