| |

VerySource

 Forgot password?
 Register
Search
View: 1023|Reply: 2

Something went wrong with the compiled program (Let me see it)

[Copy link]

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-18 17:00:01
| Show all posts |Read mode
The program syntax is correct, but the results are incorrect.
.model small
.stack 40h
.data
namepar label byte
maxnlen db 21
namelen db?
namefld db 21 dup (?)
telpar label byte
telmaxlen db 9
tellen db?
telfld db 9 dup (?)
crlf db 13,10, '$'
endaddr dw?
messg1 db 'Input name:', '$'
messg2 db 'Input a telephone number:', '$'
messg3 db 'Do you want a telephone number? (Y / N)', 13,10, '$'
messg4 db 'name?', '$'
messg5 db 'name telphone', 13,10, '$'
namectr db 0
tel_tab db 50 dup (28 dup (''))
namesav db 20 dup (?), 13,10, '$'
telsav db 8 dup (?), 13,10, '$'
na_telsav db 28 dup (?), 13,10, '$'
swapped db 0
; ************************************************ *****************************
.code
begin proc far
      mov ax, @ data
      mov ds, ax
      mov es, ax
      cld
      lea di, tel_tab
   a:
      call input_name
      call inphone
      cmp namelen, 0
      jz a30
      cmp namectr, 50
      je a30
      call stor_name
      call stor_tel
      jmp a
  a30:
      cmp namectr, 1
      jbe a40
      call name_sort
      call println
      call name_search
  a40:
      mov ax, 4c00h
      int 21h
      
; ************************************************ ****************************
input_name proc near
      mov ah, 09
      lea dx, messg1
      int 21h
      mov ah, 0ah
      lea dx, namepar
      int 21h
      mov ah, 09
      lea dx, crlf
      int 21h
      mov bh, 0
      mov bl, namelen
      mov cx, 21
      sub cx, bx
   b: mov namefld [bx], 20h
      inc bx
      loop b
      ret
input_name endp
; ************************************************ *****************************
stor_name proc near
     inc namectr
     cld
     lea si, namefld
     mov cx, 10
     rep movsw
     ret
stor_name endp
; ************************************************ *******************************
inphone proc near
     mov ah, 09
     lea dx, messg2
     int 21h
     mov ah, 0ah
     lea dx, telpar
     int 21h
     mov ah, 09
     lea dx, crlf
     int 21h
     mov bh, 0
     mov bl, tellen
     mov cx, 9
     sub cx, bx
  c: mov telfld [bx], 20h
     inc bx
     loop c
     ret
inphone endp
; ************************************************ **************************************
stor_tel proc near
     cld
     lea si, telfld
     mov cx, 4
     rep movsw
     ret

stor_tel endp
; ************************************************ *************************************
name_sort proc near
     sub di, 48
     mov endaddr, di
 g20:
     mov swapped, 0
     lea si, tel_tab
 g30:
     mov cx, 28
     mov di, si
     add di, 28
     mov ax, di
     mov bx, si
     repe cmpsb
     jbe g40
     call chg
 g40:
     mov si, ax
     cmp si, endaddr
     jbe g30
     cmp swapped, 0
     jnz g20
     ret

name_sort endp
; ************************************************ **************************************
chg proc near
     mov cx, 14
     lea di, na_telsav
     mov si, bx
     rep movsw
     mov cx, 14
     mov di, bx
     rep movsw
     mov cx, 14
     lea si, na_telsav
     rep movsw
     mov swapped, 1
     ret
chg endp
; ************************************************ ***********************************************
name_search proc near
    mov ah, 09
    lea dx, messg3
    int 21h
    mov ah, 01
    int 21h
    cmp al, 'N'
    jz exit
    cmp al, 'n'
    jz exit
    mov ah, 09
    lea dx, messg4
    int 21h
    call input_name
    lea di, tel_tab
comp:
    lea si, namefld
    mov cx, 20
    repz cmpsb
    jz equal
    add di, 8
    jmp comp
equal:
     mov cx, 8
     cld
     mov si, di
     lea di, telsav
     rep movsb
     mov ah, 09
     lea dx, telsav
     int 21h
     
exit:
     mov ax, 4c00h
     int 21h
name_search endp
; ************************************************ **************************************
println proc near
     mov ah, 09
     lea dx, messg5
     int 21h
     lea si, tel_tab
 k20:
     lea di, na_telsav
     mov cx, 14
     rep movsw
     mov ah, 9
     lea dx, na_telsav
     int 21h
     dec namectr
     jnz k20
     ret
println endp
; ************************************************ ***********************************************
end begin
Reply

Use magic Report

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-4-23 19:30:02
| Show all posts
The main result is that the output of the following paragraph is incorrect. I want to find from tel_tab whether there is a person with the same name as I entered. If it exists, her phone number will be output, but the program cannot achieve this effect. Reason, rush to hand in homework, thank you
name_search proc near
    mov ah, 09
    lea dx, mesgg3
    int 21h
    mov ah, 01
    int 21h
    cmp al, 'N'
    jz exit
    cmp al, 'n'
    jz exit
    mov ah, 09
    lea dx, mesgg4
    int 21h
    call input_name
    lea di, tel_tab
comp:
    lea si, namefld
    mov cx, 20
    repz cmpsb
    jz equal
    add di, 8
    jmp comp
equal:
     mov cx, 8
     cld
     mov si, di
     lea di, telsav
     rep movsb
     mov ah, 09
     lea dx, telsav
     int 21h
     
exit:
     mov ax, 4c00h
     int 21h
name_search endp
Reply

Use magic Report

0

Threads

23

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-4-28 17:00:01
| Show all posts
This is because, when searching for name, although the total length of name is 20, the repeat cmpsb does not wait until all 20 bytes have been compared, but terminates once it encounters a different one. So, after repe cmpsb , di does not necessarily point to the end of the name, so that when matching the next record, you can not simply add di, 8. The simple is to save di first, and then restore, the increment is the length of the entire record:
comp:
    push di; * + save di
    lea si, namefld
    mov cx, 20
    repz cmpsb
    pop di; * + resume di points to the beginning of the record
    jz equal
    add di, 28; * points to the start of the next record
    jmp comp
equal:
     mov cx, 8
     cld
     lea si, [di + 20]; * points to the 'number' field of the record
...
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list