⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 str_sigh_second_minus_expression.asm

📁 汇编语言下
💻 ASM
字号:
.model small
.stack
.data
str1 db 'Please input a expression(eg:A+B):','$'
str2 db 0dh,0ah,'Result:','$'
str3 db 0dh,0ah,'Mod:','$'
buffer db 20
       db ?
       db 20 dup(?)
.code
start:mov dx,@data
      mov ds,dx
      mov ah,09h
      mov dx,offset str1
      int 21h
      mov ah,0ah
      mov dx,offset buffer
      int 21h
call get_expression
      mov ah,4ch
      int 21h

get_expression proc
mov si,offset buffer+2
call get_two_num_10
mov ax,di
cmp cl,'+'
jz add1
cmp cl,'-'
jz sub1
cmp cl,'*'
jz mul1
cmp cl,'/'
jz div1
add1:add ax,bx
     jmp sm2
sub1:sub ax,bx
     jmp sm2
mul1:xor dx,dx
     imul bx
     push ax
     push dx
     mov ah,09h
     mov dx,offset str2
     int 21h
     pop dx
     or dx,dx
     jz sm3
     mov ax,dx
     call disp_reg_sax_10
sm3:pop ax
    call disp_reg_sax_10
    ret
div1:xor dx,dx
     idiv bx
     push dx
     push ax
     mov ah,09h
     mov dx,offset str2
     int 21h
     pop ax
     call disp_reg_sax_10
     mov ah,09h
     mov dx,offset str3
     int 21h
     pop dx
     mov ax,dx
     call disp_reg_sax_10
     ret
sm2:push ax
    mov ah,09h
    mov dx,offset str2
    int 21h
    pop ax
                                         ;test ax,8000h
                                         ;jnz sm9
                                           ;call disp_reg_sax_10
                                               ;retsm9:
                                                 ;neg ax
    call disp_reg_sax_10
    ret
get_expression endp

get_two_num_10 proc
     push dx
     xor cx,cx
 sm4:xor bx,bx
     cld
     lodsb
     cmp al,'-'
     jnz sm8
     mov ch,1
nextget:lodsb
 cmp al,'+'
     jz sm5
 cmp al,'-'
     jz sm5
 cmp al,'*'
     jz sm5
 cmp al,'/'
     jz sm5
     cmp al,'0'
     jb sm6
     cmp al,'9'
     ja sm6
 sm8:sub al,30h
     shl bx,1
     mov dx,bx
     shl bx,1
     shl bx,1
     add bx,dx
     xor ah,ah
     add bx,ax
     jmp nextget
sm6:cmp ch,0
     jz sm7
     neg bx
sm7: pop dx
     ret
sm5:mov cl,al
    mov di,bx
    jmp sm4
get_two_num_10 endp


disp_reg_sax_10 proc
     test ax,8000h
     jnz sign
call disp_reg_ax_10 
     ret
sign:push ax
     mov ah,02h
     mov dl,'-'
     int 21h
     pop ax
     neg ax
     call disp_reg_ax_10 
     ret
disp_reg_sax_10 endp

disp_reg_ax_10   proc
     mov di,10000
     mov cx,10
next:mov dx,0
     div di
     xchg ax,dx
call disp_char
     xchg ax,di
     mov dx,0
     div cx
     xchg ax,di
     or di,di
     jnz next
     ret
disp_reg_ax_10  endp

disp_char  proc
     push ax
     push dx
    add dl,30h
    cmp dl,39h
    jbe not_add
    add dl,7
not_add:mov ah,2
        int 21h
        pop dx
        pop ax
        ret
disp_char   endp

   end start

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -