Скачиваний:
14
Добавлен:
09.04.2023
Размер:
89 Кб
Скачать

ФЕДЕРАЛЬНОЕ ГОСУДАРСТВЕННОЕ БЮДЖЕТНОЕ ОБРАЗОВАТЕЛЬНОЕ УЧРЕЖДЕНИЕ ВЫСШЕГО ОБРАЗОВАНИЯ

«САНКТ-ПЕТЕРБУРГСКИЙ ГОСУДАРСТВЕННЫЙ УНИВЕРСИТЕТ ТЕЛЕКОММУНИКАЦИЙ ИМ. ПРОФ. М.А. БОНЧ-БРУЕВИЧА»

___________________________________________________

КАФЕДРА ЗАЩИЩЕННЫХ СИСТЕМ СВЯЗИ

Дисциплина: Ассемблер в задачах защиты информации

Лабораторная работа №6

Вызов функций в ассемблере – модульное программирование

Выполнил:

Студент 2 курса, группа ИКБ-95, факультет ИКСС

Преподаватель: Красов А. В.

Цель:

Написать программу на языке ассемблера, которая объединяет лабораторные работы №2, 3, 4, 5 в виде отдельных процедур.

Код:

.model small

.stack 100h

.data

; lab 2 (A+B)*C

promptA db 13, 10, 'Enter A: $'

promptB db 13, 10, 'Enter B: $'

promptC db 13, 10, 'Enter C: $'

promptResult db 13, 10, 'Result: $'

; lab 3

promptX db 13, 10, 'Enter X: $'

promptY db 13, 10, 'Enter Y: $'

lineON db 13, 10, 'The point is located on the line$'

lineABOVE db 13, 10, 'The point is located above the line$'

lineUNDER db 13, 10, 'The point is located under the line$'

circleON db 13, 10, 'The point is located on the circle$'

circleINSIDE db 13, 10, 'The point is located inside the circle$'

circleOUTSIDE db 13, 10, 'The point is located outside the circle$'

rectangleON db 13, 10, 'The point is located on the rectangle$'

rectangleINSIDE db 13, 10, 'The point is located inside the rectangle$'

rectangleOUTSIDE db 13, 10, 'The point is located outside the rectangle$'

; lab 4

first db 13, 10, 'Point is in the 1st area$'

second db 13, 10, 'Point is in the 2nd area$'

third db 13, 10, 'Point is in the 3rd area$'

fourth db 13, 10, 'Point is in the 4th area$'

fifth db 13, 10, 'Point is in the 5th area$'

; lab 5

promptHeight db 13, 10, 'Enter height (1-9): $'

promptSymbol db 13, 10, 'Enter symbol: $'

clrf db 13, 10, '$'

; common data (lab5)

height db ?

symbol db ?

; additional

labstr2 db 13, 10, '', 13, 10, ' LAB 2 ', 13, 10, '$'

labstr3 db 13, 10, '', 13, 10, ' LAB 3 ', 13, 10, '$'

labstr4 db 13, 10, '', 13, 10, ' LAB 4 ', 13, 10, '$'

labstr5 db 13, 10, '', 13, 10, ' LAB 5 ', 13, 10, '$'

.code

start:

mov ax, @data

mov ds, ax

; lab 2 title

mov ah, 09h

mov dx, offset labstr2 (Вызов надписи Лаб 2)

int 21h

; input for lab 2

mov dx, offset promptA ; prompt A (Вывод надписи Enter A)

int 21h

mov ah, 01h (Ввод А)

int 21h

sub al, '0'

mov bh, al

mov ah, 09h

mov dx, offset promptB

int 21h

mov ah, 01h

int 21h

sub al, '0'

mov bl, al

mov ah, 09h

mov dx, offset promptC

int 21h

mov ah, 01h

int 21h

sub al, '0'

mov ch, al

mov ah, 09h

mov dx, offset promptResult

int 21h

call lab2

call lab2_res

; lab 3 title

mov ah, 09h

mov dx, offset labstr3

int 21h

mov dx, offset promptX

int 21h

mov ah, 01h

int 21h

xor bx, bx

mov bl, al

push bx

mov ah, 09h

mov dx, offset promptY

int 21h

mov ah, 01h

int 21h

xor cx, cx

mov cl, al

push cx

call lab3

; lab 4 title

mov ah, 09h

mov dx, offset labstr4

int 21h

mov dx, offset promptX

int 21h

mov ah, 01h

int 21h

xor bx, bx

mov bl, al

push bx

mov ah, 09h

mov dx, offset promptY

int 21h

mov ah, 01h

int 21h

xor cx, cx

mov cl, al

push cx

call lab4

pop bx

add sp, 4

call lab4_res

; lab 5 title

mov ah, 09h

mov dx, offset labstr5

int 21h

mov dx, offset promptHeight

int 21h

mov ah, 01h

int 21h

sub al, '0'

mov height, al

mov dx, offset promptSymbol

mov ah, 09h

int 21h

mov ah, 01h

int 21h

mov symbol, al

call lab5

mov ah, 4ch

int 21h

; LAB 2

lab2 PROC

mov al, bh

add al, bl

mul ch

ret

lab2 ENDP

; Print result for lab2

lab2_res PROC

xor cx, cx

mov bx, 10

split:

xor dx, dx

div bx

push dx

inc cx

test ax, ax

jnz split ; if not zero

mov ah, 02h

show:

pop dx

add dl, '0'

int 21h

loop show

ret

lab2_res ENDP

; LAB 3

lab3 PROC

push bp

mov bp, sp

