Цель работы:
Изучение способов представления сложных структур данных на ассемблере.
Блок схема алгоритма:
Текст программы:
Файл «LAB4.ASM»:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
data segment msg1 db 10,13, 'Program started...','$' msgstr1 db 10,13, 'First str:',10,13,'$' msgstr2 db 10,13, 'Second str:',10,13,'$' msgstr3 db 10,13, 'Third str:',10,13,'$' msgafter db 10,13,'After MyProc:',10,13,'$' ; 0123456789012345678901234567890123456789012345678901234567890123456789!123456789!123456789!123456789!1234 A db ' 112131 1 ' code segment assume cs:code,ds:data start: mov ax,data; настроить сегментный mov ds,ax; регистр ds на данные lea dx,msg1; call print_msg lea dx,msgstr2 call print_msg call PrintAll; lea bx,A; push bx; call MyProc; ;вызов процедуры обработки массива pop bx; lea dx,msgafter call print_msg call PrintAll; mov ah, 01h; int 21h; mov ah,4ch; завершить int 21h; программу print_msg proc ;Процедура вывода сообщений на экран push ax; mov ah,09h; int 21h; pop ax; ret print_msg endp MyProc proc near B equ word ptr[bp+4] ;;Отключено. проверка настроен ли указатель на массив ;; mov ah,02h; ;; mov dl,bx; ;; int 21h; push bp; mov bp,sp; push ds; mov bx,[B]; buf dw 0 c dw 2 mov si,bx; mov di,bx add di,70; mov cx,35; return1: inc BX; ;mov ah,02h; mov dx,[bx]; ;int 21h; mov buf,bx; push cx; push bx; mov cx,35; mov bx,si; return2: inc bx; cmp buf,bx; je dalee; cmp dl,[bx]; je metkaloop; dalee: loop return2 pop bx; push bx; sub bx,si; push di; ;mov di,si; ;add di,70; add di,bx; ; sub ax,si; ; pop bx; ; mov ax,bx; ; push bx; ;push di; ; sub ax,si; ; add di,ax; mov [di],dl; pop di; metkaloop: pop bx; pop cx; loop return1 mov cx,35; add si,35 mov bx,si ; mov di,si; ; add di,35; sub c,1 jnz return1 mov ah,02h; mov dx,10; int 21h; mov dx,13; int 21h; mov cx,35; mov bx,di; ; add bx,70; pop ds; pop bp; ret myProc endp PrintAll proc lea dx,msgstr1 call print_msg mov cx,35; mov ah,02h; ret1: lea bx,A; add bx,cx; mov dx,[bx] int 21h; loop ret1 lea dx,msgstr2 call print_msg mov cx,35; mov ah,02h; ret2: lea bx,A; add bx,cx; add bx,35 mov dx,[bx] int 21h; loop ret2 lea dx,msgstr3 call print_msg mov cx,35; mov ah,02h; ret3: lea bx,A; add bx,cx; add bx,70 mov dx,[bx] int 21h; loop ret3 ret PrintAll endp ends end start |
Результат работы программы:
№ Опыта | Входные данные | Выходные данные |
1 | A[1,1,3]=1 | A[3,1,3]=1 |
2 | A[1,1,3]=1, A[1,1,4=1] | A[3]=ВСЕ ПРОБЕЛЫ |
3 | A[2,1,3]=1 | A[3,1,3]=1 |
Вывод:
Составленная программа работает правильно.