我正确使用源索引(si)吗?

时间:2014-03-30 04:42:50

标签: assembly x86-16

这是一堂课。本实验的目的是让用户输入M / N形式的一小部分,其中M

;       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功能         int 21h;结束计划

0 个答案:

没有答案