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

📄 booth.asm

📁 这是我汇编语言课程设计的一点收获。实现了输入两个8位以内的二进制数
💻 ASM
字号:
data segment
  tip db 'please input decimal fraction within 8 digits or it will end.$'
  A db 'input x ending with Enter x=$'
  B db 'input y ending with Blank y=$'
  C db 'the complement 0f x*y is $'
  D db 'x*y=$'
  x dw 0  ;register the -
  m db 0  ;register the digits of multiplicand - x
  n db 0  ;register the digits of multiplicator - y
data ends
code segment
  assume ds:data,cs:code
  main proc far
start:
  push ds
  mov ax,0
  push ax
 
  mov ax,data
  mov ds,ax
  
  mov bx,0
  mov cx,0
  mov si,0
  mov di,0

  call near ptr input  
  call near ptr complement
  call near ptr xy
  call near ptr outputc
  call near ptr output
l:
 ret
 main endp

 input proc near
   mov ah,09h 
   lea dx,tip
   int 21h 
   
   mov dl,0Dh  ;output CRLF
   mov ah,02h
   int 21h
   mov dl,0Ah
   mov ah,02h
   int 21h
   
   mov ah,09h 
   lea dx,A
   int 21h 
l1:
   mov cl,0    
   mov ah,01h
   int 21h
   cmp al,2Dh  ;the first char compares with -
   jz l2
   cmp al,30h  ;the first char compares with 0
   jz l3   
   jmp l  ;if the first char is not - or 0,end
l2:
   mov x,1  ;the first char is -   
   mov ah,01h
   int 21h
   cmp al,30h
   jz l3   
   jmp l
l3:
   inc cl   
   mov ah,01h
   int 21h
   cmp al,2Eh  ;the char after 0 compares with . 
   jz l4   
   jmp l
l4:
   mov ah,01h
   int 21h
   cmp al,30h
   jz l5
   cmp al,31h
   jz l5   
   jmp l
l5:
   inc cl
   sub al,30h
   shl bl,1
   add bl,al
   
   mov ah,01h
   int 21h
   cmp al,30h
   jz l5
   cmp al,31h
   jz l5
   
   cmp al,0Dh ;x inputing ends with Enter
   jz l6   
   cmp al,20h ;y inputing ends with Blank
   jz l7
   jmp l
l6:
   mov m,cl
   mov si,x   ;register the sign of x in si
   mov x,0
   
   mov bh,bl  ;register x in bh   
   mov bl,0   ;register y in bl
   
   mov dl,0Dh  ;output CRLF
   mov ah,02h
   int 21h
   mov dl,0Ah
   mov ah,02h
   int 21h
   
   mov ah,09h  ;input y
   lea dx,B
   int 21h
   jmp l1
l7:
   mov n,cl
   mov di,x
   
   ret
 input endp
 
 complement proc near
   cmp si,1
   jz l8
   jmp l9
l8:
   mov dh,0  
   mov dh,bh  ;register [-x]'s complement in dh when x is a negative.
   
   neg bh     ;register [x]'s complement in ch when x is a negative.
   mov ch,0
   mov ch,bh
   jmp yc
l9:
   mov ch,0  
   mov ch,bh  ;register [x]'s complement in dh when x is a positive.
   
   neg bh
   mov dh,0
   mov dh,bh  ;register [-x]'s complement in dh when x is a positive.   
   
yc:
   cmp di,0   ;register [y]'s complement in cl
   jz l10
   jmp l11
l10:
   mov cl,0
   mov cl,bl 
   jmp e
l11:
   neg bl
   mov cl,0
   mov cl,bl
e:
   ret
 complement endp
 
 xy proc near
  cmp si,di
  jz posi
  jmp nega
posi:
  mov x,0    ;register the sign of the result
  jmp nex
nega:
  mov x,1
nex:
  mov al,n
  cbw
  mov di,ax  ;register the shifting times in di
  mov ax,0
  mov bx,0

  dec di
  shl cl,1
  mov al,cl

  and al,03h  ;shield the first six digits
  cmp al,2    ;10
  jz a_
  cmp al,0    ;00
  jz b_
a_:
  add bh,dh
  sar bh,1
  rcr bl,1
   
  shr cl,1
  mov al,cl
  dec di   
  jnz lxy
  jmp q
b_:
  add bh,0
  sar bh,1   
  rcr bl,1
   
  shr cl,1
  mov al,cl
  dec di   
  jnz lxy
  jmp q
lxy:
  and al,03h
  cmp al,2  ;10
  jz a_
  cmp al,1  ;01
  jz c_
  jmp b_    ;00 or 11
c_:
  add bh,ch
  sar bh,1
  rcr bl,1
   
  shr cl,1
  mov al,cl
  dec di
   
  jnz lxy
  jmp q
q:
  ret
 xy endp
 
 outputc proc near
  mov dl,0Dh  ;output CRLF
  mov ah,02h
  int 21h
  mov dl,0Ah
  mov ah,02h
  int 21h
   
  mov ah,09h 
  lea dx,C
  int 21h 
   
  mov al,m
  mov cl,al
  add cl,8
  ror bx,cl
  mov si,bx
  mov di,bx
   
  mov al,m
  mov cl,al
  mov al,n
  dec al
  add cl,al
   
  rol si,1  ;output the xy's complement
  mov bx,si
  and bx,1
  add bl,30h
  
  mov dl,bl
  mov ah,02h  
  int 21h

  mov dl,2Eh  ;output a decimal point
  mov ah,02h
  int 21h   
  dec cl 
  jnz om
om:    
  rol si,1
  mov bx,si
  and bx,1
  add bl,30h
  
  mov dl,bl
  mov ah,02h  
  int 21h  
  dec cl 
  jnz om
  
   ret
 outputc endp
 
 output proc near  
  mov dl,0Dh  ;output CRLF
  mov ah,02h
  int 21h
  mov dl,0Ah
  mov ah,02h
  int 21h
   
  mov ah,09h 
  lea dx,D
  int 21h 
  
  mov al,m
  mov cl,al
  mov al,n
  dec al
  add cl,al
  
  cmp x,0
  jz xy1
  jmp xy2
xy1:
  rol di,1  ;output the xy
  mov bx,di
  and bx,1
  add bl,30h
  
  mov dl,bl
  mov ah,02h  
  int 21h

  mov dl,2Eh  ;output a decimal point
  mov ah,02h
  int 21h   
  dec cl 
  jnz om_
om_:    
  rol di,1
  mov bx,di
  and bx,1
  add bl,30h
  
  mov dl,bl
  mov ah,02h  
  int 21h  
  dec cl 
  jnz om_
  jmp o
xy2:
  mov dl,2Dh  ;output a -
  mov ah,02h
  int 21h   
  
  neg di
  rol di,1  ;output the xy
  mov bx,di
  and bx,1
  add bl,30h

  mov dl,bl
  mov ah,02h  
  int 21h

  mov dl,2Eh  ;output a decimal point
  mov ah,02h
  int 21h   
  dec cl 
  jnz oc
oc:    
  rol di,1
  mov bx,di
  and bx,1
  add bl,30h
  
  mov dl,bl
  mov ah,02h  
  int 21h  
  dec cl 
  jnz oc
o:
   ret
 output endp
  
code ends
end start

⌨️ 快捷键说明

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