There is such code:

format PE GUI 4.0 include 'WIN32AX.INC' .data formats db "%d",0 result db 256 dup(?) ; Когда будем преобразовывать число в строку, сюда сохраним результат A db 02h ; стороны B db 02h ; треугольника C db 04h ; .code start: MOV DL,byte[C] MOV AL,byte[A] MOV BL,byte[B] CMP AL,BL ; сравнение JNE NOT_EQABC CMP BL,DL JNE NOT_EQABC invoke MessageBox,0,result,"треугольник равносторонний",MB_OK ;Выводим результат на экран. JMP METKA ; переход на метку NOT_EQABC: CMP AL,BL JE EQUAL CMP BL,DL JE EQUAL CMP AL,DL JE EQUAL ; invoke MessageBox,0,result,"треугольник обычный",MB_OK ;Выводим результат на экран. JMP METKA EQUAL: ; invoke MessageBox,0,result,"треугольник равнобедренный ",MB_OK ;Выводим результат на экран. METKA: invoke ExitProcess,0 ;Выход из программы .end start 

This is a triangle identification program. I need to add two more check blocks: check if a triangle can exist, check if a triangle is rectangular.

The blocks should be about the same.

  CMP AL,BL ; сравнение JNE NOT_EQABC CMP BL,DL JNE NOT_EQABC invoke MessageBox,0,result,"треугольник равносторонний",MB_OK ;Выводим результат на экран. 

This is a fasm32 assembler ... Who knows how to do it, tell me.

  • @ cyber922, and on what basis are you going to check whether a triangle can exist? And, stupidly, the sum of the two smaller sides should be less or equal to the larger side. - insolor
  • About squareness, I can say that you need to find the greatest strongest and check that its square is equal to the sum of the squares of the other two sides (the Pythagorean theorem is the same). - insolor 4:21 pm
  • I know how to implement this in the code, that is the problem: D - Victor Khorolsky

1 answer 1

First you need to find the largest side:

 mov al,[A] mov bl,[B] mov cl,[C] cmp al,bl jae @f ; если al>=bl (без учета знака), то переход вперед (f - от слова forward) до ближайшей метки @@ xchg al,bl @@: cmp al,cl jae @f xchg al,cl @@: ; Теперь у нас в al лежит наибольшая сторона, в bl и cl две меньшие 

For the triangle to exist, it is necessary that the values ​​bl + cl be not less than al. The sum is placed for example in dl, so that the values ​​can be used again:

 mov dl,bl add dl,cl cmp al,dl ja не_существует ; выводим что треугольник не существует и выходим ; существует 

Now you can check the triangle for squareness. It is necessary to multiply the value in al by itself, save somewhere (for example in dx), then add the value from bl to al, also multiply by itself, put in bx, then put the value from cl in al, multiply by itself and add to bx. Then we compare bx and dx, if they are equal, it means that the triangle is rectangular.

 ; в al лежит значение наибольшей стороны (если треугольник прямоугольный - то это гипотенуза) mul al ; умножаем al само на себя, результат в ax mov dx,ax ; сохраняем ax в dx для последующего сравнения mov al,bl mul al mov bx,ax ; сохраняем квадрат одной из меньших сторон в bx mov al,cl mul al add bx,ax ; суммируем квадраты меньших сторон, результат в bx cmp dx,bx ; сравниваем квадрат большей стороны и сумму квадратов меньших сторон je прямоугольный ; если равны, то треугольник прямоугольный ; не прямоугольный 

By the way, result is not needed, because in this task the answer is not formed through wsprintf, but simply written in plain text:

 invoke MessageBox, 0, "Текст сообщения (например что треугольник равносторонний)", "Заголовок", MB_OK 
  • In checking the existence of a mess with the condition (Corrected. - insolor