Устранение ошибок - Assembler

Узнай цену своей работы

Формулировка задачи:

Пишу программу на асм, но не могу воспроизвести из-за ошибок. их много, но в основном однотипные. может, кто-то сможет помочь в устранении или подсказать, где искать. Код:
;.386
model small
;include    add_mac.inc ; Макросы
;include    add_proc.inc    ; Процедуры
.data
menu_title      db      'Menu:$'
    menu_a          db  'Enter (A) matrica$'
    menu_b          db  'Enter (B) matrica$'
    menu_add        db      'A(d)d matrica$'
    menu_mult       db  '(M)ultiply matrica$'
    menu_quit       db  '(Q)uit$'
    menu_help       db  'Press key in ()$'
    str_enter_el        db  'Enter elements$'
    str_el_1        db  '[$'
    str_el_2        db  ',$'
    str_el_3        db  ']: $'
    str_probel      db  '  $'
matrica struc
    M_one_one   db  0
    M_one_two   db  0
    M_one_three db  0
    M_one_four  db  0
    M_two_one   db  0
    M_two_two   db  0
    M_two_three db  0
    M_two_four  db  0
    M_three_one db  0
    M_three_two db  0
    M_three_three   db  0
    M_three_four    db  0
matrica ends
    A matrica <>
    B matrica <>
    C matrica <>
    stroki  db  0
    el_str  db  5, ?, 5 dup(?)
.stack 100h
.code
start:
writeln macro
    push dx
    push ax
    mov ah,2
    mov dl,13
    int 21h
    mov dl,10
    int 21h
    pop ax
    pop dx
endm
write macro string
    push ax
    push dx
    mov ah,09h
    mov dx,offset string
    int 21h
    pop dx
    pop ax
endm
read macro string
    push ax
    push dx
    mov ah,0Ah
    mov dx,offset string
    int 21h
    pop dx
    pop ax
endm
exit macro
    mov al,0
    mov ah,4Ch
    int 21h
endm
clrscr macro
    push ax
    push bx
    push cx
    push dx
    mov ax,0600h
    mov bh,07h
    xor cx,cx
    mov dh,24
    mov dl,80
    int 10h
    mov ah,0fh
    int 10h
    mov dx,0101h
    mov ah,2
    int 10h
    pop dx
    pop cx
    pop bx
    pop ax
endm
readkey macro registr
    push ax
    mov ah,10h
    int 16h
    mov registr,ax
    pop ax
endm
probel macro
    push ax
    mov ah,02h
    mov dl,' '
    int 21h
    pop ax
endm
num_rasp macro
    push bx
    xor cx,cx
    mov si,0
    mov cl, byte ptr di[1]
    mov bx,2
    mov dx,1
    cmp cx,1
    je lop
    dec cx
pod:    
    imul dx,10
    loop pod
    mov cl, byte ptr di[1]
lop:
    xor ax,ax
    mov al, byte ptr di[bx]
    inc bx
    sbb al,'0'
    imul ax,dx
    push cx
    push ax
    mov ax,dx
    mov cx,10
    push dx
    xor dx,dx
    idiv cx
    pop dx
    mov dx,ax
    pop ax
    pop cx
    add si,ax
    loop lop
    pop bx
endm
print_menu macro
    clrscr
    write menu_title
    writeln
    write menu_a
    writeln
    write menu_b
    writeln
    write menu_add
    writeln
    write menu_mult
    writeln
    write menu_quit
    writeln
    writeln
    write menu_help
    writeln
endm
print_num macro registr
    push ax
    push dx
    mov dx,registr
    add dl,'0'
    mov ah,02h
    int 21h
    pop dx
    pop ax
endm
enter_matrica proc
    clrscr
    write str_enter_el
    writeln
    writeln
    mov bx,dx
    mov cx,11
    mov di,0    ;stroki
    mov si,0    ;stolbzy
    mov stroki,1
get_elements:
    write str_el_1
    push dx
    xor dx,dx
    mov dl, stroki
    print_num dx
    pop dx
    write str_el_2
    inc si
    print_num si
    dec si
    write str_el_3
    mov ah,0Ah
    mov dx,offset el_str
    int 21h
    push di
    push si
    mov di,dx
    num_rasp
    mov ax,si
    cmp ax,255
    jge get_elements
    pop si
    pop di
    add bx,di 
    mov [bx+si],al
    sub bx,di
    inc si
    cmp si,4
    jne skip_this
        add di,4
        mov si,0
        inc stroki
    skip_this:
    writeln
    cmp di,12
    jne get_elements
    ret
endp
add_matrica proc
    mov bx,0
    mov cx,12
