2013-04-19 4 views
0

Я умножаю два значения ввода из окна консоли. Я использую 32-разрядные регистры eax, ebx, но это не умножение значений. Программа работает, но она не умножается. Может ли кто-нибудь обнаружить проблему? Что не так в этом коде? Я использую KIP.R.IRVINE Link Libraries на ассемблере.Умножить 2 значения в языке сборки 8086?

Вот код:

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 

Еще один вопрос: Нужно ли мне использовать флаг переноса в нем? Если да, то каков будет код для него?

+0

комментарий; num1 * num2 = 6 * 2 в умножении PROC - пример –

+0

Вы ожидаете, что второй вызов 'ReadInt' вернет значение в' ebx'. Я предполагаю, что возвращаемое значение фактически находится в 'eax'. – Michael

+0

Получил отладчик? –

ответ

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

Может только немного помочь, если вы на самом деле загрузить значения в регистрах, а не комментарий, что это то, что вы должны делать,

+0

его ошибочно сделанный мной, когда я отправлял вопрос, если я прокомментирую эту инструкцию mov eax, num1; перемещает num1 в eax mov ebx, num2, то также он не работает –

+0

если я удалю комментарий, то и он не работает извините за неудобства ... я написал его ошибочно .. –

0

у вас есть ошибка при вводе второго значения ReadInt всегда ставит значения в EAX, но вы говорите:

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

должно быть

call ReadInt ; read integer 
mov num2, eax  ; store the value 
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 

 Смежные вопросы

  • Нет связанных вопросов^_^