分享一道西电微机实验汇编题,肝了几个小时,写得也不怎么样


编写Q=a+(b-c)*d的程序。(abcd0-9间的正整数)要求:abcd均从键盘输入,计算结果在虚拟终端上显示。

data segment

    str1 DB 'PLEASE INPUT A NUMBER TO a:$'

    str2 DB 'PLEASE INPUT A NUMBER TO b:$'

    str3 DB 'PLEASE INPUT A NUMBER TO c:$'

    str4 DB 'PLEASE INPUT A NUMBER TO d:$'

    str5 DB 'The answer is:Q=a+(b-c)*d=$'

    fuhao db '-$'

    a DB 0

    b DB 0

    c DB 0

    d DB 0

    Q db 0

    

    pkey db "press any key...$"

ends

 

stack segment

    dw   128  dup(0)

ends

 

code segment

main proc far

    ASSUME CS:CODE,DS:DATA,SS:STACK

start:

    MOV AX, DATA

    MOV DS, AX

    MOV ES, AX

   

    LEA DX,str1

    MOV AH,9

    INT 21H

    CALL input

    mov a,bl

         

    LEA DX,str2

    MOV AH,9

    int 21h

    CALL input

    mov b,bl

    

    LEA DX,str3

    MOV AH,9

    INT 21H

    call input

    mov c,bl

    

    LEA DX,str4

    MOV AH,9

    INT 21H

    call input

    mov d,bl

    

    lea dx,str5

    mov ah,9

    int 21h

     

    mov ax,0

    mov bx,0

    mov al,b

    mov bl,c

    cmp al,c

    jna calculator

    jmp normal

    calculator:

        sub bl,al

        mov al,d

        mul bl

        mov bl,a

        cmp bl,al

        jna buzhidao

        jmp natural

        buzhidao:

            sub al,bl

            cmp al,0

            je printling

            mov Q,al

            mov bx,0ah

            mov cx,0

            lea dx,fuhao

            mov ah,9

            int 21h

            mov ax,0

            mov al,Q

            jmp trans

        natural:

            sub bl,al

            mov al,bl

            mov bx,0ah

            mov cx,0

            jmp trans

normal:

    sub al,bl    

    mov bl,d

    mul bl

    mov bl,a

    add al,bl

    mov bx,0ah

    mov cx,0

    jmp trans

 

trans:

    mov dx,0

    div bx

    push dx

    inc cx

    cmp ax,0

    je print

    cwd

    jmp trans

print:

    pop dx

    add dl,30h

    mov ah,2h

    int 21h

loop print

    HLT

printling:

    mov dl,0

    add dl,30h

    mov ah,2h

    int 21h

;退出操作

    mov ah,2

    mov dl,10

    int 21h

    lea dx,pkey

    mov ah,9

    int 21h

    mov ah,1

    int 21h

    mov ax,4c00h

    int 21h

        

    ret

        

main endp

input proc

    mov bx,0

    mov ah,1       

    int 21h

    cmp al,0dh

    je exit

    sub al,30h     

    mov bl,al

    jmp exit

    exit:

        call crlf

    ret

input endp

 

crlf proc near

     mov dl,0ah

     mov ah,2h

     int 21h

     mov dl,0dh

     mov ah,2h

     int 21h

     ret

crlf endp   

ends

 

end start