Федеральное агенство связи федеральное государственное бюджетное
Скачать 67.6 Kb.
|
ФЕДЕРАЛЬНОЕ АГЕНСТВО СВЯЗИ ФЕДЕРАЛЬНОЕ ГОСУДАРСТВЕННОЕ БЮДЖЕТНОЕ ОБРАЗОВАТЕЛЬНОЕ УЧРЕЖДЕНИЕ ВЫСШЕГО ОБРАЗОВАНИЯ «САНКТ-ПЕТЕРБУРСКИЙ ГОСУДАРСТВЕННИЙ УНИВЕРСИТЕТ ТЕЛЕКОММУНИКАЦИЙ ИМ. ПРОФ. М.А. БОНЧ-БРУЕВИЧА» (СПБГУТ) ФАКУЛЬТЕТ ИНФОКОММУНИКАЦИОННЫХ СЕТЕЙ И СИСТЕМ (ИКСС) КАФЕДРА ПРОГРАММНОЦ ИНЖЕНЕРИИ И ВЫЧИСЛИТЕЛЬНОЙ ТЕХНИКИ (ПИ И ВТ) ДИСЦИПЛИНА : « Машинно-зависимые языки программирования» Лабораторная работа Nº 1. ТЕМА: «Вычисление целочисленных арифметических выражений» Вариант Nº 9 Выполнил: Студент группы ИКПИ -94 Жоау Ошвалду Б. Педру Подпись__________ Приния: Морозов Д.П Подпись__________ «____»____________2020 А. Постановка задачи Вычислить заданное целочисленное выражение для исходных данных в знаковых и беззнаковых форматах длиной 8 и 16 бит (53+c*2-1)/(b-a+4) B. Результаты вычислений C. Программа на языке С++ и ASM //Signed Byte CPP #include extern "C" {void functGetAsm -(void);} short a, b, c; long int numerator = 0; int denominator = 0; int rezultat; void functionCPP() { numerator = (53+ c*2 -1); denominator =(b-a+4); rezultat = (53+ c*2-1) / (b-a+4); cout<< "CPP numerator: " << numerator << "\n"; cout<< "CPP denominador: " << denominator << "\n"; cout<< rezultat << "\n"; } void functionASM() { rezultat = 0; functGetAsm(); cout<< "ASM Numerator: " << numerator << "\n"; cout<< "ASM Denominator: " << denominator << "\n"; cout< } int main() { cout<< "Insert the number a: "; cin>> a; cout<< "\n Insert the number b: "; cin>> b; cout<< "\n Insert the number c: "; cin>> c; cout<< "\n"; functionCPP(); functionASM(); return 0; } .MODEL large, c .data Extrn a: byte, b: byte, c: byte, numerator: dword, denominator: word, rezultat: word; .code public functGetAsm functGetAsm proc far ;begin the program ;numerator (53 c*2-1)--------------------------------- mov al, c cbw ; ax word mov cl, 2 ; cl =2 imul cl ;ax=ax*2 sub ax, 1 ;ax=ax-1 add ax,53 ;ax=ax+53 cwd ;dx=ax mov word ptr numerator, ax mov word ptr numerator +2,dx ;denominator (b-a+4)--------------------------------------- mov al, a ;al=a cbw ; ax=al mov ax,bx ;bx=ax mov al,b ;al=b cbw ; ax=al sub ax,bx ; ax=ax-bx add ax,4 ;ax=ax+4 mov denominator, ax ;rezultat ((53+c*2-1)/(b-a+4))------------------------ mov ax, word ptr numerator mov dx, word ptr numerator +2 idiv denominator; ax=ax/ denominator mov rezultat, ax ret functGetAsm endp ; finished the metod asm end ; finished the program ----------------------------------------------------- //unsigned peremeni #include extern "C" {void functGetAsm (void);} unsigned short a, b, c; unsigned long int numerator = 0; unsigned int denominator = 0; unsigned int rezultat; void functionCPP() { numerator = (53+ c*2 -1); denominator =(b-a+4); rezultat = (53+ c*2-1) / (b-a+4); cout<< "CPP Numerator: " << numerator << "\n"; cout<< "CPP Denominador: " << denominator << "\n"; cout<< “CPP Rezultat =” << rezultat<<"\n"; } void functionASM() { rezultat = 0; functGetAsm(); cout<< "ASM Numerator: " << numerator << "\n"; cout<< "ASM Denominator: " << denominator << "\n"; cout< } int main() { cout<< "Insert the number a: "; cin>> a; cout<< "\n Insert the number b: "; cin>> b; cout<< "\n Insert the number c: "; cin>> c; cout<< "\n"; functionCPP(); functionASM(); return 0; } //Unsigned byte ASM .MODEL large, c .data Extrn a: byte, b: byte, c: byte, numerator: dword, denominator: word, rezultat: word; .code public functGetAsm functGetAsm proc far ;begin the program ;numerator (53 c*2-1)--------------------------------- mov al, c cbw ; ax word mov cl, 2 ; cl =2 imul cl ;ax=ax*2 sub ax, 1 ;ax=ax-1 add ax,53 ;ax=ax+53 cwd ;dx=ax mov word ptr numerator, ax mov word ptr numerator +2,dx ;denominator (b-a+4)--------------------------------------- mov al, a ;al=a cbw ; ax=al mov ax,bx ;bx=ax mov al,b ;al=b cbw ; ax=al sub ax,bx ; ax=ax-bx add ax,4 ;ax=ax+4 mov denominator, ax ;rezultat ((53+c*2-1)/(b-a+4))------------------------ mov ax, word ptr numerator mov dx, word ptr numerator +2 idiv denominator; ax=ax/ denominator mov rezultat, ax ret functGetAsm endp ; finished the metod asm end ; finished the program ----------------------------------------------------- //Signed word CPP #include extern "C" {void functGetAsm (void);} int a, b, c; long int numerator = 0; int denominator = 0; int rezultat; void functionCPP() { numerator = (53+(long int) c*2 -1); denominator =(b-a+4); rezultat = (53+ (long int)c*2-1) / (b-a+4); cout<< "CPP Numerator: " << numerator << "\n"; cout<< "CPP Denominador: " << denominator << "\n"; cout<< “CPP Rezultat =” << rezultat<<"\n"; } void functionASM() { rezultat = 0; functGetAsm(): cout<< "ASM Numerator: " << numerator << "\n"; cout<< "ASM Denominator: " << denominator << "\n"; cout< } int main() { cout<< "Insert the number a: "; cin>> a; cout<< "\n Insert the number b: "; cin>> b; cout<< "\n Insert the number c: "; cin>> c; cout<< "\n"; functionCPP(); functionASM(); return 0; } .MODEL large, c .data Extrn a: word, b: word, c: word, numerator: dword, denominator: word, rezultat: word; .code public functGetAsm functGetAsm proc far ;begin the program ;numerator (53 c*2-1)--------------------------------------- mov ax, c cwd ; dx=ax; mov cx, 2 ; cx =2 imul cx ;ax=ax*2 sub ax, 1 ;ax=ax-1 add ax,53 ;ax=ax+53 cwd ;dx=ax mov word ptr numerator, ax mov word ptr numerator +2, dx ;denominator (b-a+4)--------------------------------------- mov ax, a ;ax=a mov bx,b ;bx=b sub bx,ax ; bx=bx-ax add bx,4 ;bx=bx+4 mov denominator, bx ;rezultat ((53+c*2-1)/(b-a+4))------------------------ mov ax, word ptr numerator mov dx, word ptr numerator +2 idiv denominator; ax=ax/ denominator mov rezultat, ax ret functGetAsm endp ; finished the metod asm end ; finished the program ------------------------------------------------------------- //Signed word CPP #include extern "C" {void functGetAsm(void);} unsigned int a, b, c; unsigned long int numerator = 0; unsigned int denominator = 0; unsigned int rezultat; void functionCPP() { numerator = (53+(unsigned long int) c*2 -1); denominator =(b-a+4); rezultat = (53+ (unsigned long int)c*2-1) / (b-a+4); cout<< "CPP Numerator: " << numerator << "\n"; cout<< "CPP Denominador: " << denominator << "\n"; cout<< “CPP Rezultat =” << rezultat<<"\n"; } void functionASM() { rezultat = 0; functGetAsm (); cout<< "ASM Numerator: " << numerator << "\n"; cout<< "ASM Denominator: " << denominator << "\n"; cout< } int main() { cout<< "Insert the number a: "; cin>> a; cout<< "\n Insert the number b: "; cin>> b; cout<< "\n Insert the number c: "; cin>> c; cout<< "\n"; functionCPP(); functionASM(); return 0; } .MODEL large, c .data Extrn a: word, b: word, c: word, numerator: dword, denominator: word, rezultat: word; .code public functGetAsm functGetAsm proc far ;begin the program ;numerator (53 c*2-1)--------------------------------------- mov ax, c cwd ; dx=ax; mov cx, 2 ; cx =2 imul cx ;ax=ax*2 sub ax, 1 ;ax=ax-1 add ax,53 ;ax=ax+53 cwd ;dx=ax mov word ptr numerator, ax mov word ptr numerator +2, dx ;denominator (b-a+4)--------------------------------------- mov ax, a ;ax=a mov bx,b ;bx=b sub bx,ax ; bx=bx-ax add bx,4 ;bx=bx+4 mov denominator, bx ;rezultat ((53+c*2-1)/(b-a+4))------------------------ mov ax, word ptr numerator mov dx, word ptr numerator +2 idiv denominator; ax=ax/ denominator mov rezultat, ax ret functGetAsm endp ; finished the metod asm end ; finished the program |