Demo entry 6678262

123

   

Submitted by anonymous on Dec 05, 2017 at 15:57
Language: Java. Code size: 6.9 kB.

datarea  segment
mess1    db    'Please input name:','$'
mess2    db    'Please input telephone number:','$'
mess3    db    'Do you want to search a telephone number?(y/n)','$'
mess4    db    0dh,0ah,'what is the name?','$'
mess5    db    'Not find',0dh,0ah,'$'
mess6    db    'the number you want to store:','$'
crlf     db     0dh,0ah,'$'  0AH就是换行 0DH就是回车 '$'这个就是表示输入的字符串结束了
stokin1  label  byte
max1      db     21
act1      db     ?
stokn1    db     21 dup(?)
stokin2  label  word
max2      db     9
act2      db     ?
stokn2    db     9 dup(?)
numtable   db     50 dup(28 dup(?))
name_count dw    0
endaddr   dw     ?
swapped   dw     ?
totalnum dw   ?
savenp    db     28 dup(?),0dh,0ah,'$'
searchaddr dw    ?
flag      db     ?
flagb      db     ?
show      db     'name                phone',0dh,0ah,'$'
datarea  ends
;********************************************************************
codesg  segment
   assume ds:datarea,cs:codesg,es:datarea
main    proc    far
       mov ax,datarea
       mov ds,ax
       mov es,ax
       lea di,numtable     ;di must be protected
       lea dx,mess6        ;显示信息请输入想存入的电话号码总数
       mov ah,09        是输出字符串功能但是必须先把字符串的地址送到DX中既LEA DX要输出的字符串名
       int 21h
       mov bx,0
  newchar:                ;这个是参考书上例2.6从键盘接收数字然后转换成ASCII码
       mov ah,1          ;从键盘接收totalnum,并回显AL=输入字符
       int 21h
       sub al,30h         ;ascii to binary
       jl next             ;jump if<0
       cmp al,9            ;is it >9d?
       jg next             ;yes jump
       cbw                 ;byte in AL to word in AX
将A L的最高有效位D7扩展至AH
	   	;(digit is now in AX)
       xchg ax,bx            ;交换
       mov cx,10             ;put 10 dec in CX
       mul cx                  ;number times 10 DX,AX<-(AX)*src
       xchg ax,bx               ;交换
       add bx,ax              ;add digit to number
       jmp newchar                ;get next digit
   next:
       mov totalnum,bx
       lea dx,crlf
       mov ah,09
       int 21h
 a10:                              
       lea dx,mess1                ;显示请输入名字
       mov ah,09
       int 21h
       call input_name       
       inc  name_count            count加1
       call stor_name 
       lea dx,mess2                 ;显示请输入电话
       mov ah,09
       int 21h
       call inphone
       call stor_phone
       cmp  name_count,0
       je  exit
       mov bx,totalnum
       cmp  name_count,bx         ;输入与之前输入总数相等的姓名电话
       jnz  a10
       call name_sort
 a20:
       lea dx,mess3                 ;显示是否需要查找电话号码
       mov ah,09
       int 21h
       mov ah,08                     ;键盘输入无回显检测ctrl-break  Ctrl-C,AL=输入字符
       int 21h
       cmp al,'y'
       jz  a30
       cmp al,'n'
       jz  exit
       jmp a20                          
 a30:
       mov ah,09
       lea dx,mess4             ;显示询问名字
       int 21h
       call input_name
 a40:
       call name_search
       ;call printline
	   ;dec flag
	   ;sub flag,0        ;要是没结束的话
       ;jnz  a40
       jmp a20
 exit:
       mov ax,4c00h            ;;;;带返回码终止AL=子出口码AH=返回代码00=正常终止01=用Ctrl-c终止02=严重设备错误终止03=用功能调用31H终止
       int 21h
 main endp
;--------------------------------------------------------------------
input_name  proc  near
     mov ah,0ah
     lea dx,stokin1
     int 21h
     mov ah,09
     lea dx,crlf
     int 21h
     sub bh,bh
     mov bl,act1
     mov cx,21
     sub cx,bx              ;;dst<-dst-src,cx为计数功能寄存器呀