mov bl, [bp + 6]

mov bh, [bp + 4]

mov sp, bp

pop bp

call checkLine

call checkCircle

call checkRectangle

ret 4

checkLine PROC

xor dx, dx

mov ah, 09h

cmp bh, '5'

je online ; if equal to

ja aboveLine ; if more

jb belowLine ; if less

onLine:

mov dx, offset lineON

int 21h

ret

aboveLine:

mov dx, offset lineABOVE

int 21h

ret

belowLine:

mov dx, offset lineUNDER

int 21h

ret

checkLine ENDP

checkCircle PROC

xor dx, dx

mov ah, 09h

cmp bl, '0'

je cx0 ; if equal to

cmp bl, '1'

je cx1 ; if equal to

cmp bl, '2'

je cx2 ; if equal to

cmp bl, '3'

je cx3 ; if equal to

cmp bl, '4'

je cx4 ; if equal to

ja outsideCircle

cx0:

cmp bh, '7'

je onCircle ; if equal to

ja outsideCircle ; if more

jb outsideCircle ; if less

cx1:

cmp bh, '9'

je outsideCircle ; if equal to

cmp bh, '5'

ja insideCircle ; if more

je outsideCircle ; if equal to

jb outsideCircle ; if less

cx2:

cmp bh, '9'

je onCircle ; if equal to

cmp bh, '5'

ja insideCircle ; if more

je onCircle ; if equal to

jb outsideCircle ; if less

cx3:

cmp bh, '9'

je outsideCircle ; if equal to

cmp bh, '5'

ja insideCircle ; if more

je outsideCircle ; if equal to

jb outsideCircle ; if less

cx4:

cmp bh, '7'

ja outsideCircle ; if more

je onCircle ; if equal to

jb outsideCircle ; if less

onCircle:

mov dx, offset circleON

int 21h

ret

insideCircle:

mov dx, offset circleINSIDE

int 21h

ret

outsideCircle:

mov dx, offset circleOUTSIDE

int 21h

ret

checkCircle ENDP

checkRectangle PROC

xor dx, dx

mov ah, 09h

cmp bl, '5'

je vert ; if equal to

jb outsideRectangle ; if less

cmp bl, '9'

je vert ; if equal to

jb hor ; if less

vert:

cmp bh, '0'

je outsideRectangle ; if equal to

ja onRectangle ; if more

hor:

cmp bh, '1'

je onRectangle ; if equal to

jb outsideRectangle ; if less

cmp bh, '9'

je onRectangle ; if equal to

jb insideRectangle ; if less

onRectangle:

mov dx, offset rectangleON

int 21h

ret

insideRectangle:

mov dx, offset rectangleINSIDE

int 21h

ret

outsideRectangle:

mov dx, offset rectangleOUTSIDE

int 21h

ret

checkRectangle ENDP

; LAB 4

lab4 PROC

push bp

mov bp, sp

mov bl, [bp + 6]

mov bh, [bp + 4]

mov sp, bp

pop bp

mov ah, 09h

cmp bh, '5'

ja above5 ; if more

je above5 ; if equal to

jb below5 area1 ; if less

below5:

cmp bl, '9'

je area1

cmp bl, '5'

ja ar1or2 ; if more

je ar1or2 ; if equal to

jb area1 ; if less

ar1or2:

cmp bh, '0'

je area1 ; if equal to

ja area2 ; if more

above5:

cmp bl, '9'

je area4 ; if equal to

cmp bl, '4'

je area4 ; if equal to

ja area3 ; if more

cmp bl, '3'

je x1or3 ; if equal to

cmp bl, '2'

je area5 ; if equal to

cmp bl, '1'

je x1or3 ; if equal to

jb x0 ; if less

x1or3:

cmp bh, '9'

je area4 ; if equal to

cmp bh, '5'

je area4 ; if equal to

ja area5 ; if more

x0:

cmp bh, '7'

ja area4 ; if more

je area5 ; if equal to

jb area4 ; if less

area1:

mov bx, 1

pop cx

push bx

push cx

ret

area2:

mov bx, 2

pop cx

push bx

push cx

ret

area3:

mov bx, 3

pop cx

push bx

push cx

ret

area4:

mov bx, 4

pop cx

push bx

push cx

ret

area5:

mov bx, 5

pop cx

push bx

push cx

ret

lab4 ENDP

; print result for lab4

lab4_res PROC

mov ah, 09h

cmp bx, 1

je a1 ; if equal to

cmp bx, 2

je a2 ; if equal to

cmp bx, 3

je a3 ; if equal to

cmp bx, 4

je a4 ; if equal to

cmp bx, 5

je a5 ; if equal to

a1:

mov dx, offset first

int 21h

ret

a2:

mov dx, offset second

int 21h

ret

a3:

mov dx, offset third

int 21h

ret

a4:

mov dx, offset fourth

int 21h

ret

a5:

mov dx, offset fifth

int 21h

ret

lab4_res ENDP

; LAB 5

lab5 PROC

mov ah, 09h ; new line

mov dx, offset clrf

int 21h

xor dx, dx

xor bx, bx

mov dl, symbol

mov cl, height

mov ah, 02h

column:

push cx

inc bl

mov cl, bl

row:

int 21h

loop row

pop cx

push dx

mov ah, 09h

mov dx, offset clrf

int 21h

pop dx

mov ah, 02h

loop column

ret

lab5 ENDP

end start

Демонстрация работы программы:

Вывод:

В ходе выполнения лабораторной работы, была написана программа, соответствующая поставленным условиям.

Санкт-Петербург

2020