step_1:
    mov al, byte ptr A[bx]
    mov byte ptr C[bx], al
    inc bx
    loop step_1
    mov bx,0
    mov cx,12
step_2:
    mov al, byte ptr B[bx]
    add byte ptr C[bx], al
    inc bx
    loop step_2
    ret
endp
writenum macro numb
    mov ah,02h
    mov dl,numb
    add dl,'0'
    int 21h
endm
print_c_matrica proc
    clrscr
    writeln
    writenum C.M_one_one
    write str_probel
    writenum C.M_one_two
    write str_probel
    writenum C.M_one_three
    write str_probel
    writenum C.M_one_four
    writeln
    writeln
    writenum C.M_two_one
    write str_probel
    writenum C.M_two_two
    write str_probel
    writenum C.M_two_three
    write str_probel
    writenum C.M_two_four
    writeln
    writeln
    writenum C.M_three_one
    write str_probel
    writenum C.M_three_two
    write str_probel
    writenum C.M_three_three
    write str_probel
    writenum C.M_three_four
    write str_probel
    ret
endp
start:
    mov ax,@data
    mov ds,ax
;-------------
what_to_do:
    print_menu
    readkey dx
    cmp dl,'a'
    je enter_a
    cmp dl,'b'
    je enter_b
    cmp dl,'d'
    je add_mat
    cmp dl,'m'
    je mult_mat
    cmp dl,'q'
    je quit
    jmp what_to_do
enter_a:
    mov dx,offset A
    call enter_matrica
    jmp what_to_do
enter_b:
    mov dx,offset B
    call enter_matrica
    jmp what_to_do
add_mat:
    call add_matrix 
    call print_c_matrica
    readkey ax
    jmp what_to_do
mult_mat:
    call mult_matrica
    jmp what_to_do
quit:
    exit
writeln macro
    push dx
    push ax
    mov ah,2
    mov dl,13
    int 21h
    mov dl,10
    int 21h
    pop ax
    pop dx
endm
write macro string
    push ax
    push dx
    mov ah,09h
    mov dx,offset string
    int 21h
    pop dx
    pop ax
endm
read macro string
    push ax
    push dx
    mov ah,0Ah
    mov dx,offset string
    int 21h
    pop dx
    pop ax
endm
exit macro
    mov al,0
    mov ah,4Ch
    int 21h
endm
clrscr macro
    push ax
    push bx
    push cx
    push dx
    mov ax,0600h
    mov bh,07h
    xor cx,cx
    mov dh,24
    mov dl,80
    int 10h
    mov ah,0fh
    int 10h
    mov dx,0101h
    mov ah,2
    int 10h
    pop dx
    pop cx
    pop bx
    pop ax
endm
readkey macro registr
    push ax
    mov ah,10h
    int 16h
    mov registr,ax
    pop ax
endm
probel macro
    push ax
    mov ah,02h
    mov dl,' '
    int 21h
    pop ax
endm
num_rasp macro
    push bx
    xor cx,cx
    mov si,0
    mov cl, byte ptr di[1]
    mov bx,2
    mov dx,1
    cmp cx,1
    je lop
    dec cx
pod:    
    imul dx,10
    loop pod
    mov cl, byte ptr di[1]
lop:
    xor ax,ax
    mov al, byte ptr di[bx]
    inc bx
    sbb al,'0'
    imul ax,dx
    push cx
    push ax
    mov ax,dx
    mov cx,10
    push dx
    xor dx,dx
    idiv cx
    pop dx
    mov dx,ax
    pop ax
    pop cx
    add si,ax
    loop lop
    pop bx
endm
print_menu macro
    clrscr
    write menu_title
    writeln
    write menu_a
    writeln
    write menu_b
    writeln
    write menu_add
    writeln
    write menu_mult
    writeln
    write menu_quit
    writeln
    writeln
    write menu_help
    writeln
endm
print_num macro registr
    push ax
    push dx
    mov dx,registr
    add dl,'0'
    mov ah,02h
    int 21h
    pop dx
    pop ax
endm
enter_matrica proc
    clrscr
    write str_enter_el
    writeln
    writeln
    mov bx,dx
    mov cx,11
    mov di,0    ;stroki
    mov si,0    ;stolbzy
    mov stroki,1
get_elements:
    write str_el_1
    push dx
    xor dx,dx
    mov dl, stroki
    print_num dx
    pop dx
    write str_el_2
    inc si
    print_num si
    dec si
    write str_el_3
    mov ah,0Ah
    mov dx,offset el_str
    int 21h
    push di
    push si
    mov di,dx
    num_rasp
    mov ax,si
    cmp ax,255
    jge get_elements
    pop si
    pop di
    add bx,di 
    mov [bx+si],al
    sub bx,di
    inc si
    cmp si,4
    jne skip_this
        add di,4
        mov si,0
        inc stroki
    skip_this:
    writeln
    cmp di,12
    jne get_elements
    ret
endp
add_matrica proc
    mov bx,0
    mov cx,12
step_1:
    mov al, byte ptr A[bx]
    mov byte ptr C[bx], al
    inc bx
    loop step_1
    mov bx,0
    mov cx,12
step_2:
    mov al, byte ptr B[bx]
    add byte ptr C[bx], al
    inc bx
    loop step_2
    ret
endp
        writenum macro numb
    mov ah,02h
    mov dl,numb
    add dl,'0'
    int 21h
endm
print_c_matrica proc
    clrscr
    writeln
    writenum C.M_one_one
    write str_probel
    writenum C.M_one_two
    write str_probel
    writenum C.M_one_three
    write str_probel
    writenum C.M_one_four
    writeln
    writeln
    writenum C.M_two_one
    write str_probel
    writenum C.M_two_two
    write str_probel
    writenum C.M_two_three
    write str_probel
    writenum C.M_two_four
    writeln
    writeln
    writenum C.M_three_one
    write str_probel
    writenum C.M_three_two
    write str_probel
    writenum C.M_three_three
    write str_probel
    writenum C.M_three_four
    write str_probel
    ret
endp
        start:
    mov ax,@data
    mov ds,ax
;-------------
what_to_do:
    print_menu
    readkey dx
    cmp dl,'a'
    je enter_a
    cmp dl,'b'
    je enter_b
    cmp dl,'d'
    je add_mat
    cmp dl,'m'
    je mult_mat
    cmp dl,'q'
    je quit
    jmp what_to_do
enter_a:
    mov dx,offset A
    call enter_matrica
    jmp what_to_do
enter_b:
    mov dx,offset B
    call enter_matrica
    jmp what_to_do
add_mat:
    call add_matrica    
    call print_c_matrica
    readkey ax
    jmp what_to_do
mult_mat:
;   call mult_matrica
    jmp what_to_do
quit:
    exit
end start

Решение задачи: «Устранение ошибок»

textual
Листинг программы
.386
model small
;include    add_mac.inc ; Макросы
;include    add_proc.inc    ; Процедуры
.data
menu_title      db      'Menu:$'
    menu_a          db  'Enter (A) matrica$'
    menu_b          db  'Enter (B) matrica$'
    menu_add        db      'A(d)d matrica$'
    menu_mult       db  '(M)ultiply matrica$'
    menu_quit       db  '(Q)uit$'
    menu_help       db  'Press key in ()$'
    str_enter_el        db  'Enter elements$'
    str_el_1        db  '[$'
    str_el_2        db  ',$'
    str_el_3        db  ']: $'
    str_probel      db  '  $'
matrica struc; создаем структуру матрицы
    M_one_one   db  0
    M_one_two   db  0
    M_one_three db  0
    M_one_four  db  0
    M_two_one   db  0
    M_two_two   db  0
    M_two_three db  0
    M_two_four  db  0
    M_three_one db  0
    M_three_two db  0
    M_three_three   db  0
    M_three_four    db  0
matrica ends
    A matrica <> ; матрицы, в которых будем использовать данную структуру
    B matrica <>
    C matrica <>
    stroki  db  0
    el_str  db  5, ?, 5 dup(?)
.stack 100h
.code
start:
writeln macro
    push dx
    push ax
    mov ah,2
    mov dl,13
    int 21h
    mov dl,10
    int 21h
    pop ax
    pop dx
endm
write macro string
    push ax
    push dx
    mov ah,09h
    mov dx,offset string
    int 21h
    pop dx
    pop ax
endm
read macro string
    push ax
    push dx
    mov ah,0Ah
    mov dx,offset string
    int 21h
    pop dx
    pop ax
endm
exit macro
    mov al,0
    mov ah,4Ch
    int 21h
endm
clrscr macro
    push ax
    push bx
    push cx
    push dx
    mov ax,0600h
    mov bh,07h
    xor cx,cx
    mov dh,24
    mov dl,80
    int 10h
    mov ah,0fh
    int 10h
    mov dx,0101h
    mov ah,2
    int 10h
    pop dx
    pop cx
    pop bx
    pop ax
endm
readkey macro registr
    push ax
    mov ah,10h
    int 16h
    mov registr,ax
    pop ax
endm
probel macro
    push ax
    mov ah,02h
    mov dl,' '
    int 21h
    pop ax