b10:
     mov stokn1[bx],' '   ;补全空格
     inc bx
     loop b10
; b20:
    ; call name_search
    ; sub flag,0
    ; jz b30
	; lea dx,mess5
    ; mov ah,09
    ; int 21h       
; b30:
    ret
input_name endp
;--------------------------------------------------------------------
stor_name     proc   near
      lea  si,stokn1
      mov  cx,20
      rep  movsb
      ret
stor_name  endp
;--------------------------------------------------------------------
inphone   proc   near
     mov ah,0ah
     lea dx,stokin2
     int 21h
     mov ah,09
     lea dx,crlf
     int 21h
     sub bh,bh
     mov bl,act2
     mov cx,9
     sub cx,bx
c10:
     mov stokn2[bx],' '
     inc bx
     loop c10
     ret 
inphone endp
;--------------------------------------------------------------------
stor_phone  proc near
     lea  si,stokn2
     mov  cx,8
     rep  movsb   ;movs 串传送指令 cmps 串比较操作
     ret
stor_phone endp
;--------------------------------------------------------------------
name_sort  proc near     ;;;;;;;;
     sub  di,28
     mov  endaddr,di
 c1:
     mov  swapped,0
     lea  si,numtable
 c2:
     mov  cx,20
     mov  di,si
     add  di,28
     mov  ax,di
     mov  bx,si   ;cmpsb si-di  movsb di<-si
     repz cmpsb   ;repz 当为0时重复串操作repe 当相等时重复串操作rep 重复串操作直至计数寄存器count reg 的内容为0为止
     jbe  c3     ;CF与ZF=1小于等于则转移
 ;chang order 
     mov si,bx
     lea di,savenp
     mov cx,28
     rep movsb
     mov cx,28
     mov di,bx
     rep movsb
     mov cx,28
     lea si,savenp
     rep movsb
     mov swapped,1
 c3:
     mov  si,ax
     cmp  si,endaddr
     jb   c2        ;CF=1则转移小于等于则转移
     cmp  swapped,0
     jnz  c1    ;结果不为0则转移
     ret
name_sort endp
;--------------------------------------------------------------------
name_search proc near
      lea  bx,numtable
	  mov  flag,0      ;清零
	  ;mov  flagb,0  
   d: 
      ;mov  flag,0      ;flag清零
	   ;mov  flagb,0  
      mov  cx,20
	  lea si,stokn1
      mov  di,bx
      repz cmpsb      如果ds:si和es:di所指向的两个字节相等则继续比较
所以如果不相等的话就停止循环但是这时候si和di已经自动加1了如果要找不相等的那两个数就要把si和di减1
      jz  d2
      ;jb  dexit
      add bx,28            ;下一条
      cmp  bx,endaddr   
      jbe  d             ;未结束继续找
	  ;add flagb,flag
	  sub flag,0  ;要是没有找到的话
       jz  nof
    jmp  dexit         ;结束退出
 nof:  lea dx,mess5
       mov ah,09
       int 21h 
  d2:
      mov searchaddr,bx
      ;mov flag,1         ;标志找到了
	  inc flag
	  call printline
	  ; dec flag
	   ;sub flag,0  ;要是没结束的话
	   add bx,28            ;下一条
      cmp  bx,endaddr   
      jbe  d             ;未结束继续找
      jmp  dexit         ;结束退出
       jnz  d
 dexit:
        ret
name_search endp
;--------------------------------------------------------------------
printline proc  near
       sub flag,0  ;要是没有找到的话
       jz  no
 p10:
       mov ah,09
       lea dx,show
       int 21h
       mov cx,28
       mov si,searchaddr
       lea di,savenp
       rep movsb      ESI 所指地址的ECX个字节搬移到以EDI 所指的地址开头的等长内存里头
       lea dx,savenp
       mov ah,09
       int 21h
       jmp fexit
no:    lea dx,mess5
       mov ah,09
       int 21h 
fexit:  
       ret
printline endp
;--------------------------------------------------------------------
codesg ends
;--------------------------------------------------------------------
end main       

This snippet took 0.02 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).