这是一堂课 . 本实验的目标是让用户输入M / N形式的一小部分,其中M <N并将扩展打印到6位小数 . 在阅读并运行了几次之后,似乎在进行算术运算时我没有得到数字 . 所以,我假设当我尝试访问它们时,我的源索引没有指向数字 . 我只想知道我的逻辑是否有偏差 . 代码列在下面并编译 . 我正在使用dosbox .
; get two numbers from user and divide them
org 100h
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
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
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
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
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
mov dl, 46 ; put in . to print
mov ah, 2 ; print func
int 21h ; print period
mov cx, 10 ; set up loop counter
divide:
xor ax, ax ; clear register
xor bx, bx ; clear register
mov al, 10 ; get ready to multiply
mov bl, [M] ; get ready to multiply
mul bl ; multiply, result in al
mov bl, [N] ; get ready to divide
div bl ; divide bl with al
mov dl, al ; store result to dl
mov [M], ah ; store remainder in M to divide again
add dl, 48 ; convert back to decimal
mov ah, 2 ; print out function
int 21h ; print it
loop divide ; loop 10 times
endProgram:mov ax,4C00h;结束dos函数21h;结束计划