endm
num_rasp macro
    push bx
    xor cx,cx
    mov si,0
    mov cl, byte ptr di[1]
    mov bx,2
    mov dx,1
    cmp cx,1
    je lop
    dec cx
pod:    
    imul dx,10
    loop pod
    mov cl, byte ptr di[1]
lop:
    xor ax,ax
    mov al, byte ptr di[bx]
    inc bx
    sbb al,'0'
    imul ax,dx
    push cx
    push ax
    mov ax,dx
    mov cx,10
    push dx
    xor dx,dx
    idiv cx
    pop dx
    mov dx,ax
    pop ax
    pop cx
    add si,ax
    loop lop
    pop bx
endm
print_menu macro
    clrscr
    write menu_title
    writeln
    write menu_a
    writeln
    write menu_b
    writeln
    write menu_add
    writeln
    write menu_mult
    writeln
    write menu_quit
    writeln
    writeln
    write menu_help
    writeln
endm
print_num macro registr
    push ax
    push dx
    mov dx,registr
    add dl,'0'
    mov ah,02h
    int 21h
    pop dx
    pop ax
endm
enter_matrica proc
    clrscr
    write str_enter_el
    writeln
    writeln
    mov bx,dx
    mov cx,11
    mov di,0    ;stroki
    mov si,0    ;stolbzy
    mov stroki,1
get_elements:
    write str_el_1
    push dx
    xor dx,dx
    mov dl, stroki
    print_num dx
    pop dx
    write str_el_2
    inc si
    print_num si
    dec si
    write str_el_3
    mov ah,0Ah
    mov dx,offset el_str
    int 21h
    push di
    push si
    mov di,dx
    num_rasp
    mov ax,si
    cmp ax,255
    jge get_elements
    pop si
    pop di
    add bx,di 
    mov [bx+si],al
    sub bx,di
    inc si
    cmp si,4
    jne skip_this
        add di,4
        mov si,0
        inc stroki
    skip_this:
    writeln
    cmp di,12
    jne get_elements
    ret
endp
add_matrica proc
    mov bx,0
    mov cx,12
step_1:
    mov al, byte ptr A[bx]
    mov byte ptr C[bx], al
    inc bx
    loop step_1
    mov bx,0
    mov cx,12
step_2:
    mov al, byte ptr B[bx]
    add byte ptr C[bx], al
    inc bx
    loop step_2
    ret
                    endp
writenum macro numb
    mov ah,02h
    mov dl,numb
    add dl,'0'
    int 21h
endm
print_c_matrica proc
    clrscr
    writeln
    writenum C.M_one_one
    write str_probel
    writenum C.M_one_two
    write str_probel
    writenum C.M_one_three
    write str_probel
    writenum C.M_one_four
    writeln
    writeln
    writenum C.M_two_one
    write str_probel
    writenum C.M_two_two
    write str_probel
    writenum C.M_two_three
    write str_probel
    writenum C.M_two_four
    writeln
    writeln
    writenum C.M_three_one
    write str_probel
    writenum C.M_three_two
    write str_probel
    writenum C.M_three_three
    write str_probel
    writenum C.M_three_four
    write str_probel
    ret
            endp
start:
    mov ax,@data
    mov ds,ax
;-------------
what_to_do:
    print_menu
    readkey dx
    cmp dl,'a'
    je enter_a
    cmp dl,'b'
    je enter_b
    cmp dl,'d'
    je add_mat
    cmp dl,'m'
    je mult_mat
    cmp dl,'q'
    je quit
    jmp what_to_do
enter_a:
    mov dx,offset A
    call enter_matrica
    jmp what_to_do
enter_b:
    mov dx,offset B
    call enter_matrica
    jmp what_to_do
add_mat:
    call add_matrica    
    call print_c_matrica
    readkey ax
    jmp what_to_do
mult_mat:
    call mult_matrica
    jmp what_to_do
quit:
    exit
  end start

Объяснение кода листинга программы

  1. В коде присутствует использование макросов, процедур и функций для работы с меню и матрицами.
  2. Кодировка меню и элементов матрицы представлена в виде строк в кавычках.
  3. Матрица представлена структурой с полями для хранения чисел размером 4x4.
  4. Для ввода элементов матрицы используется функция enter_matrica, которая запрашивает ввод элементов строки матрицы и сохраняет их в соответствующую матрицу.
  5. Для сложения матриц A и B используется функция add_matrica, которая складывает элементы соответствующих строк матрицы C.
  6. Для умножения матрицы A на матрицу B используется функция mult_matrica.
  7. Для вывода меню и чисел матрицы используется функция print_menu и print_num.
  8. Для обработки ошибок и выхода из программы используется функция exit.

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

6   голосов , оценка 4.333 из 5
Похожие ответы