2017-04-03 7 views
0

私は、ユーザから2つの入力を受け取り、それらを乗算したコードを持っています。ご覧のとおり、下記の通りです。プロシージャ内のコードを分割する

私は物事を別々の手順に分割して、最後にそれらをすべて呼び出そうとしました。

私は何をしたかについていくつか質問がありますが、各getValueプロシージャの最初の比較の後、私は次の比較にジャンプする必要があることを理解しましたが、2回目の比較の後にどこにジャンプするのかわかりませんでした。

2番目の比較の後に次の手順の開始にジャンプするのが理にかなっていますか、または単に戻りまたは終了手順のステートメントにジャンプする必要がありますか?

同じことをする2つの別々のプロシージャを呼び出すのではなく、ただ1つのgetValueプロシージャを用意して、最後に2回コールするのが理にかなっているかどうかについて、

それは正常に構築されていると言いますが、私が実行すると「何かボタンを押して続ける...」というだけで、コードが出てくるのではなく、そのことが分かりません。

INCLUDE Irvine32.inc 
.data 
    intVal1 SDWORD ? ; User input one 
    intVal2 SDWORD ? ; User input two 
    prompt BYTE "The result of multiplying the numbers is ",0 
    prompt2 BYTE "Enter a number that will be multiplied",0 
    prompt3 BYTE "Error. Number not in range.",0 

.code 

; Error procedure displays error prompt 
error PROC 
    mov edx, OFFSET prompt3 
    call WriteString 
ret 
error ENDP 

; GetValue1 procedure will get first input from user and display error  and end program when input not in range 
GetValue1 PROC 
    mov edx, OFFSET prompt2 
    call WriteString ; tells the user to enter a number 
    call ReadInt 
    mov intVal1,eax  ; save the returned value from eax to intVal1 
    cmp intVal1, 32767 
    jl Loop1  ; if intVal1 is less than 32767 jump to Loop1, otherwise continue with error procedure 
    call error 
    jmp end 
    Loop1: cmp intVal1, -32768 
    jg Loop2   ; if intVal1 is greater than -32768 jump to Loop2, otherwise continue with error procedure 
    call error 
    jmp end 
    ret 
GetValue1 ENDP 

; GetValue2 procedure will do the same thing as GetValue1 
GetValue2 PROC 
    Loop2: mov edx, OFFSET prompt2 
    call WriteString 
    call ReadInt 
    mov intVal2,eax 
    cmp intVal1, 32767 
    jl Loop3  ; if intVal1 is less than 32767 jump to Loop3, otherwise  continue with error procedure 
    call error 
    jmp end 
    Loop3: cmp intVal1, -32768 
    jg Loop4  ; if intVal1 is greater than -32768 jump to Loop4, otherwise continue with error procedure 
    call error 
    jmp end 
    ret 
GetValue2 ENDP 

; MultiplyAndDisplay will multiply the inputs and display the result along with a prompt 
MultiplyAndDisplay PROC 
    Loop4: imul eax, intVal1  ; signed multiply of eax by intVal1     
    mov edx, OFFSET prompt 
    call WriteString  ; Writes the prompt in edx 
    call WriteDec   ; Writes the value in eax 
    ret 
MultiplyAndDisplay ENDP 

main PROC 
    call GetValue1 
    call GetValue2 
    call MultiplyAndDisplay 
    exit 
main ENDP 
END main 
+0

質問に詳細を加えなかった文章を削除しました。読みやすくするために段落区切りが追加されました。 – Dijkgraaf

答えて

0

単一の手順を使用して値を取得します。プロシージャにeaxの値を返します。あるプロシージャから別のプロシージャにジャンプするジャンプを使用しないでください。メインコードは次のとおりです:

main PROC 
    call GetValue   ;eax == first value 
    push eax     ;save first value 
    call GetValue   ;eax == second value 
    pop ebx     ;ebx == first value 
    call MultiplyAndDisplay ;change this to multiply eax by ebx 
    exit 
main ENDP 
+0

なぜ単に両方の値を押して、最後の2つの要素をプッシュするために 'MultiplyAndDisplay'を変更するのはなぜですか? – Tommylee2k

+0

@ Tommylee2k - 本当ですが、私は元のコードに厳密に従おうとしていました。 – rcgldr

関連する問題