这是一堂课。本实验的目的是让用户输入M / N形式的一小部分,其中M section .data
numOneMsg db "Enter first number: ", "$"
numTwoMsg db "Enter second number: ", "$"
resultMsg db "The answer is: ", "$"
tmp: dw " "
M: dw " "
N: dw " "
section .text
xor bx, bx ; clear out bx
xor ax, ax ; clear out ax firstNum:
mov ah, 1 ; read in char func
int 21h ; read in char
cmp al, 0Dh ; did they git CR?
je preSecNum ; set up division
sub al, 48 ; convert to binary
mov [tmp], al ; store value to temp
mov al, 10 ; get ready to multiply to make number
mov bl, [M] ; get ready to multiply to make number
mul bl ; multiply
add al, [tmp] ; add to make new number
mov [M], al ; store value
loop firstNum ; do this over to increase number for input preSecNum:
mov dx, numTwoMsg ; print message for second number
mov ah, 9 ; print func
int 21h ; print out secondNum:
mov ah, 1 ; get second number
int 21h ; read it in
cmp al, 0Dh ; did they hit CR?
je preDiv ; jmp if they hit CR
sub al, 48 ; convert to binary
mov [tmp], al ; store to temp
mov al, 10 ; get ready to multiply
mov bl, [N] ; get ready to multiply
mul bl ; multiply to get increase number
add al, [tmp] ; add to get correct inputed number
mov [N], al ; store number
loop secondNum ; loop to get entire number preDiv:
mov dx, resultMsg ; print result message
mov ah, 9 ; print func
int 21h ; print it divide:
xor ax, ax ; clear register
xor bx, bx ; clear register endProgram:
mov ax,4C00h;结束dos功能
int 21h;结束计划
; get two numbers from user and divide them
org 100h
mov dx, numOneMsg
mov ah, 9
int 21h
mov ah, 1 ; read in char func
int 21h ; read in char
cmp al, 0Dh ; did they hit CR?
je secondNum ; get the second number
sub al, 48 ; convert to binary
mov [M], al
mov cx, 4 ; loop 5 times max
mov ah, 1 ; read in char func
int 21h ; read in char
cmp al, 0Dh ; did they hit CR?
je secondNum
sub al, 48 ; convert to binary
mov [N], al ; store value
mov cx, 4 ; set up loop counter
mov dl, 46 ; put in . to print
mov ah, 2 ; print func
int 21h ; print period
mov cx, 10 ; set up loop counter