汇编语言8086中的2个值乘以?

时间:2013-04-19 21:07:14

标签: assembly x86 masm irvine32

我将从控制台窗口输入两个值相乘。我正在使用 32位寄存器eax,ebx ,但它没有将这些值相乘。该程序正在运行,但它没有成倍增加。任何人都可以发现问题吗?这段代码有什么问题?我正在使用汇编语言的KIP.R.IRVINE链接库。

以下是代码:

  INCLUDE Irvine32.inc

  .data

   inputValue1st BYTE "Input the 1st integer = ",0
   inputValue2nd BYTE "Input the 2nd integer = ",0
   outputSumMsg BYTE "The sum of the two integers is = ",0

   num1 DD ?
   num2 DD ?
   sum  DD ?


  .code

  main PROC

   ; here we are calling our Procedures

  call InputValues
  call multiplyValue
  call outputValue
  call Crlf

  exit
  main ENDP



InputValues PROC

;----------- For 1st Value--------
; input message

call Crlf
mov edx,OFFSET inputValue1st
call WriteString


call ReadInt    ; read integer
mov num1, eax   ; store the value


 ;-----------For 2nd Value----------

 ; output the prompt message
 mov edx,OFFSET inputValue2nd
 call WriteString


  call ReadInt  ; read integer
  mov num2, ebx     ; store the value

  ret
  InputValues ENDP



   ;---------multiply----------------

   multiplyValue PROC
   ; compute the sum

    mov eax, num1   ; moves num1 to eax
    mov ebx, num2   ; moves num2 to ebx

    mul ebx  ; num1 * num2 = 6 * 2
    mov sum, eax  ; the val is stored in ebx


    ret
    multiplyValue ENDP


    ;--------For Sum Output Result----------

    outputValue PROC


    ; output result
    mov edx, OFFSET outputSumMsg
    call WriteString


    mov eax, sum
    call WriteInt ; prints the value in eax
    ret
    outputValue ENDP


    End main

还有一个问题:我是否需要在其中使用进位标志?如果是这样,那么它的代码是什么样的?

3 个答案:

答案 0 :(得分:1)

;mov eax, num1   ; moves num1 to eax
;mov ebx, num2  ; moves num2 to ebx

如果您要将值实际加载到寄存器中而不是评论这是您应该做的事情,那么可能只是帮助一点,

答案 1 :(得分:0)

输入第二个值时出现错误ReadInt总是将值放在eax中,但你说:

call ReadInt  ; read integer
mov num2, ebx     ; store the value

一定是

call ReadInt  ; read integer
mov num2, eax     ; store the value

答案 2 :(得分:0)

迟到总比没有好:)

TITLE MultiplyTwoNumbers (multiply.asm)

INCLUDE Irvine32.inc

.data

inputValue1st BYTE "Input the 1st integer = ",0
inputValue2nd BYTE "Input the 2nd integer = ",0
outputSumMsg BYTE "The sum of the two integers is = ",0

num1 DD ?
num2 DD ?
sum  DD ?


.code

main PROC

; here we are calling our Procedures

call InputValues
call multiplyValue
call outputValue
call Crlf

exit
main ENDP



InputValues PROC

;----------- For 1st Value--------
; input message

mov edx,OFFSET inputValue1st
call WriteString


call ReadInt    ; read integer
mov num1, eax   ; store the value


 ;-----------For 2nd Value----------

 ; output the prompt message
 mov edx,OFFSET inputValue2nd
 call WriteString


  call ReadInt  ; read integer
  mov num2, eax     ; store the value

  mov eax,0

  ret
  InputValues ENDP



   ;---------multiply----------------

   multiplyValue PROC
   ; compute the sum

    mov eax, num1   ; moves num1 to eax
    imul eax, num2   ; multiplies content in eax with num2 
    mov sum, eax  ; the val is stored in eax


    ret
    multiplyValue ENDP


    ;--------For Sum Output Result----------

    outputValue PROC


    ; output result
    mov edx, OFFSET outputSumMsg
    call WriteString


    mov eax, sum
    call WriteInt ; prints the value in eax
    ret
    outputValue ENDP


    End main