دنبال کننده ها

۱۳۹۷ فروردین ۱۹, یکشنبه

dosbox - entering two numbers and multiplying and dividing them on NASM

[ad_1]



good evening everyone. I've been working on this code where the user will input two numbers and they will be multiplied and divided and show the results. I am using procedures to separate the processes. My question is: somehow if I only do the multiplication the program will end and everything will be clear. If I call both procedures the program seems to stay right after the multiplication call and won't go any further. (lets say 10 and 2. expected multiplication is 20 and quotient 5 with 0 remainer, or 12 and 5 where multiplication is 60 and division is 2 remainder 2) Maybe my logic might be wrong or my procedure calls are wrong but I would like to ask if anyone could lend me another pair of eyes so I can learn where my mistake might be. Thanks!!



this is done for NASM on DosBox 0.74



; Input: Requests two integers from the user.
; Output: Outputs the multiplication and division of the input integers.

%include "io.mac"
.STACK 100H
.DATA
prompt_msg1 db "Please input the first number: ",0
prompt_msg2 db "Please input second number: ",0
mul_msg db "multiplication N1 * N2 is: ",0
div_msg db "Division N1/N2 is: ", 0
rem_msg db "Remainder N1/N2 is: ", 0

.CODE
.STARTUP
PutStr prompt_msg1 ; request first number
GetInt CX ; CX = first number
nwln

PutStr prompt_msg2 ; request second number
GetInt DX ; DX = second number
nwln


;multiplication call
call multi ; returns multiplication in BX
PutStr mul_msg ; display multiplication message
PutInt AX ; display multiplication result


;division call
call divis ; returns division in BX
PutStr div_msg ; display Division message
PutInt BX ; display quotient result
nwln
PutStr rem_msg ; display remainder message
PutInt DX ; display remainder result

done:
.EXIT

multi:
mov AX, CX ; imul= first number
imul AX, DX ; imul = imul * second number
ret ; return

divis:
mov BX, CX
div DX ; idiv = first number / second number
ret ; return



[ad_2]

لینک منبع